Skip to content

Commit

Permalink
Enhanced Travis CI test script
Browse files Browse the repository at this point in the history
  • Loading branch information
mabrarov committed Nov 10, 2020
1 parent ec7b57d commit e1e66d3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ matrix:
jdk: 'openjdk8'
env:
- MAVEN_WRAPPER: '1'
# OpenJDK 11 with Maven Wrapper
# OpenJDK 11
- dist: 'bionic'
jdk: 'openjdk11'

Expand Down
23 changes: 4 additions & 19 deletions travis/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@

set -e

build_maven_project() {
if [[ "${MAVEN_WRAPPER}" -ne 0 ]]; then
build_cmd="${build_cmd:+${build_cmd} }$(printf "%q" "${TRAVIS_BUILD_DIR}/mvnw")"
else
build_cmd="${build_cmd:+${build_cmd} }mvn"
fi
source "${TRAVIS_BUILD_DIR}/travis/maven.sh"

build_cmd="${build_cmd:+${build_cmd} }--settings $(printf "%q" "${TRAVIS_BUILD_DIR}/travis/settings.xml")"
build_cmd="${build_cmd:+${build_cmd} }--file $(printf "%q" "${TRAVIS_BUILD_DIR}/pom.xml")"
build_maven_project() {
build_cmd="$(maven_runner)$(maven_settings)$(maven_project_file)$(docker_maven_plugin_version)"
build_cmd="${build_cmd:+${build_cmd} }--batch-mode"

if [[ "${DOCKER_MAVEN_PLUGIN_VERSION}" != "" ]]; then
build_cmd="${build_cmd:+${build_cmd} }--define docker-maven-plugin.version=$(printf "%q" "${DOCKER_MAVEN_PLUGIN_VERSION}")"
fi

if [[ "${DOCKERHUB_USER}" != "" ]]; then
build_cmd="${build_cmd:+${build_cmd} }--define docker.image.registry=$(printf "%q" "${DOCKERHUB_USER}")"
fi
Expand Down Expand Up @@ -68,13 +59,7 @@ wait_for_healthy_container() {
}

test_images() {
if [[ "${MAVEN_WRAPPER}" -ne 0 ]]; then
project_version_cmd="${project_version_cmd:+${project_version_cmd} }$(printf "%q" "${TRAVIS_BUILD_DIR}/mvnw")"
else
project_version_cmd="${project_version_cmd:+${project_version_cmd} }mvn"
fi
project_version_cmd="${project_version_cmd:+${project_version_cmd} }--settings $(printf "%q" "${TRAVIS_BUILD_DIR}/travis/settings.xml")"
project_version_cmd="${project_version_cmd:+${project_version_cmd} }--file $(printf "%q" "${TRAVIS_BUILD_DIR}/pom.xml")"
project_version_cmd="$(maven_runner)$(maven_settings)$(maven_project_file)"
project_version_cmd="${project_version_cmd:+${project_version_cmd} }--batch-mode --non-recursive"
project_version_cmd="${project_version_cmd:+${project_version_cmd} }--define expression=project.version"
project_version_cmd="${project_version_cmd:+${project_version_cmd} }org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate"
Expand Down
26 changes: 26 additions & 0 deletions travis/maven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

maven_runner() {
if [[ "${MAVEN_WRAPPER}" -ne 0 ]]; then
printf "%q" "${TRAVIS_BUILD_DIR}/mvnw"
else
echo "mvn"
fi
}

maven_settings() {
maven_settings_file="${TRAVIS_BUILD_DIR}/travis/settings.xml"
if [[ -f "${maven_settings_file}" ]]; then
printf " %s %q" "--settings" "${maven_settings_file}"
fi
}

maven_project_file() {
printf " %s %q" "--file" "${TRAVIS_BUILD_DIR}/pom.xml"
}

docker_maven_plugin_version() {
if [[ "${DOCKER_MAVEN_PLUGIN_VERSION}" != "" ]]; then
printf " %s%q" "--define docker-maven-plugin.version=" "${DOCKER_MAVEN_PLUGIN_VERSION}"
fi
}
33 changes: 9 additions & 24 deletions travis/push-docker-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,19 @@

set -e

# Copied from https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_retry.bash
travis_retry() {
local result=0
local count=1
while [[ "${count}" -le 3 ]]; do
[[ "${result}" -ne 0 ]] && {
echo -e "\\n${ANSI_RED}The command \"${*}\" failed. Retrying, ${count} of 3.${ANSI_RESET}\\n" >&2
}
"${@}" && { result=0 && break; } || result="${?}"
count="$((count + 1))"
sleep 1
done

[[ "${count}" -gt 3 ]] && {
echo -e "\\n${ANSI_RED}The command \"${*}\" failed 3 times.${ANSI_RESET}\\n" >&2
}

return "${result}"
}
source "${TRAVIS_BUILD_DIR}/travis/maven.sh"
source "${TRAVIS_BUILD_DIR}/travis/travis-retry.sh"

main() {
travis_retry docker login -u "${DOCKERHUB_USER}" -p "${DOCKERHUB_PASSWORD}"

mvn --settings "${TRAVIS_BUILD_DIR}/travis/settings.xml" \
--file "${TRAVIS_BUILD_DIR}/pom.xml" \
--batch-mode \
--define docker.push.retries="${DOCKER_PUSH_RETRIES}" \
docker:push
push_cmd="$(maven_runner)$(maven_settings)$(maven_project_file)$(docker_maven_plugin_version)"
push_cmd="${push_cmd:+${push_cmd} }--batch-mode"
push_cmd="${push_cmd:+${push_cmd} }--define docker.push.retries=$(printf "%q" "${DOCKER_PUSH_RETRIES}")"
push_cmd="${push_cmd:+${push_cmd} }docker:push"

echo "Pushing images with: ${push_cmd}"
eval "${push_cmd}"
}

main "${@}"
21 changes: 21 additions & 0 deletions travis/travis-retry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Copied from https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_retry.bash
travis_retry() {
local result=0
local count=1
while [[ "${count}" -le 3 ]]; do
[[ "${result}" -ne 0 ]] && {
echo -e "\\n${ANSI_RED}The command \"${*}\" failed. Retrying, ${count} of 3.${ANSI_RESET}\\n" >&2
}
"${@}" && { result=0 && break; } || result="${?}"
count="$((count + 1))"
sleep 1
done

[[ "${count}" -gt 3 ]] && {
echo -e "\\n${ANSI_RED}The command \"${*}\" failed 3 times.${ANSI_RESET}\\n" >&2
}

return "${result}"
}

0 comments on commit e1e66d3

Please sign in to comment.