-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrelease.sh
executable file
·45 lines (36 loc) · 1.24 KB
/
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
#!/bin/bash
set -o errexit
if [ -z "$ACCOUNT" ] || [ -z "$REPO" ] || [ -z "$ACCESS_TOKEN" ] || [ -z "$TRAVIS_TAG" ]; then
echo "Please set value for ACCOUNT, REPO, ACCESS_TOKEN and TRAVIS_TAG"
exit 1
fi
echo "Attempting to create a new $TRAVIS_TAG release"
json="{
\"tag_name\": \"$TRAVIS_TAG\",
\"name\": \"$TRAVIS_TAG\",
\"body\": \"Release of $TRAVIS_TAG: [changelog](https://github.com/resin-io/edge-node-manager/blob/master/CHANGELOG.md)\n$1\"
}"
resp=$(curl -i --data "$json" --header "Content-Type:application/json" \
"https://api.github.com/repos/$ACCOUNT/$REPO/releases?access_token=$ACCESS_TOKEN" | \
head -n 1 | cut -d$' ' -f2)
if [ $resp = "201" ]; then
echo "Success"
elif [ $resp = "422" ]; then
echo "Release already exists, appending instead"
release=$(curl https://api.github.com/repos/$ACCOUNT/$REPO/releases/tags/$TRAVIS_TAG)
id=$(echo $release | jq .id)
body=$(echo $release | jq .body)
body="${body%\"}"
body="${body#\"}"
json="{
\"body\": \"$body\n$1\"
}"
resp=$(curl --data "$json" --header "Content-Type:application/json" \
-X PATCH "https://api.github.com/repos/$ACCOUNT/$REPO/releases/$id?access_token=$ACCESS_TOKEN" | \
head -n 1 | cut -d$' ' -f2)
if [ $resp = "200" ]; then
exit 0
else
exit 1
fi
fi