This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from alphagov/travis-tag-releases
Travis tags the repo with a release_??? tag
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/bin/bash -ex | ||
|
||
# This script is run by Travis after the current commit passes all the tests. | ||
# It creates the following tags and pushes them to the repo: | ||
# - release_<travis build number> | ||
# - release | ||
# | ||
# This requires a GitHub token with permission to write to the repo. | ||
|
||
|
||
##### TESTING LOCALLY ##### | ||
|
||
# To test locally we need to fake the environment variables provided by Travis. | ||
# | ||
# Do this by setting LOCAL_TEST_MODE to "true" and TESTING_GITHUB_TOKEN to a | ||
# token you create in github with ``public_repo`` permission. | ||
|
||
|
||
LOCAL_TEST_MODE="false" | ||
TESTING_GITHUB_TOKEN="make-yourself-one-in-github" | ||
|
||
|
||
##### RUNNING IN TRAVIS ##### | ||
|
||
# When running in Travis the GH_TOKEN variable is set by Travis itself by | ||
# decrypting the ``secure`` section from the .travis.yml file | ||
|
||
# To create a new token, follow these steps: | ||
# | ||
# - create a new token in GitHub with the ``public_repo`` permission | ||
# (preferably as gds-ci-pp user) | ||
# - /var/apps/stagecraft | ||
# - sudo gem install travis | ||
# - travis encrypt --add GH_TOKEN=the-token-from-github | ||
|
||
# For Travis encrypted environment variables, see: | ||
# - http://docs.travis-ci.com/user/encryption-keys/ | ||
|
||
# Get the public key of your repo with: | ||
# - https://api.travis-ci.org/repos/alphagov/stagecraft/key | ||
|
||
# For Travis environment variables, see | ||
# http://docs.travis-ci.com/user/ci-environment/ | ||
|
||
# For a similar example of working with Github and Travis, see: | ||
# - http://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/ | ||
|
||
function ensure_running_in_travis_master_branch { | ||
|
||
if [ "$TRAVIS" != "true" ]; then | ||
echo "Not running outside of Travis." | ||
exit 1 | ||
fi | ||
|
||
if [ "$TRAVIS_BRANCH" != "master" ]; then | ||
echo "Not pushing release tag, not on Travis master." | ||
exit 2 | ||
fi | ||
} | ||
|
||
function make_temp_repo_directory { | ||
TMP_REPO_DIR=$(mktemp --directory --suffix _travis_${TRAVIS_BUILD_NUMBER}) | ||
} | ||
|
||
function clone_repo { | ||
|
||
git clone https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} ${TMP_REPO_DIR} | ||
} | ||
|
||
function make_release_tag_from_travis_build_number { | ||
pushd ${TMP_REPO_DIR} | ||
|
||
git checkout ${TRAVIS_COMMIT} | ||
git tag "${RELEASE_BRANCH_NAME}_${TRAVIS_BUILD_NUMBER}" | ||
git push origin --tags | ||
|
||
git tag "${RELEASE_BRANCH_NAME}" | ||
git push --force origin --tags | ||
|
||
popd | ||
} | ||
|
||
function setup_fake_travis_environment { | ||
echo "Setting up fake Travis environment" | ||
TRAVIS="true" | ||
TRAVIS_REPO_SLUG="alphagov/stagecraft" | ||
TRAVIS_BRANCH="master" | ||
TRAVIS_COMMIT="3aed87b4f7bbb62e15fef65bd9a1b27d07d6e351" | ||
TRAVIS_BUILD_NUMBER="123456789" | ||
GH_TOKEN="${TESTING_GITHUB_TOKEN}" | ||
} | ||
|
||
if [ "${LOCAL_TEST_MODE}" == "true" ]; then | ||
setup_fake_travis_environment | ||
RELEASE_BRANCH_NAME="release_testing" | ||
else | ||
RELEASE_BRANCH_NAME="release" | ||
fi | ||
|
||
|
||
|
||
ensure_running_in_travis_master_branch | ||
make_temp_repo_directory | ||
clone_repo | ||
make_release_tag_from_travis_build_number | ||
|