CI: create the Gitea release object if missing on tag (was failing to publish)
Build & Release APK / build (push) Successful in 12m49s

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.
This commit is contained in:
2026-06-05 16:05:13 +00:00
parent 4c24f45808
commit abec5276f9
+14 -7
View File
@@ -10,6 +10,8 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: write # needed to create the release object on a tag
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@@ -63,12 +65,17 @@ jobs:
TAG: ${{ github.ref_name }} TAG: ${{ github.ref_name }}
VERSION: ${{ steps.ver.outputs.name }} VERSION: ${{ steps.ver.outputs.name }}
run: | run: |
RELEASE_ID=$(curl -sf \ API="https://gitea.khodak.me/api/v1/repos/amir/SyncFlow"
"https://gitea.khodak.me/api/v1/repos/amir/SyncFlow/releases/tags/$TAG" \ # A pushed git tag does NOT create a Gitea release object — fetch it, create if missing.
-H "Authorization: token $TOKEN" \ RELEASE_ID=$(curl -s "$API/releases/tags/$TAG" -H "Authorization: token $TOKEN" \
| python3 -c "import sys,json; print(json.load(sys.stdin)['id'])") | python3 -c "import sys,json;d=json.load(sys.stdin);print(d.get('id','') if isinstance(d,dict) else '')" 2>/dev/null)
curl -sf -X POST \ if [ -z "$RELEASE_ID" ]; then
"https://gitea.khodak.me/api/v1/repos/amir/SyncFlow/releases/$RELEASE_ID/assets" \ 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" \ -H "Authorization: token $TOKEN" \
-F "attachment=@dist/SyncFlow-v${VERSION}.apk" -F "attachment=@dist/SyncFlow-v${VERSION}.apk"
echo "APK uploaded to release $TAG" echo "APK uploaded to release $TAG (id $RELEASE_ID)"