forked from shoukoo/golang-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 3
/
release.sh
executable file
·35 lines (28 loc) · 840 Bytes
/
release.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
#!/bin/sh
set -exuo pipefail
EVENT_DATA=$(cat $GITHUB_EVENT_PATH)
UPLOAD_URL=$(echo $EVENT_DATA | jq -r .release.upload_url)
UPLOAD_URL=${UPLOAD_URL/\{?name,label\}/}
PROJECT_NAME=$(basename $GITHUB_REPOSITORY)
EXT=""
if [ $GOOS == 'windows' ]; then
EXT='.exe'
fi
NAME="${PROJECT_NAME}-${GOOS}-${GOARCH}${EXT}"
echo "Building $NAME under $GOOS/$GOARCH"
go build -o "${PROJECT_NAME}"
tar cvfz tmp.tgz "${PROJECT_NAME}"
CHECKSUM=$(sha256sum tmp.tgz | cut -d ' ' -f 1)
curl \
--fail \
-X POST \
--data-binary @tmp.tgz\
-H 'Content-Type: application/octet-stream' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${UPLOAD_URL}?name=${NAME}.tar.gz"
curl \
-X POST \
--data "$CHECKSUM" \
-H 'Content-Type: text/plain' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${UPLOAD_URL}?name=${NAME}_checksum_sha256.txt"