Skip to content

Commit

Permalink
perf(Travis): beautify bash command
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Oct 26, 2020
1 parent 037e9b1 commit 5750e06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ install: skip
# Grant execute permission to prevent error like:
# xxx.sh: Permission denied
before_script:
- "echo [INSTALL] INFO Grant execute permission"
- NOW=$(date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23)
- echo "$NOW INFO --- [INSTALL] Grant execute permission"
- chmod +x .travis/install.sh
- chmod +x .travis/deploy.sh
- chmod +x mvnw
Expand Down
29 changes: 20 additions & 9 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,58 @@
# https://stackoverflow.com/questions/19622198/what-does-set-e-mean-in-a-bash-script
set -e

NOW=$(date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23)

# Check the variables are set
if [ -z "$OSSRH_USERNAME" ]; then
echo "[Deployment] ERROR - Missing environment value: OSSRH_USERNAME" >&2
echo "$NOW ERROR --- [DEPLOY] Missing environment value: OSSRH_USERNAME" >&2
exit 1
fi

if [ -z "$OSSRH_PASSWORD" ]; then
echo "[Deployment] ERROR - Missing environment value: OSSRH_PASSWORD" >&2
echo "$NOW ERROR --- [DEPLOY] Missing environment value: OSSRH_PASSWORD" >&2
exit 1
fi

if [ -z "$GPG_KEY_NAME" ]; then
echo "[Deployment] ERROR - Missing environment value: GPG_KEY_NAME" >&2
echo "$NOW ERROR --- [DEPLOY] Missing environment value: GPG_KEY_NAME" >&2
exit 1
fi

if [ -z "$GPG_PASSPHRASE" ]; then
echo "[Deployment] ERROR - Missing environment value: GPG_PASSPHRASE" >&2
echo "$NOW ERROR --- [DEPLOY] Missing environment value: GPG_PASSPHRASE" >&2
exit 1
fi

echo "[Deployment] INFO - All expected variables are set. OSSRH_USERNAME, OSSRH_PASSWORD, GPG_KEY_NAME and GPG_PASSPHRASE"
echo "$NOW INFO --- [DEPLOY] All expected variables are set. OSSRH_USERNAME, OSSRH_PASSWORD, GPG_KEY_NAME and GPG_PASSPHRASE" >&2

# If decrypted file .travis/gpg.asc not exists
if [ ! -f "${TRAVIS_BUILD_DIR}/.travis/gpg.asc" ]; then
echo "[Deployment] ERROR - Missing decrypted file: .travis/gpg.asc" >&2
echo "$NOW ERROR --- [DEPLOY] Missing decrypted file: .travis/gpg.asc" >&2
exit 1
else
echo "[Deployment] INFO - Found decrypted file: .travis/gpg.asc"
echo "$NOW INFO --- [DEPLOY] Found decrypted file: .travis/gpg.asc"
fi

# Prepare the local keyring (requires travis to have decrypted the file beforehand)
gpg --fast-import .travis/gpg.asc

# If `TRAVIS_TAG` string is not empty
if [ -n "$TRAVIS_TAG" ]; then
echo "[Deployment] INFO - Maven deploy on a tag -> set pom.xml <version> to TRAVIS_TAG: $TRAVIS_TAG"
echo "$NOW WARN --- [DEPLOY] Maven deploy on a tag -> set pom.xml <version> to TRAVIS_TAG: $TRAVIS_TAG"
mvn --settings "${TRAVIS_BUILD_DIR}/.travis/maven-settings.xml" org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=$TRAVIS_TAG 1>/dev/null 2>/dev/null
else
echo "[Deployment] INFO - Maven deploy not on a tag -> keep snapshot version in pom.xml"
echo "$NOW WARN --- [DEPLOY] Maven deploy not on a tag -> keep snapshot version in pom.xml"
fi

# Run the maven deploy steps
mvn deploy -P publish -DskipTests=true --quiet --settings "${TRAVIS_BUILD_DIR}/.travis/maven-settings.xml"

DEPLOY_COMMAND_RESULT=$?

if [ "$DEPLOY_COMMAND_RESULT" -eq 0 ]; then
echo "$NOW INFO --- [DEPLOY] Deployment succeed. DEPLOY_COMMAND_RESULT: $DEPLOY_COMMAND_RESULT"
else
echo "$NOW ERROR --- [DEPLOY] Deployment failed. DEPLOY_COMMAND_RESULT: $DEPLOY_COMMAND_RESULT" >&2
exit 1
fi
11 changes: 4 additions & 7 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
# https://stackoverflow.com/questions/19622198/what-does-set-e-mean-in-a-bash-script
set -e

function now() {
echo date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23
return 0
}
NOW=$(date +%Y-%m-%d' '%H:%M:%S.%N | cut -b 1-23)

CURRENT_DIR=$(pwd)
echo "$(now) INFO --- [INSTALL] CURRENT_DIR: $CURRENT_DIR"
echo "$NOW INFO --- [INSTALL] CURRENT_DIR: $CURRENT_DIR"
command "ls"

# Run the Maven clean install
Expand All @@ -19,8 +16,8 @@ command "ls"
INSTALL_COMMAND_RESULT=$?

if [ "$INSTALL_COMMAND_RESULT" -eq 0 ]; then
echo "$(now) INFO --- [INSTALL] Installation succeed. INSTALL_COMMAND_RESULT: $INSTALL_COMMAND_RESULT"
echo "$NOW INFO --- [INSTALL] Installation succeed. INSTALL_COMMAND_RESULT: $INSTALL_COMMAND_RESULT"
else
echo "$(now) INFO --- [INSTALL] Installation failed. INSTALL_COMMAND_RESULT: $INSTALL_COMMAND_RESULT" >&2
echo "$NOW ERROR --- [INSTALL] Installation failed. INSTALL_COMMAND_RESULT: $INSTALL_COMMAND_RESULT" >&2
exit 1
fi

0 comments on commit 5750e06

Please sign in to comment.