diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 47ee165..8c39057 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -48,35 +48,64 @@ jobs: - name: Build zip package run: make zip + # Gitea has no `gh` CLI; use REST API (same host as checkout). - name: Nightly release (single tag, updated in place) env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SERVER_URL: ${{ github.server_url }} run: | set -euo pipefail TAG=nightly ZIP="./output/OmniNX Downloader.zip" - REPO="${{ github.repository }}" + FULL="${{ github.repository }}" + OWNER="${FULL%%/*}" + REPO_NAME="${FULL#*/}" SHA="${{ github.sha }}" REF="${{ github.ref_name }}" + API="${SERVER_URL%/}/api/v1" git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git tag -f "$TAG" git push origin "refs/tags/$TAG" --force - NOTES="Single nightly build artifact (updated every push). + NOTES="Single nightly build artifact (updated on schedule or manual run). **Commit:** \`${SHA}\` **Branch:** \`${REF}\` **Built:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')" - if gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then - gh release upload "$TAG" "$ZIP" --clobber --repo "$REPO" - gh release edit "$TAG" --title "Nightly" --notes "$NOTES" --prerelease --repo "$REPO" - else - gh release create "$TAG" "$ZIP" \ - --title "Nightly" \ - --notes "$NOTES" \ - --prerelease \ - --repo "$REPO" + AUTH=(-H "Authorization: token ${GITHUB_TOKEN}") + + # Remove existing release so we can recreate with a fresh attachment (Gitea has no clobber). + HTTP_CODE=$(curl -sS -o /tmp/gitea_rel.json -w "%{http_code}" "${AUTH[@]}" \ + "${API}/repos/${OWNER}/${REPO_NAME}/releases/tags/${TAG}") + if [ "$HTTP_CODE" = "200" ]; then + RID=$(python3 -c "import json; print(json.load(open('/tmp/gitea_rel.json'))['id'])") + curl -sS -X DELETE "${AUTH[@]}" \ + "${API}/repos/${OWNER}/${REPO_NAME}/releases/${RID}" fi + + export NOTES TAG + JSON_BODY=$(python3 <<'PY' + import json, os + print(json.dumps({ + "tag_name": os.environ["TAG"], + "name": "Nightly", + "body": os.environ["NOTES"], + "draft": False, + "prerelease": True, + })) + PY + ) + curl -sS -f -X POST "${AUTH[@]}" -H "Content-Type: application/json" \ + -d "$JSON_BODY" \ + "${API}/repos/${OWNER}/${REPO_NAME}/releases" | tee /tmp/gitea_create.json + + RID=$(python3 -c "import json; print(json.load(open('/tmp/gitea_create.json'))['id'])") + export ASSET_NAME="OmniNX Downloader.zip" + QNAME=$(python3 -c "import urllib.parse,os; print(urllib.parse.quote(os.environ['ASSET_NAME']))") + + curl -sS -f -X POST "${AUTH[@]}" \ + -F "attachment=@${ZIP};filename=${ASSET_NAME}" \ + "${API}/repos/${OWNER}/${REPO_NAME}/releases/${RID}/assets?name=${QNAME}"