ci: handle existing release in workflow

This commit is contained in:
SW 2026-09-10 10:29:20 +02:00
parent 6d01888c85
commit fb7a13092d

View file

@ -74,17 +74,26 @@ jobs:
VERSION=${{ github.ref_name }} VERSION=${{ github.ref_name }}
API="${FORGEJO_URL}/api/v1/repos/seth/Caddyview" 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}" \ RELEASE_JSON=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-X POST \ -X POST \
-d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \ -d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \
"${API}/releases") "${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) RELEASE_ID=$(echo "${RELEASE_JSON}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
if [ -z "${RELEASE_ID}" ]; then 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 exit 1
fi fi