diff options
| author | Lena <lena@omega> | 2026-07-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-07-01 00:00:00 +0000 |
| commit | fb3199b4a993be16804129111c0bb35cc39a70f3 (patch) | |
| tree | 3ebdb85e97dba7a11d6fcee7a6b1d5a0591e30b7 /ci | |
| parent | 80a4a209d63e55ff09c7f31b59358bfe56b055b4 (diff) | |
| download | rsend-fb3199b4a993be16804129111c0bb35cc39a70f3.tar.gz | |
ci: make release.sh idempotent
Re-running on the same tag died creating a release that already
existed. Reuse the tag's release when present, replace a stale asset
before uploading, and parse API responses with python3 instead of sed.
Diffstat (limited to 'ci')
| -rwxr-xr-x | ci/release.sh | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/ci/release.sh b/ci/release.sh index cec2b42..260efba 100755 --- a/ci/release.sh +++ b/ci/release.sh @@ -19,18 +19,33 @@ apk=app/build/outputs/apk/release/app-release.apk [ -f "$apk" ] || { echo "release: $apk not found; run ci/build.sh first" >&2; exit 1; } api="$base/api/v1/repos/$CODEBERG_REPO" +auth="Authorization: token $CODEBERG_TOKEN" +name="rsend-$tag.apk" -# Create the release for the tag and capture its id. -id=$(curl -fsS -X POST "$api/releases" \ - -H "Authorization: token $CODEBERG_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"tag_name\":\"$tag\",\"name\":\"$tag\"}" \ - | sed -n 's/.*"id":\([0-9][0-9]*\).*/\1/p' | head -1) +# Reuse the tag's release if it exists, else create it. Re-runs are idempotent: +# same release, and a stale asset from an earlier run is replaced below. +id=$(curl -fsS -H "$auth" "$api/releases/tags/$tag" 2>/dev/null \ + | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])' 2>/dev/null) || id= +if [ -n "$id" ]; then + curl -fsS -H "$auth" "$api/releases/$id/assets" \ + | python3 -c 'import json,sys +for a in json.load(sys.stdin): + if a["name"] == sys.argv[1]: + print(a["id"])' "$name" \ + | while read -r aid; do + curl -fsS -X DELETE -H "$auth" "$api/releases/$id/assets/$aid" + done +else + id=$(curl -fsS -X POST "$api/releases" \ + -H "$auth" -H "Content-Type: application/json" \ + -d "{\"tag_name\":\"$tag\",\"name\":\"$tag\"}" \ + | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])') +fi [ -n "$id" ] || { echo "release: could not create release for $tag" >&2; exit 1; } # Upload the APK as a release asset. -curl -fsS -X POST "$api/releases/$id/assets?name=rsend-$tag.apk" \ - -H "Authorization: token $CODEBERG_TOKEN" \ +curl -fsS -X POST "$api/releases/$id/assets?name=$name" \ + -H "$auth" \ -F "attachment=@$apk" >/dev/null -echo "release: uploaded rsend-$tag.apk to $CODEBERG_REPO ($tag)" +echo "release: uploaded $name to $CODEBERG_REPO ($tag)" |