forked from livepeer/go-livepeer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_build.sh
executable file
·96 lines (81 loc) · 2.81 KB
/
upload_build.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
#!/bin/bash
# CI script for uploading builds.
set -e
set -o nounset
if [[ $(uname) == *"MSYS"* ]]; then
ARCH="windows"
EXT=".exe"
else
ARCH=$(uname | tr '[:upper:]' '[:lower:]')
EXT=""
if [[ -n "${RELEASE_TAG:-}" ]]; then
ARCH="$ARCH-$RELEASE_TAG"
fi
fi
BASE="livepeer-$ARCH-amd64"
BRANCH="${TRAVIS_BRANCH:-unknown}"
if [[ "${GHA_REF:-}" != "" ]]; then
BRANCH="$(echo $GHA_REF | sed 's/refs\/heads\///')"
fi
VERSION="$(./print_version.sh)"
if echo $VERSION | grep dirty; then
echo "Error: git state dirty, refusing to upload build"
git diff | cat
git status
exit 1
fi
# If we want to build with branch --> network support for any other networks, add them here!
NETWORK_BRANCHES="rinkeby mainnet"
# If the binaries are built off a network branch then the resource path should include the network branch name i.e. X.Y.Z/rinkeby or X.Y.Z/mainnet
# If the binaries are not built off a network then the resource path should only include the version i.e. X.Y.Z
VERSION_AND_NETWORK=$VERSION
for networkBranch in $NETWORK_BRANCHES; do
if [[ $BRANCH == "$networkBranch" ]]; then
VERSION_AND_NETWORK="$VERSION/$BRANCH"
fi
done
NODE="./livepeer${EXT}"
CLI="./livepeer_cli${EXT}"
BENCH="./livepeer_bench${EXT}"
ROUTER="./livepeer_router${EXT}"
mkdir $BASE
cp $NODE $BASE
cp $CLI $BASE
cp $BENCH $BASE
cp $ROUTER $BASE
# do a basic upload so we know if stuff's working prior to doing everything else
if [[ $ARCH == "windows" ]]; then
FILE=$BASE.zip
zip -r ./$FILE ./$BASE
else
FILE=$BASE.tar.gz
tar -czvf ./$FILE ./$BASE
fi
FILE_SHA256=`shasum -a 256 ${FILE}`
# Quick self-check to see if the thing can execute at all
(cd $BASE && $NODE -version)
if [[ "${GCLOUD_KEY:-}" == "" ]]; then
echo "GCLOUD_KEY not found, not uploading to Google Cloud."
exit 0
fi
# https://stackoverflow.com/a/44751929/990590
bucket=build.livepeer.live
resource="/${bucket}/${VERSION_AND_NETWORK}/${FILE}"
contentType="application/x-compressed-tar"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${GCLOUD_SECRET} -binary | base64`
fullUrl="https://storage.googleapis.com${resource}"
# Failsafe - don't overwrite existing uploads!
if curl --head --fail $fullUrl 2>/dev/null; then
echo "$fullUrl already exists, not overwriting!"
exit 0
fi
curl -X PUT -T "${FILE}" \
-H "Host: storage.googleapis.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${GCLOUD_KEY}:${signature}" \
$fullUrl
curl --fail -s -H "Content-Type: application/json" -X POST -d "{\"content\": \"Build succeeded ✅\nBranch: $BRANCH\nPlatform: $ARCH-amd64\nLast commit: $(git log -1 --pretty=format:'%s by %an')\nhttps://build.livepeer.live/$VERSION_AND_NETWORK/${FILE}\nSHA256:\n${FILE_SHA256}\"}" $DISCORD_URL 2>/dev/null
echo "done"