Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
Version release pipeline steps triggered by git tag (GitHub release) (#…
Browse files Browse the repository at this point in the history
…14)

Trigger release/publish steps based upon git tags rather than master branch
  • Loading branch information
rconway authored Jun 19, 2020
1 parent 6ab0657 commit 40f5d49
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
28 changes: 16 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
sudo: required
language: java
install: true

jdk: openjdk11
install: skip

services:
- docker

jobs:
include:
- stage: build (compile, unit test, package)
language: java
jdk: openjdk11
install: skip
script: travis/build.sh

- stage: container creation and publishing
install: skip
script: travis/containerCreation.sh
- stage: container creation
script:
- travis/containerCreation.sh

- stage: smoke and acceptance test
language: minimal
install: skip # without this there's a `git clone` and `gradlew assemble` executed!
script: travis/acceptanceTest.sh

- stage: release
if: branch = master AND NOT type IN (pull_request)
- stage: release and tag on DockerHub
if: tag =~ ^v[0-9.]*$
language: minimal
install: skip
script: travis/release.sh
post_script: travis/delete-dockerhub-images.sh
deploy:
provider: script
script: travis/release.sh
on:
tags: true
after_deploy:
- travis/delete-dockerhub-images.sh

import:
- docs/.travis.yml
Expand Down
4 changes: 3 additions & 1 deletion docs/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
jobs:
include:
- stage: generate docs
if: branch = master AND NOT type IN (pull_request)
if: tag =~ ^v[0-9.]*$
language: minimal
install: skip

# Assume that 'docker' service is stated at the Travis global level. It seems that re-stating it here confuses Travis.
# services:
Expand Down
12 changes: 8 additions & 4 deletions travis/containerCreation.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# fail fast settings from https://dougrichardson.org/2018/08/03/fail-fast-bash-scripting.html
set -euov pipefail
set -eov pipefail

# obtain current repository name
REPO_LOCAL_PATH=`git rev-parse --show-toplevel`
Expand All @@ -18,6 +18,10 @@ buildTag=travis_$TRAVIS_BUILD_NUMBER # We use a temporary build number for taggi
docker build -t eoepca/${REPO_NAME} .
docker tag eoepca/${REPO_NAME} eoepca/${REPO_NAME}:$buildTag # Tags container in EOEPCA repository with buildTag

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

docker push eoepca/${REPO_NAME}:$buildTag # defaults to docker hub EOEPCA repository
if [ -n "${DOCKER_USERNAME}" -a -n "${DOCKER_PASSWORD}" ]
then
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push eoepca/${REPO_NAME}:$buildTag # defaults to docker hub EOEPCA repository
else
echo "WARNING: No credentials - Cannot push to docker hub"
fi
23 changes: 14 additions & 9 deletions travis/release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# fail fast settings from https://dougrichardson.org/2018/08/03/fail-fast-bash-scripting.html
set -euov pipefail
set -eov pipefail

# Check presence of environment variables
TRAVIS_BUILD_NUMBER="${TRAVIS_BUILD_NUMBER:-0}"
Expand All @@ -13,13 +13,18 @@ REPO_NAME=`basename $REPO_LOCAL_PATH`
# Create a Docker image and tag it as 'travis_<build number>'
buildTag=travis_$TRAVIS_BUILD_NUMBER # We use a temporary build number for tagging, since this is a transient artefact

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker pull eoepca/${REPO_NAME}:${buildTag} # have to pull locally in order to tag as a release
if [ -n "${DOCKER_USERNAME}" -a -n "${DOCKER_PASSWORD}" ]
then
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker pull eoepca/${REPO_NAME}:${buildTag} # have to pull locally in order to tag as a release

# Tag and push as a Release following the SemVer approach, e.g. 0.1.1-Alpha
docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:release_${TRAVIS_TAG} # This recovers the GitHub release/tag number
docker push eoepca/${REPO_NAME}:release_${TRAVIS_TAG}
# Tag and push as a Release following the SemVer approach, e.g. 0.1.1-Alpha
docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:${TRAVIS_TAG} # This recovers the GitHub release/tag number
docker push eoepca/${REPO_NAME}:${TRAVIS_TAG}

# Tag and push as `latest`
docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:latest
docker push eoepca/${REPO_NAME}:latest
# Tag and push as `latest`
docker tag eoepca/${REPO_NAME}:${buildTag} eoepca/${REPO_NAME}:latest
docker push eoepca/${REPO_NAME}:latest
else
echo "WARNING: No credentials - Cannot push to docker hub"
fi

0 comments on commit 40f5d49

Please sign in to comment.