-
Notifications
You must be signed in to change notification settings - Fork 61
/
deploy-website.sh
101 lines (79 loc) · 2.18 KB
/
deploy-website.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# If there are any errors, fail Travis
set -e
# Set a default API environment for other branches/pull requests
APIENVIRONMENT=1
# Define variables depending on the branch
if [[ $TRAVIS_BRANCH == 'release' ]]
then
AZURE_WEBSITE=$PROD_AZURE_WEBSITE
APP_INSIGHTS_KEY=$PROD_APP_INSIGHTS_KEY
APIENVIRONMENT=3
fi
if [[ $TRAVIS_BRANCH == 'uat' ]]
then
AZURE_WEBSITE=$UAT_AZURE_WEBSITE
APP_INSIGHTS_KEY=$UAT_APP_INSIGHTS_KEY
APIENVIRONMENT=2
fi
if [[ $TRAVIS_BRANCH == 'develop' ]]
then
AZURE_WEBSITE=$DEV_AZURE_WEBSITE
APP_INSIGHTS_KEY=''
APIENVIRONMENT=1
fi
# if not live
if [[ $TRAVIS_BRANCH == 'develop' ]] || [[ $TRAVIS_BRANCH == 'uat' ]]
then
cd src/files
# block robots
echo "User-agent: *" > robots.txt
echo "Disallow /" >> robots.txt
echo "robots.txt rewritten to:"
cat robots.txt
# delete google site verification
rm googledcd9eb47a9ac8a14.html
cd ../../
fi
# Get the commit details
THE_COMMIT=`git rev-parse HEAD`
# Set git details
git config --global user.email "[email protected]"
git config --global user.name "Travis CI"
# Set environment
cd src/js
rm env.js
cat > env.js << EOF
module.exports = $APIENVIRONMENT
EOF
echo "env.js file rewritten to:"
cat env.js
cd ../../
# Create version.txt
cd src/files
cat > version.txt << EOF
$DATE
EOF
cd ../../
# Set appInsightsKey
cd src/data
sed -i.bak "s/\"appInsightsKey\": \".*\"/\"appInsightsKey\": \"$APP_INSIGHTS_KEY\"/" site.json
cd ../../
# Run gulp
gulp deploy --debug --production
if [[ $TRAVIS_PULL_REQUEST == 'false' ]]
then
# Move to created directory
cd _dist
# Push to git by overriding previous commits
# IMPORTANT: Supress messages so nothing appears in logs
if [[ $TRAVIS_BRANCH == 'release' ]] || [[ $TRAVIS_BRANCH == 'uat' ]] || [[ $TRAVIS_BRANCH == 'develop' ]]
then
git init
git add -A
git commit -m "Travis CI automatic build for $THE_COMMIT"
git push --quiet --force "https://${AZURE_USER}:${AZURE_PASSWORD}@${AZURE_WEBSITE}.scm.azurewebsites.net:443/${AZURE_WEBSITE}.git" master > /dev/null 2>&1
else
echo "Not on a build branch so don't push the changes"
fi
fi