Skip to content

Commit

Permalink
! improve integration-test.sh
Browse files Browse the repository at this point in the history
- mvn clean before install
- clean maven build and install of COLA in maven local repository
- rename function: runCmd -> logAndRun
  • Loading branch information
oldratlee committed Jan 7, 2021
1 parent 44e1fd8 commit 93dca11
Showing 1 changed file with 50 additions and 27 deletions.
77 changes: 50 additions & 27 deletions scripts/integration-test.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/bin/bash
# NOTE about Bash Traps and Pitfalls:
#
# 1. DO NOT declare var as readonly if value is supplied by subshell!!
# for example: readonly var1=$(echo value1)
#
# readonly declaration make exit code of assignment to be always 0,
# aka. the exit code of command in subshell is discarded.
# tested on bash 3.2.57/4.2.46

set -eEuo pipefail

# adjust current dir to project root dir
cd "$(dirname "$0")/.."


################################################################################
# constants
################################################################################

# NOTE: $'foo' is the escape sequence syntax of bash
readonly nl=$'\n' # new line
readonly ec=$'\033' # escape char
readonly nl=$'\n' # new line
readonly ec=$'\033' # escape char
readonly eend=$'\033[0m' # escape end


################################################################################
# common util functions
################################################################################
Expand Down Expand Up @@ -43,20 +50,29 @@ headInfo() {
colorEcho "0;34;46" ================================================================================
yellowEcho "$*"
colorEcho "0;34;46" ================================================================================
echo
}

runCmd() {
blueEcho "Run under work directory $PWD :$nl$*"
time "$@"
logAndRun() {
local simple_mode=false
[ "$1" = "-s" ] && {
simple_mode=true
shift
}

if $simple_mode; then
echo "Run under work directory $PWD : $*"
"$@"
else
blueEcho "Run under work directory $PWD :$nl$*"
time "$@"
fi
}

die() {
redEcho "Error: $*" 1>&2
exit 1
}


################################################################################
# build util functions
################################################################################
Expand All @@ -76,40 +92,52 @@ MVN() {
d=$(dirname "$d")
done

runCmd "$d/$maven_wrapper_name" "${MVN_OPTIONS[@]}" "$@"
logAndRun "$d/$maven_wrapper_name" "${MVN_OPTIONS[@]}" "$@"
}

# Where is Maven local repository?
# https://mkyong.com/maven/where-is-maven-local-repository/

# NOTE: DO NOT declare mvn_local_repository_dir var as readonly, its value is supplied by subshell.
mvn_local_repository_dir="$(
cd cola-components/ &&
./mvnw --no-transfer-progress help:evaluate -Dexpression=settings.localRepository |
grep '^/'
)"
[ -n "$mvn_local_repository_dir" ] || die "Fail to find find maven local repository directory: $mvn_local_repository_dir"

echo "find maven local repository directory: $mvn_local_repository_dir"

################################################################################
# CI operations
################################################################################

headInfo "clean maven build and install of COLA in maven local repository:"
logAndRun -s rm -rf "$mvn_local_repository_dir/com/alibaba/demo"
logAndRun -s rm -rf "$mvn_local_repository_dir/com/alibaba/cola"
logAndRun -s rm -rf "$mvn_local_repository_dir/com/alibaba/craftsman"

(
headInfo "CI: cola-components"

cd cola-components/
MVN install
MVN clean install
)


(
headInfo "CI: cola-archetypes"

cd cola-archetypes/
MVN install
MVN clean install
)


(
headInfo "CI: archetype:generate by cola-framework-archetype-service"

# NOTE: DO NOT declare archetypeVersion var as readonly!!
# readonly declaration make exit code of assignment to be always 0,
# aka. the exit code of command in subshell is discarded.
# tested on bash 3.2.57/4.2.46
# NOTE: DO NOT declare archetypeVersion var as readonly, its value is supplied by subshell.
archetypeVersion=$(
grep '<version>.*</version>' cola-archetypes/cola-archetype-service/pom.xml |
awk -F'</?version>' 'NR==1 {print $2}'
awk -F'</?version>' 'NR==1 {print $2}'
)

readonly demo_dir="cola-archetypes/target/cola-framework-archetype-service-demo"
Expand All @@ -131,17 +159,13 @@ MVN() {
MVN install
)


(
headInfo "CI: archetype:generate by cola-framework-archetype-web"

# NOTE: DO NOT declare archetypeVersion var as readonly!!
# readonly declaration make exit code of assignment to be always 0,
# aka. the exit code of command in subshell is discarded.
# tested on bash 3.2.57/4.2.46
# NOTE: DO NOT declare archetypeVersion var as readonly, its value is supplied by subshell.
archetypeVersion=$(
grep '<version>.*</version>' cola-archetypes/cola-archetype-web/pom.xml |
awk -F'</?version>' 'NR==1 {print $2}'
awk -F'</?version>' 'NR==1 {print $2}'
)

readonly demo_dir="cola-archetypes/target/cola-framework-archetype-web-demo"
Expand All @@ -163,10 +187,9 @@ MVN() {
MVN install
)


(
headInfo "CI: sample/craftsman"

cd sample/craftsman/
MVN install
MVN clean install
)

0 comments on commit 93dca11

Please sign in to comment.