-
Notifications
You must be signed in to change notification settings - Fork 22
/
create_release.sh
executable file
·90 lines (82 loc) · 2.81 KB
/
create_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
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
#!/bin/bash
VERSION=`awk '/^const BEETLE_VERSION =/ { gsub(/"/, ""); print $4}' go/version.go`
TAG="v$VERSION"
BASEURL="https://github.com/gitapi/repos/xing/beetle"
if test -z "$GITHUB_COM_USER"; then
echo please set environment variable GITHUB_COM_USER
exit 1
fi
if test -z "$GITHUB_COM_API_TOKEN"; then
echo please set environment variable GITHUB_COM_API_TOKEN
exit 1
fi
AUTHENTICATION="--basic --user $GITHUB_COM_USER:$GITHUB_COM_API_TOKEN"
read -r -d '' DESC <<EOF
Downloads:\n\`curl -L https://github.com/xing/beetle/releases/download/$TAG/linux.tar.gz\`\n\`curl -L https://github.com/xing/beetle/releases/download/$TAG/darwin.tar.gz\`
EOF
read -r -d '' POST_DATA <<EOF
{
"tag_name": "$TAG",
"target_commitish": "master",
"name": "$TAG",
"body": "$DESC",
"draft": false,
"prerelease": false
}
EOF
read -r -d '' PATCH_DATA <<EOF
{
"body": "$DESC",
"draft": false,
"prerelease": false
}
EOF
function get_release() {
JSON=$(curl -s $BASEURL/releases/tags/$TAG)
# echo "==========" $JSON
ID=$(echo $JSON | awk '{for(i=1;i<=NF;i++){ if($i=="\"id\":"){ gsub(",", ""); print $(i+1)} } }' | head -1)
# echo "----------" $ID
}
function verify_ID() {
# verify we got the right id
JSON2=$(curl -s $BASEURL/releases/$ID)
if test -z "$JSON2"; then
echo "release id could bot be retrieved"
exit 1
fi
if [ "$JSON" != "$JSON2" ]; then
echo "release id '$ID' could bot be verified"
exit 1
fi
}
get_release
if test -z "$ID"; then
RESPONSE=$(curl -s $AUTHENTICATION -H 'Accept: application/vnd.github.v3+json' -d "$POST_DATA" $BASEURL/releases)
if [ $? != 0 ]; then
echo "could not create release"
exit 1
fi
get_release
verify_ID
else
verify_ID
# update the release
RESPONSE=$(curl -s $AUTHENTICATION -H 'Accept: application/vnd.github.v3+json' -XPATCH -d "$PATCH_DATA" $BASEURL/releases/$ID)
if [ $? != 0 ]; then
echo "could not update release"
exit 1
fi
fi
UPLOAD_URL=$(echo $JSON | awk '{for(i=1;i<=NF;i++){ if($i=="\"upload_url\":"){ gsub(/[",]/, ""); gsub(/[\{][?]namelabel[\}]/, ""); print $(i+1); } } }')
echo uploading linux binaries using $UPLOAD_URL
RESPONSE=$(curl -s $AUTHENTICATION -H 'Accept: application/vnd.github.v3+json' -H 'Content-Type: application/gzip' --data-binary @release/linux.tar.gz ${UPLOAD_URL}?name=linux.tar.gz)
if [ $? != 0 ]; then
echo "could not upload linux binaries (maybe the attachment already exists)"
exit 1
fi
echo uploading darwin binaries using $UPLOAD_URL
RESPONSE=$(curl -s $AUTHENTICATION -H 'Accept: application/vnd.github.v3+json' -H 'Content-Type: application/gzip' --data-binary @release/darwin.tar.gz ${UPLOAD_URL}?name=darwin.tar.gz)
if [ $? != 0 ]; then
echo "could not upload darwin binaries (maybe the attachment already exists)"
exit 1
fi