diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index 884121d..726689b 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -74,17 +74,26 @@ jobs: VERSION=${{ github.ref_name }} API="${FORGEJO_URL}/api/v1/repos/seth/Caddyview" + # Try to create release; if it already exists, fetch the existing one. RELEASE_JSON=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \ -H "Content-Type: application/json" \ -X POST \ -d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \ "${API}/releases") - echo "Release response: ${RELEASE_JSON}" + echo "Create release response: ${RELEASE_JSON}" RELEASE_ID=$(echo "${RELEASE_JSON}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) if [ -z "${RELEASE_ID}" ]; then - echo "Failed to create release" + echo "Release may already exist, fetching existing release..." + EXISTING=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \ + "${API}/releases/tags/${VERSION}") + echo "Existing release response: ${EXISTING}" + RELEASE_ID=$(echo "${EXISTING}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) + fi + + if [ -z "${RELEASE_ID}" ]; then + echo "Failed to create or fetch release" exit 1 fi