forked from multiarch/qemu-user-static
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
executable file
·52 lines (46 loc) · 1.53 KB
/
publish.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
#!/bin/bash -e
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
while getopts "v:t:r:" opt; do
case "$opt" in
v) VERSION=$OPTARG
;;
t) GITHUB_TOKEN=$OPTARG
;;
r) REPO=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
# create a release
release_id=$(curl -sL -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Cache-Control: no-cache" -d "{
\"tag_name\": \"v${VERSION}\",
\"target_commitish\": \"master\",
\"name\": \"v${VERSION}\",
\"body\": \"# \`qemu-*-static\` @ ${VERSION}\",
\"draft\": false,
\"prerelease\": false
}" "https://api.github.com/repos/${REPO}/releases" | jq -r ".id")
if [ "$release_id" = "null" ]; then
# get the existing release id
release_id=$(set -x; curl -sL \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Cache-Control: no-cache" \
"https://api.github.com/repos/${REPO}/releases" | jq -r --arg version "${VERSION}" '.[] | select(.name == "v"+$version).id')
fi
cd releases/
for file in *; do
content_type=$(file --mime-type -b ${file})
curl -sL \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: ${content_type}" \
--upload-file ${file} \
"https://uploads.github.com/repos/${REPO}/releases/${release_id}/assets?name=${file}"
done