From fa1b65484c81ec02e0f8edbf7f2396a90ca766b1 Mon Sep 17 00:00:00 2001 From: bvandeusen Date: Wed, 11 Mar 2026 23:29:24 -0400 Subject: [PATCH] ci: attach APK to existing release when created via Forgejo UI --- .forgejo/workflows/ci.yml | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 0679020..50ead4e 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -89,34 +89,40 @@ jobs: path: build/app/outputs/flutter-apk/app-release.apk retention-days: 30 - - name: Create Forgejo release + - name: Publish Forgejo release if: startsWith(github.ref, 'refs/tags/') env: RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} TAG: ${{ github.ref_name }} + API: https://git.fabledsword.com/api/v1/repos/bvandeusen/FabledApp run: | - echo "Creating release $TAG..." + # Look for an existing release (created via the UI or a prior run). + EXISTING=$(curl -s \ + "$API/releases/tags/$TAG" \ + -H "Authorization: token $RELEASE_TOKEN") - RESPONSE=$(curl -s -X POST \ - "https://git.fabledsword.com/api/v1/repos/bvandeusen/FabledApp/releases" \ - -H "Authorization: token $RELEASE_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"\"}") + RELEASE_ID=$(echo "$EXISTING" | grep -oE '"id":[[:space:]]*[0-9]+' | head -1 | grep -oE '[0-9]+') - RELEASE_ID=$(echo "$RESPONSE" | grep -oE '"id":[[:space:]]*[0-9]+' | head -1 | grep -oE '[0-9]+') - - if [ -z "$RELEASE_ID" ]; then - echo "Failed to create release. API response:" - echo "$RESPONSE" - exit 1 + if [ -n "$RELEASE_ID" ]; then + echo "Found existing release $TAG (id $RELEASE_ID), attaching APK..." + else + echo "No existing release found, creating $TAG..." + RESPONSE=$(curl -s -X POST "$API/releases" \ + -H "Authorization: token $RELEASE_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"\"}") + RELEASE_ID=$(echo "$RESPONSE" | grep -oE '"id":[[:space:]]*[0-9]+' | head -1 | grep -oE '[0-9]+') + if [ -z "$RELEASE_ID" ]; then + echo "Failed to create release. API response:" + echo "$RESPONSE" + exit 1 + fi + echo "Release created with id $RELEASE_ID." fi - echo "Release created with ID $RELEASE_ID, uploading APK..." - - curl -s -X POST \ - "https://git.fabledsword.com/api/v1/repos/bvandeusen/FabledApp/releases/$RELEASE_ID/assets" \ + curl -s -X POST "$API/releases/$RELEASE_ID/assets" \ -H "Authorization: token $RELEASE_TOKEN" \ -F "attachment=@build/app/outputs/flutter-apk/app-release.apk" - echo "Done — release $TAG is live at:" + echo "Done — $TAG is live at:" echo "https://git.fabledsword.com/bvandeusen/FabledApp/releases/tag/$TAG"