#!/bin/bash # Create (or reuse) a GitHub release and upload the JASP tarball to it. # Uses the REST API directly so the workflow does not depend on `gh` being # present in the runner image. # # GH_TOKEN PAT with `contents: write` on the target repo (required) # GH_OWNER GitHub account owning the release repo (required) # GH_REPO release repo name (default jasp-desktop-bin) # TAG release tag, e.g. v0.98.1-1 (required) # ASSET path to the tarball to upload (required) set -euo pipefail : "${GH_TOKEN:?GH_TOKEN is required}" : "${GH_OWNER:?GH_OWNER is required}" : "${TAG:?TAG is required}" : "${ASSET:?ASSET is required}" GH_REPO="${GH_REPO:-jasp-desktop-bin}" API="https://api.github.com/repos/${GH_OWNER}/${GH_REPO}" UPLOADS="https://uploads.github.com/repos/${GH_OWNER}/${GH_REPO}" AUTH=(-H "Authorization: Bearer ${GH_TOKEN}" -H "Accept: application/vnd.github+json") asset_name="$(basename "$ASSET")" echo ":: looking for existing release $TAG" release_id="$(curl -sSf "${AUTH[@]}" "${API}/releases/tags/${TAG}" 2>/dev/null \ | python3 -c 'import json,sys; print(json.load(sys.stdin).get("id",""))' 2>/dev/null || true)" if [[ -z "$release_id" ]]; then echo ":: creating release $TAG" release_id="$(curl -sSf -X POST "${AUTH[@]}" "${API}/releases" \ -d "$(python3 -c ' import json, os print(json.dumps({ "tag_name": os.environ["TAG"], "name": "JASP " + os.environ["TAG"], "body": os.environ.get("RELEASE_NOTES", ""), "draft": False, "prerelease": False, }))')" | python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')" else echo ":: reusing release $release_id" # Replace a same-named asset so re-runs are idempotent. old="$(curl -sSf "${AUTH[@]}" "${API}/releases/${release_id}/assets" \ | python3 -c " import json, sys name = '${asset_name}' print(next((a['id'] for a in json.load(sys.stdin) if a['name'] == name), '')) ")" if [[ -n "$old" ]]; then echo ":: deleting previous asset $old" curl -sSf -X DELETE "${AUTH[@]}" "${API}/releases/assets/${old}" fi fi echo ":: uploading $asset_name ($(du -h "$ASSET" | cut -f1))" curl -sSf -X POST "${AUTH[@]}" \ -H "Content-Type: application/zstd" \ --data-binary "@${ASSET}" \ "${UPLOADS}/releases/${release_id}/assets?name=${asset_name}" >/dev/null echo ":: uploaded to https://github.com/${GH_OWNER}/${GH_REPO}/releases/tag/${TAG}"