fix: CI 用 node 替代 jq 解析 JSON
Build and Release auth-rt / release (push) Failing after 51s Details

node:20-bookworm 没有 jq,改用 node -e 解析 API 响应。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ywkj 2026-03-20 21:21:42 +08:00
parent 9fd284e556
commit 48a03f3376
1 changed files with 9 additions and 5 deletions

View File

@ -34,12 +34,14 @@ jobs:
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }} FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
API_URL: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} API_URL: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
run: | run: |
json_get() { node -e "process.stdout.write(String(JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).$1 || ''))"; }
# Create release # Create release
RELEASE_ID=$(curl -s -X POST "$API_URL/releases" \ RELEASE_ID=$(curl -s -X POST "$API_URL/releases" \
-H "Authorization: token $FORGEJO_TOKEN" \ -H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"auth-rt $TAG\"}" \ -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"auth-rt $TAG\"}" \
| jq -r '.id') | json_get id)
echo "Created release ID: $RELEASE_ID" echo "Created release ID: $RELEASE_ID"
@ -55,12 +57,14 @@ jobs:
# Maintain "latest" release # Maintain "latest" release
LATEST_ID=$(curl -s "$API_URL/releases/tags/latest" \ LATEST_ID=$(curl -s "$API_URL/releases/tags/latest" \
-H "Authorization: token $FORGEJO_TOKEN" | jq -r '.id // empty') -H "Authorization: token $FORGEJO_TOKEN" | json_get id)
if [ -n "$LATEST_ID" ]; then if [ -n "$LATEST_ID" ]; then
# Delete old assets # Delete old assets
curl -s "$API_URL/releases/$LATEST_ID/assets" \ ASSET_IDS=$(curl -s "$API_URL/releases/$LATEST_ID/assets" \
-H "Authorization: token $FORGEJO_TOKEN" | jq -r '.[].id' | while read aid; do -H "Authorization: token $FORGEJO_TOKEN" \
| node -e "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).forEach(a=>console.log(a.id))")
for aid in $ASSET_IDS; do
curl -s -X DELETE "$API_URL/releases/$LATEST_ID/assets/$aid" \ curl -s -X DELETE "$API_URL/releases/$LATEST_ID/assets/$aid" \
-H "Authorization: token $FORGEJO_TOKEN" -H "Authorization: token $FORGEJO_TOKEN"
done done
@ -73,7 +77,7 @@ jobs:
-H "Authorization: token $FORGEJO_TOKEN" \ -H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"tag_name":"latest","name":"latest","body":"auth-rt latest","prerelease":true}' \ -d '{"tag_name":"latest","name":"latest","body":"auth-rt latest","prerelease":true}' \
| jq -r '.id') | json_get id)
fi fi
for f in auth-rt-*; do for f in auth-rt-*; do