generated from jdillard/continuous-sphinx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.sh
executable file
·35 lines (28 loc) · 1.24 KB
/
restore.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
#!/usr/bin/env bash
# die on error
set -e
# https://developer.travis-ci.org/resource/builds#Builds
echo 'Retrieving last successful Travis-CI build...'
for row in $(curl -H "Travis-API-Version: 3" -H "User-Agent: API Explorer" -H "Authorization: token $TRAVISCI_API_KEY" https://api.travis-ci.org/builds?limit=10 | jq -r '.builds[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
if [ $(_jq '.state') == "passed" ]; then
good_build=$(_jq '.commit.sha')
break
fi
done
# https://www.netlify.com/docs/api/#deploys
echo "Retrieving Netlify deploy for Travis-CI build ${good_build}..."
for row in $(curl -H "Authorization: Bearer $NETLIFY_PUBLISH_KEY" https://api.netlify.com/api/v1/sites/kiwipedia.netlify.com/deploys | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
deploy_commit=$(_jq '.commit_ref')
if [ "$deploy_commit" == "$good_build" ]; then
good_deploy=$(_jq '.id')
fi
done
# https://www.netlify.com/docs/api/#deploys
echo "Publishing Netlify build ${good_deploy}..."
curl -X POST -H "Authorization: Bearer $NETLIFY_PUBLISH_KEY" -d "{}" "https://api.netlify.com/api/v1/sites/kiwipedia.netlify.com/deploys/${good_deploy}/restore"