Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Travis tags the repo with a release_??? tag #54

Merged
merged 3 commits into from
Feb 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ python:
install:
- pip install -r requirements/ci.txt --use-mirrors
env:
matrix:
- DJANGO_SETTINGS_MODULE=stagecraft.settings.ci SECRET_KEY=xyz DATABASE_URL=postgres://a:b@foo:999/db
global:
# NOTE: contains GH_TOKEN=xxx from github user gds-pp-ci
secure: gY2BW8rNmXa3oc2mWv0a3780E+DEOh4ETXfz1DVDACuOMbm3PXzu5TRvAN4XcKc8biUlCHyx8ReeZzcya5M3/4dQA9LYBdSzXb4JFcWpYyxIKwrqQVeKbR79BNTYLGtJ700uJRV2lXqvLSZJD5A8CaLeoNhlBKIBjZaE1+z07Is=
script:
- ./run_tests.sh
after_script:
- coveralls
after_success:
- ./.travis_scripts/push_release_tag.sh
branches:
except:
- release
Expand Down
106 changes: 106 additions & 0 deletions .travis_scripts/push_release_tag.sh
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