fix(ci): use jq instead of python3, handle existing releases via PATCH
This commit is contained in:
@@ -69,37 +69,43 @@ jobs:
|
|||||||
|
|
||||||
# Read release notes if present
|
# Read release notes if present
|
||||||
if [ -f RELEASE_NOTES.md ]; then
|
if [ -f RELEASE_NOTES.md ]; then
|
||||||
export RELEASE_NOTES=$(cat RELEASE_NOTES.md)
|
BODY_JSON=$(jq -Rs '.' < RELEASE_NOTES.md)
|
||||||
echo "Found RELEASE_NOTES.md"
|
echo "Found RELEASE_NOTES.md"
|
||||||
else
|
else
|
||||||
export RELEASE_NOTES=""
|
BODY_JSON='""'
|
||||||
echo "No RELEASE_NOTES.md found — release will have no body"
|
echo "No RELEASE_NOTES.md found — release will have no body"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BODY_JSON=$(python3 -c "
|
# Check if release already exists for this tag
|
||||||
import json, os
|
EXISTING=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||||
notes = os.environ.get('RELEASE_NOTES', '')
|
"$BASE_URL/releases/tags/$TAG" \
|
||||||
print(json.dumps(notes.strip()))
|
-H "Authorization: token $DEPLOY_TOKEN")
|
||||||
")
|
|
||||||
|
|
||||||
# Create release via Gitea API
|
if [ "$EXISTING" = "200" ]; then
|
||||||
RELEASE=$(curl -s -X POST "$BASE_URL/releases" \
|
# Update existing release
|
||||||
-H "Authorization: token $DEPLOY_TOKEN" \
|
RELEASE_ID=$(curl -s "$BASE_URL/releases/tags/$TAG" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Authorization: token $DEPLOY_TOKEN" | jq -r '.id')
|
||||||
-d "{
|
curl -s -X PATCH "$BASE_URL/releases/$RELEASE_ID" \
|
||||||
\"tag_name\": \"$TAG\",
|
-H "Authorization: token $DEPLOY_TOKEN" \
|
||||||
\"name\": \"$VERSION\",
|
-H "Content-Type: application/json" \
|
||||||
\"body\": $BODY_JSON,
|
-d "{
|
||||||
\"draft\": false,
|
\"name\": \"$VERSION\",
|
||||||
\"prerelease\": $IS_PRE
|
\"body\": $BODY_JSON,
|
||||||
}")
|
\"draft\": false,
|
||||||
|
\"prerelease\": $IS_PRE
|
||||||
# Fallback: if release already exists for this tag, reuse it
|
}"
|
||||||
RELEASE_ID=$(echo "$RELEASE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])" 2>/dev/null)
|
echo "Updated existing release $RELEASE_ID for $TAG"
|
||||||
if [ -z "$RELEASE_ID" ]; then
|
else
|
||||||
echo "::warning::Release already exists for tag $TAG — reusing existing release"
|
# Create new release
|
||||||
RELEASE=$(curl -s "$BASE_URL/releases/tags/$TAG" \
|
curl -s -X POST "$BASE_URL/releases" \
|
||||||
-H "Authorization: token $DEPLOY_TOKEN")
|
-H "Authorization: token $DEPLOY_TOKEN" \
|
||||||
RELEASE_ID=$(echo "$RELEASE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{
|
||||||
|
\"tag_name\": \"$TAG\",
|
||||||
|
\"name\": \"$VERSION\",
|
||||||
|
\"body\": $BODY_JSON,
|
||||||
|
\"draft\": false,
|
||||||
|
\"prerelease\": $IS_PRE
|
||||||
|
}"
|
||||||
|
echo "Created release for $TAG"
|
||||||
fi
|
fi
|
||||||
echo "Created release $RELEASE_ID for $TAG"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user