Debian Codegraph @

.ci/update-github-release.sh

raw symbols SCIP
1 #!/bin/sh
2
3 if [ -z "$CI_COMMIT_TAG" ]; then
4 echo "CI_COMMIT_TAG is unset or empty; exiting"
5 exit 1
6 fi
7
8 echo "Checking if release exists for ${CI_COMMIT_TAG}"
9 # check if we already have a release for the current tag or not
10 http_code=$(curl \
11 -s \
12 -o /dev/null \
13 -I \
14 -w "%{http_code}" \
15 -H "Accept: application/vnd.github+json" \
16 -H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\
17 -H "X-GitHub-Api-Version: 2022-11-28" \
18 "https://api.github.com/repos/Nheko-Reborn/nheko/releases/tags/$CI_COMMIT_TAG")
19
20 if [ "$http_code" = "404" ]; then
21 echo "Release does not exist... getting notes from CHANGELOG.md:"
22 release_notes="$(perl -0777 -ne '/.*?(## .*?)\n(## |\Z)/s && print $1' CHANGELOG.md | jq -R -s '.')"
23 echo "$release_notes"
24
25 echo "Creating new release for ${CI_COMMIT_TAG}"
26 # Doing a 'fresh' release, not just updating the assets.
27 release_json="$(curl \
28 -X POST \
29 -H "Accept: application/vnd.github+json" \
30 -H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\
31 -H "X-GitHub-Api-Version: 2022-11-28" \
32 https://api.github.com/repos/Nheko-Reborn/nheko/releases \
33 -d "{\"tag_name\":\"${CI_COMMIT_TAG}\",\"target_commitish\":\"master\",\"name\":\"${CI_COMMIT_TAG}\",\"body\":${release_notes},\"draft\":true,\"prerelease\":true,\"generate_release_notes\":false}")"
34 elif [ "$http_code" = "200" ]; then
35 echo "Release already exists for ${CI_COMMIT_TAG}; Updating"
36 # Updating a release (probably because of cirrus-ci or so)
37 release_json=$(curl \
38 -s \
39 -H "Accept: application/vnd.github+json" \
40 -H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\
41 -H "X-GitHub-Api-Version: 2022-11-28" \
42 "https://api.github.com/repos/Nheko-Reborn/nheko/releases/tags/$CI_COMMIT_TAG")
43 fi
44
45 echo "Getting upload URL..."
46 upload_url="$(echo "$release_json" | jq -r '."upload_url"')"
47 # get rid of the 'hypermedia' stuff at the end and use a 'real' URL
48 echo "Upload URL (hypermedia): ${upload_url}"
49 upload_url="$(echo "$upload_url" | sed 's/{?name,label\}/?name/g')"
50
51 ls -la .
52 echo "Uploading artifacts"
53 for file in ./artifacts/*; do
54 name="${file##*/}"
55 echo "Uploading $file"
56 [ -e "$file" ] && curl \
57 -X POST \
58 -H "Accept: application/vnd.github+json" \
59 -H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\
60 -H "X-GitHub-Api-Version: 2022-11-28" \
61 -H "Content-Type: application/octet-stream" \
62 "${upload_url}=$name" \
63 --data-binary "@$file"
64 done
65
66
67 # TODO: AppVeyor stuffs?