-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-release.sh
executable file
·115 lines (97 loc) · 4.51 KB
/
github-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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /bin/bash
# Portions of this script from https://github.com/probonopd/uploadtool Copyright 2016 Simon Peter under the MIT License
RELEASE_NAME=appimage_continuous_$BRANCH
[ -n "$REPO_SLUG" ] || ( echo "No repo slug"; exit 1 )
[ -n "$GITHUB_TOKEN" ] || ( echo "No github token"; exit 1 )
echo "Releasing..."
clear_tmp() {
# Info regarding temporary release that already exists.
old_tmp_releaseurl="https://api.github.com/repos/$REPO_SLUG/releases/tags/$RELEASE_NAME.tmp"
echo "Getting the release ID..."
echo "old_tmp_releaseurl: $old_tmp_releaseurl"
old_tmp_releaseinfos=$(curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" "${old_tmp_releaseurl}")
echo "old_tmp_releaseinfos: $old_tmp_releaseinfos"
old_tmp_releaseid=$(echo "$old_tmp_releaseinfos" | jq -r '.id')
# Delete release if required.
if [ x"$old_tmp_releaseid" != "x" ]; then
delete_url="https://api.github.com/repos/$REPO_SLUG/releases/$old_tmp_releaseid"
echo "Deleting the release..."
echo "delete_url: $delete_url"
curl -XDELETE \
--header "Authorization: token ${GITHUB_TOKEN}" \
"${delete_url}"
fi
# Delete tag
echo "Deleting the tag..."
delete_url="https://api.github.com/repos/$REPO_SLUG/git/refs/tags/$RELEASE_NAME.tmp"
echo "delete_url: $delete_url"
curl -XDELETE \
--header "Authorization: token ${GITHUB_TOKEN}" \
"${delete_url}"
}
clear_tmp
# Create the release.
release_infos=$(curl -H "Authorization: token ${GITHUB_TOKEN}" --data '{"tag_name": "'"$RELEASE_NAME.tmp"'","target_commitish": "'"master"'","name": "'"Temp:$BRANCH:$PLATFORM_BUILD"'","body": "'"Temporary release while uploading $BRANCH build $PLATFORM_BUILD."'","draft": false, "prerelease": true}' "https://api.github.com/repos/$REPO_SLUG/releases")
echo "$release_infos"
release_id=$(echo "$release_infos" | jq -r '.id')
# Get the upload url, should use URI Templates here.
upload_url="https://uploads.github.com/repos/$REPO_SLUG/releases/$release_id/assets"
echo "upload_url: $upload_url"
release_url=$(echo "$release_infos" | jq -r '.url')
echo "release_url: $release_url"
pushd out
# Create the zsync files...
echo "Running zsyncmake"
for FILE in *.AppImage; do
if [ -e "$FILE" ]; then
zsyncmake -o "$FILE.zsync" "$FILE"
fi
done
# Upload the AppImages and zsync files...
echo "Uploading files"
for FILE in *; do
if [ -e "$FILE" ]; then
FULLNAME="${FILE}"
BASENAME="$(basename "${FILE}")"
echo "Uploading: $BASENAME"
curl -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.manifold-preview" \
-H "Content-Type: application/octet-stream" \
--data-binary @$FULLNAME \
"$upload_url?name=$BASENAME" | tee /dev/null
fi
done
# Upload commit file last.
curl -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.manifold-preview" \
-H "Content-Type: application/octet-stream" \
--data "$COMMIT" \
"$upload_url?name=_commit.txt" | tee /dev/null
popd
# Info regarding release that already exists.
old_release_url="https://api.github.com/repos/$REPO_SLUG/releases/tags/$RELEASE_NAME"
echo "Getting the release ID..."
echo "old_release_url: $old_release_url"
old_release_infos=$(curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" "${old_release_url}")
echo "old_release_infos: $old_release_infos"
old_release_id=$(echo "$old_release_infos" | jq -r '.id')
# Delete release if required.
if [ x"$old_release_id" != "x" ]; then
delete_url="https://api.github.com/repos/$REPO_SLUG/releases/$old_release_id"
echo "Deleting the release..."
echo "delete_url: $delete_url"
curl -XDELETE \
--header "Authorization: token ${GITHUB_TOKEN}" \
"${delete_url}"
fi
# Delete tag
echo "Deleting the tag..."
delete_url="https://api.github.com/repos/$REPO_SLUG/git/refs/tags/$RELEASE_NAME"
echo "delete_url: $delete_url"
curl -XDELETE \
--header "Authorization: token ${GITHUB_TOKEN}" \
"${delete_url}"
# Finish the release.
release_infos=$(curl -H "Authorization: token ${GITHUB_TOKEN}" --data '{"draft": false, "name": "'"Continuous build: $BRANCH"'","body": "'"AppImages built from the \`$BRANCH\` branch.\n\n* [How to use these AppImages](https://redeclipse.net/docs/AppImages)\n* [About the AppImage format and project](https://appimage.org)\n\nThe \`.zsync\` and \`_commit.txt\` files are used automatically for update information."'","tag_name": "'"$RELEASE_NAME"'"}' "$release_url")
echo "$release_infos"
clear_tmp