From abec5276f9d501a019612d96905cdb3af12a589d Mon Sep 17 00:00:00 2001 From: Friday Date: Fri, 5 Jun 2026 16:05:13 +0000 Subject: [PATCH] CI: create the Gitea release object if missing on tag (was failing to publish) A pushed git tag doesn't create a Gitea release object, so the publish step 404'd trying to attach the APK. Now it creates the release if absent (with contents:write permission), then uploads. v1.0.65 was published manually. --- .gitea/workflows/release.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index c2d3b13..2c46c2c 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -10,6 +10,8 @@ on: jobs: build: runs-on: ubuntu-latest + permissions: + contents: write # needed to create the release object on a tag steps: - uses: actions/checkout@v4 @@ -63,12 +65,17 @@ jobs: TAG: ${{ github.ref_name }} VERSION: ${{ steps.ver.outputs.name }} run: | - RELEASE_ID=$(curl -sf \ - "https://gitea.khodak.me/api/v1/repos/amir/SyncFlow/releases/tags/$TAG" \ - -H "Authorization: token $TOKEN" \ - | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])") - curl -sf -X POST \ - "https://gitea.khodak.me/api/v1/repos/amir/SyncFlow/releases/$RELEASE_ID/assets" \ + API="https://gitea.khodak.me/api/v1/repos/amir/SyncFlow" + # A pushed git tag does NOT create a Gitea release object — fetch it, create if missing. + RELEASE_ID=$(curl -s "$API/releases/tags/$TAG" -H "Authorization: token $TOKEN" \ + | python3 -c "import sys,json;d=json.load(sys.stdin);print(d.get('id','') if isinstance(d,dict) else '')" 2>/dev/null) + if [ -z "$RELEASE_ID" ]; then + RELEASE_ID=$(curl -s -X POST "$API/releases" -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\"}" \ + | python3 -c "import sys,json;print(json.load(sys.stdin).get('id',''))") + echo "created release object $RELEASE_ID for $TAG" + fi + curl -sf -X POST "$API/releases/$RELEASE_ID/assets?name=SyncFlow-v${VERSION}.apk" \ -H "Authorization: token $TOKEN" \ -F "attachment=@dist/SyncFlow-v${VERSION}.apk" - echo "APK uploaded to release $TAG" + echo "APK uploaded to release $TAG (id $RELEASE_ID)"