This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.sh
executable file
·66 lines (57 loc) · 1.97 KB
/
generate.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
set -euxo pipefail
setup_git() {
git config user.email "<[email protected]>"
git config user.name "Data Rebuild (via TravisCI)"
# add git auth
eval "$(ssh-agent -s)" #start the ssh agent
set +x
openssl aes-256-cbc -K $encrypted_d99de3c51fb1_key -iv $encrypted_d99de3c51fb1_iv -in deploy_key.enc -out deploy_key -d
set -x
chmod 600 deploy_key # this key should have push access
ssh-add deploy_key
git remote set-url origin [email protected]:OpenUpSA/static-budget-portal.git
}
regenerate_data() {
if [[ "${TRAVIS_COMMIT_MESSAGE}" == *"[staging]"* ]]
then
echo -n "STAGING"
export PORTAL_URL=https://dynamicbudgetportal-staging.openup.org.za/
else
echo -n "PROD"
fi
python generate/from_dynamic.py 1>&2
}
# Initialise REMOTE_TRIGGER if it isn't set.
# https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash/13864829#13864829
# Since we use -u to error when variables are unexpectedly not set, we use
# conditional substitution (+notnull) so that the conditional expression
# below doesn't error, and its result be true if REMOTE_TRIGGER wasn't set.
if [ -z ${REMOTE_TRIGGER+notnull} ]
then
REMOTE_TRIGGER="false"
fi
if [ "${TRAVIS_PULL_REQUEST}" = "true" ]
then
echo "Ignoring pull request"
elif [[ "${TRAVIS_COMMIT_MESSAGE}" == *"[ci]"* ]] || [[ "${REMOTE_TRIGGER}" == "true" ]]
then
setup_git
git log -n 2
git pull origin $TRAVIS_BRANCH
git log -n 2
DATA_ENVIRONMENT=$(regenerate_data)
if [[ `git status --porcelain | grep -v deploy_key` ]]
then
# save changes
git add .
# !!! ENSURE WE DON'T COMMIT PLAINTEXT DEPLOY PRIVATE KEY !!!
git reset -- deploy_key
git commit -m "Updated data via TravisCI using ${DATA_ENVIRONMENT} data server"
echo "Deploying to GitHub"
git push origin HEAD:$TRAVIS_BRANCH
else
echo "No changes to commit."
fi
else
echo "No data update requested."
fi