-
Notifications
You must be signed in to change notification settings - Fork 6
/
codepipeline_deploy.sh
executable file
·35 lines (29 loc) · 1.31 KB
/
codepipeline_deploy.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
#!/bin/bash
set -e
if [ ! -z "${TRAVIS_TAG}" ]; then
# Do not run for builds triggered by tagging.
echo "Skipping $0 $@"
exit 0
fi
# Get the HEAD commit ID for version.json in master branch if exists
set +e # May fail
BRANCH_INFO=`aws codecommit get-branch --repository-name $APP_MANIFEST_REPO --branch-name mainline`
BRANCH_INFO_STATUS=$?
set -e
if [ $BRANCH_INFO_STATUS -ne 0 ]; then
echo "Could not find mainline branch for repository $APP_MANIFEST_REPO. Creating first commit."
else
export BRANCH_COMMIT_ID=`echo $BRANCH_INFO | jq -r '.branch.commitId'`
fi
export PARENT_COMMIT_FLAG=""
if [ -n "$BRANCH_COMMIT_ID" ]; then
PARENT_COMMIT_FLAG="--parent-commit-id=$BRANCH_COMMIT_ID"
fi
if [ -z "$SA_VERSION" ]; then
echo "No application version set, did add_tag run?"
exit 1
fi
TIMESTAMP=`date +%s`
aws codecommit put-file --repository-name "$APP_MANIFEST_REPO" --branch-name mainline --file-content "{\"application_version\": \"$SA_VERSION\",\"timestamp\":\"$TIMESTAMP\"}" --file-path "/version.json" --commit-message "Updating to version $SA_VERSION. Commit for this version bump: $TRAVIS_COMMIT" --name "$GH_USER_NAME" --email "$GH_USER_EMAIL" $PARENT_COMMIT_FLAG
# Restore default setting to be able to safely source this script in Travis: https://github.com/travis-ci/travis-ci/issues/891
set +e