forked from ReactionMechanismGenerator/RMG-database
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
79 lines (63 loc) · 2.21 KB
/
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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
set -e # exit with nonzero exit code if anything fails
openssl aes-256-cbc -K $encrypted_02f40ca58e32_key -iv $encrypted_02f40ca58e32_iv -in deploy_key.enc -out deploy_key -d
echo 'Travis Build Dir: '$TRAVIS_BUILD_DIR
if $TRAVIS_PULL_REQUEST
then
DEPLOY_BRANCH=$TRAVIS_PULL_REQUEST
else
DEPLOY_BRANCH=$TRAVIS_BRANCH
fi
# Deploy built site to this branch
echo Deploy branch: $DEPLOY_BRANCH
# SSH URL of the RMG/RMG-tests repo that is pushed to:
[email protected]:ReactionMechanismGenerator/RMG-tests.git
if [ -n "$TRAVIS_BUILD_ID" ]; then
#
# Set the following environment variables in the travis configuration (.travis.yml)
#
# DEPLOY_BRANCH - The only branch that Travis should deploy from
# GIT_NAME - The Git user name
# GIT_EMAIL - The Git user email
#
GIT_NAME="Travis Deploy"
GIT_EMAIL="[email protected]"
echo DEPLOY_BRANCH: $DEPLOY_BRANCH
echo GIT_NAME: $GIT_NAME
echo GIT_EMAIL: $GIT_EMAIL
if [ "$TRAVIS_BRANCH" != "$DEPLOY_BRANCH" ]; then
echo "Travis should only deploy from the DEPLOY_BRANCH ($DEPLOY_BRANCH) branch"
exit 0
else
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
echo "Travis should not deploy from pull requests"
exit 0
else
# use the decrypted deploy SSH key as
# the credentials to push to the RMG-tests repo:
chmod 600 deploy_key
eval `ssh-agent -s`
ssh-add deploy_key
git config --global user.name "$GIT_NAME"
git config --global user.email "$GIT_EMAIL"
fi
fi
fi
# create a temporary folder:
REPO_NAME=$(basename $REPO)
TARGET_DIR=$(mktemp -d /tmp/$REPO_NAME.XXXX)
REV=$(git rev-parse HEAD)
# clone RMG-tests repo in the newly created folder:
git clone ${REPO} ${TARGET_DIR}
# go inside the newly created folder:
cd $TARGET_DIR
# create a new branch in RMG-tests with the name equal to
# the branch name of the tested RMG-database branch:
RMGTESTSBRANCH=rmgdb-$DEPLOY_BRANCH
git checkout -b $RMGTESTSBRANCH || true
git checkout $RMGTESTSBRANCH
# create an empty commit with the SHA-ID of the
# tested commit of the RMG-database branch:
git commit --allow-empty -m rmgdb-$REV
# push to the branch to the RMG/RMG-tests repo:
git push -f $REPO $RMGTESTSBRANCH > /dev/null