-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdeploy.sh
executable file
·62 lines (51 loc) · 1.92 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
#!/bin/bash
cp ./now.json ./output/dist
PROD_BRANCHES=("master" "v6" "v7" "v8")
function contains() {
local n=$#
local value=${!n}
for ((i=1;i < $#;i++)) {
if [ "${!i}" == "${value}" ] ; then
echo "y"
return 0
fi
}
echo "n"
return 1
}
prefix=""
if [ "$DOMAIN_PREFIX" != "" ] ; then
prefix="$DOMAIN_PREFIX-"
fi
name="${prefix}dojo-io"
if [ "$1" != "" ] ; then
name="$1-${prefix}dojo-io"
fi
echo "Deploying ${name}...";
if [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
echo "npx now ./output/dist --token=$PUBLIC_NOW_TOKEN --public --name=$name --confirm";
nowurl=$(npx now ./output/dist --token=$PUBLIC_NOW_TOKEN --public --name=$name --confirm)
if [ "$nowurl" = "" ] ; then
echo "Now deployment failed"
exit 1
fi
echo "* $name: $nowurl" &>> deployments.txt
else
if [ $(contains "${PROD_BRANCHES[@]}" "$TRAVIS_BRANCH") == "y" ] ; then
nowurl=$(npx now ./output/dist --token=$NOW_TOKEN --public --name=$name --scope=dojo --prod --confirm)
if [ "$nowurl" = "" ] ; then
echo "Now deployment failed"
exit 1
fi
echo "Deployed to $nowurl"
if [ "$name" = "dojo-io" ] ; then
deploymenturl=$(curl -H "Authorization: Bearer $GITHUB_TOKEN" -H "Content-Type: application/vnd.github.v3+json" -s -X POST https://api.github.com/repos/$TRAVIS_REPO_SLUG/deployments -d '{"ref": "'$TRAVIS_COMMIT'","environment": "production","description": "Deploy request from Travis","auto_merge":false,"required_contexts":[]}' | jq -r '.url')
if [ "$deploymenturl" = "null" ] ; then
echo "Failed creating github deployment"
exit 1
fi
echo "Github deployment url $deploymenturl"
curl -H "Authorization: Bearer $GITHUB_TOKEN" -H "Content-Type: application/vnd.github.v3+json" -s -X POST $deploymenturl/statuses -d '{"environment": "production", "state": "success", "target_url": "'$nowurl'", "log_url": "'$nowurl'/_logs", "environment_url": "'$nowurl'", "description": "Deployment finished successfully."}'
fi
fi
fi