-
Notifications
You must be signed in to change notification settings - Fork 6
/
add_tag.sh
executable file
·41 lines (36 loc) · 1.73 KB
/
add_tag.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
set -e
if [ ! -z "${TRAVIS_TAG}" ]; then
# Do not run for builds triggered by tagging.
echo "Skipping $0 $@"
exit 0
fi
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Set up GitHub SSH Deploy Key
if [ ! -f ~/.ssh/github_deploy.pem ]; then
cat $SCRIPT_DIR/ssh-config >> ~/.ssh/config && eval `ssh-agent -s`
chmod 400 $TRAVIS_BUILD_DIR/github_deploy.pem && mv $TRAVIS_BUILD_DIR/github_deploy.pem ~/.ssh/ && ssh-add ~/.ssh/github_deploy.pem
fi
if [ ! -z "${SHOULD_UPDATE_VERSION}" ]; then
# Use git tag for versioning, updating package.xml in the process
# Figure out what's the new version
python $SCRIPT_DIR/update_version.py "$TRAVIS_BUILD_DIR/version.json" "`git describe --abbrev=0 --tags 2>&1`"
export SA_VERSION=`cat $TRAVIS_BUILD_DIR/version.json | jq -r .application_version`
# Set Travis fake user & email
git config --global user.email "${GH_USER_EMAIL}"
git config --global user.name "${GH_USER_NAME}"
# Switch to SSH url
git remote set-url origin git@github.com:${TRAVIS_REPO_SLUG}.git
# Add and push tag
git tag -a $SA_VERSION -m "Release $SA_VERSION"
git push origin $SA_VERSION
else
# Use Travis build number for versioning; Git tags & package manifest will not be updated.
stored_pwd=`pwd`
cd $SCRIPT_DIR && CURRENT_SA_VERSION=`python -c "import update_version; print update_version.get_current_package_xml_version()"`
cd $stored_pwd
export SA_VERSION=${CURRENT_SA_VERSION}.${TRAVIS_BUILD_NUMBER}
echo {\"application_version\": \"${SA_VERSION}\"} > "$TRAVIS_BUILD_DIR/version.json"
fi
# Restore default setting to be able to safely source this script in Travis: https://github.com/travis-ci/travis-ci/issues/891
set +e