-
Notifications
You must be signed in to change notification settings - Fork 3
/
release-latest.sh
executable file
·35 lines (30 loc) · 1.3 KB
/
release-latest.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
#!/bin/bash
set -x
CURL_RETRIES="--connect-timeout 60 --retry 5 --retry-delay 5"
# Delete assets
asset_id=($(curl -u $GITHUB_ACTOR:$GH_TOKEN $CURL_RETRIES \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/latest \
| jq -r '.assets[] | select(.name | contains("'"$1"'")) | .id' | tr -d '\r'))
for id in "${asset_id[@]}"; do
curl -u $GITHUB_ACTOR:$GH_TOKEN $CURL_RETRIES \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/assets/$id;
done
# Release assets
curl -u $GITHUB_ACTOR:$GH_TOKEN $CURL_RETRIES \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases \
-d '{"tag_name": "latest"}'
release_id=$(curl -u $GITHUB_ACTOR:$GH_TOKEN $CURL_RETRIES \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/latest | jq -r '.id')
for f in $2/*.xz; do
curl -u $GITHUB_ACTOR:$GH_TOKEN $CURL_RETRIES \
-X POST -H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: $(file -b --mime-type $f)" \
https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$release_id/assets?name=$(basename $f) \
--data-binary @$f;
done