CI: create the Gitea release object if missing on tag (was failing to publish)
Build & Release APK / build (push) Successful in 12m49s
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:
@@ -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)"
|
||||
|
||||
Reference in New Issue
Block a user