forked from logrotate/logrotate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-release.sh
executable file
·75 lines (63 loc) · 1.89 KB
/
upload-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
#!/bin/bash
set -x
SELF="$0"
TAG="$1"
TOKEN="$2"
NAME="logrotate"
NV="${NAME}-${TAG}"
usage() {
printf "Usage: %s TAG TOKEN\n" "$SELF" >&2
exit 1
}
die() {
printf "%s: error: %s\n" "$SELF" "$*" >&2
exit 1
}
# check arguments
test "$TAG" = "$(git describe --tags "$TAG")" || usage
test -n "$TOKEN" || usage
# check that .tar.gz is prepared
TAR_GZ="${NV}.tar.gz"
test -e "$TAR_GZ" || die "$TAR_GZ does not exist"
# check that .tar.xz is prepared
TAR_XZ="${NV}.tar.xz"
test -e "$TAR_XZ" || die "$TAR_XZ does not exist"
# sign the tarballs
for file in "$TAR_GZ" "$TAR_XZ"; do
gpg --armor --detach-sign "$file" || die "tarball signing failed"
test -f "${file}.asc" || die "tarball signature was not created"
done
# file to store response from GitHub API
JSON="./${NV}-github-relase.js"
# create a new release on GitHub
curl "https://api.github.com/repos/${NAME}/${NAME}/releases" \
-o "$JSON" --fail --verbose \
--header "Authorization: token $TOKEN" \
--data '{
"tag_name": "'"$TAG"'",
"target_commitish": "master",
"name": "'"$NV"'",
"draft": false,
"prerelease": false
}' || exit $?
# parse upload URL from the response
UPLOAD_URL="$(grep '^ *"upload_url": "' "$JSON" \
| sed -e 's/^ *"upload_url": "//' -e 's/{.*}.*$//')"
grep '^https://uploads.github.com/.*/assets$' <<< "$UPLOAD_URL" || exit $?
# upload both .tar.gz and .tar.xz
for comp in gzip xz; do
file="${NV}.tar.${comp:0:2}"
curl "${UPLOAD_URL}?name=${file}" \
-T "$file" --fail --verbose \
--header "Authorization: token $TOKEN" \
--header "Content-Type: application/x-${comp}" \
|| exit $?
done
# upload signatures
for file in "${TAR_GZ}.asc" "${TAR_XZ}.asc"; do
curl "${UPLOAD_URL}?name=${file}" \
-T "$file" --fail --verbose \
--header "Authorization: token $TOKEN" \
--header "Content-Type: text/plain" \
|| exit $?
done