Skip to content

Commit 449ca55

Browse files
committed
feat(workflow): auto-fetch GitHub release description when manual trigger without description (#179)
- Add logic to automatically fetch release description from GitHub API when manual workflow trigger doesn't provide release_body - Fallback to informative default message if release not found or has no description - Maintain existing behavior when release_body is explicitly provided - Improve user experience by eliminating need to manually copy descriptions
1 parent 6165b3d commit 449ca55

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

.github/workflows/sync-release-to-gitcode.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Sync Release to GitCode
22

33
on:
44
release:
5-
types: [published, edited]
5+
types: [published, prereleased, edited]
66
workflow_dispatch:
77
inputs:
88
tag_name:
@@ -61,9 +61,37 @@ jobs:
6161
echo "🔧 Manual trigger detected, using workflow inputs"
6262
echo "tag_name=${{ github.event.inputs.tag_name }}" >> $GITHUB_OUTPUT
6363
echo "release_name=${{ github.event.inputs.release_name || github.event.inputs.tag_name }}" >> $GITHUB_OUTPUT
64-
echo "release_body<<EOF" >> $GITHUB_OUTPUT
65-
echo "${{ github.event.inputs.release_body || 'Test release created via manual trigger' }}" >> $GITHUB_OUTPUT
66-
echo "EOF" >> $GITHUB_OUTPUT
64+
65+
# Handle release body - fetch from GitHub if not provided
66+
if [ -z "${{ github.event.inputs.release_body }}" ]; then
67+
echo "📄 No release description provided, fetching from GitHub API..."
68+
69+
release_response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
70+
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.event.inputs.tag_name }}")
71+
72+
if [ "$(echo "$release_response" | jq -r '.message // empty')" = "Not Found" ]; then
73+
echo "⚠️ Release not found for tag: ${{ github.event.inputs.tag_name }}, using default description"
74+
github_release_body="Release created via manual trigger for tag ${{ github.event.inputs.tag_name }}"
75+
else
76+
github_release_body=$(echo "$release_response" | jq -r '.body // empty')
77+
if [ -z "$github_release_body" ] || [ "$github_release_body" = "null" ]; then
78+
echo "⚠️ No description found in GitHub release, using default description"
79+
github_release_body="Release created via manual trigger for tag ${{ github.event.inputs.tag_name }}"
80+
else
81+
echo "✅ Successfully fetched release description from GitHub"
82+
fi
83+
fi
84+
85+
echo "release_body<<EOF" >> $GITHUB_OUTPUT
86+
echo "$github_release_body" >> $GITHUB_OUTPUT
87+
echo "EOF" >> $GITHUB_OUTPUT
88+
else
89+
echo "📝 Using provided release description"
90+
echo "release_body<<EOF" >> $GITHUB_OUTPUT
91+
echo "${{ github.event.inputs.release_body }}" >> $GITHUB_OUTPUT
92+
echo "EOF" >> $GITHUB_OUTPUT
93+
fi
94+
6795
echo "prerelease=${{ github.event.inputs.prerelease }}" >> $GITHUB_OUTPUT
6896
echo "draft=${{ github.event.inputs.draft }}" >> $GITHUB_OUTPUT
6997
echo "test_mode=${{ github.event.inputs.test_mode }}" >> $GITHUB_OUTPUT
@@ -368,13 +396,13 @@ jobs:
368396
echo "✅ Test mode: Would upload all assets successfully to GitCode"
369397
else
370398
echo "📦 Uploading assets to GitCode release using JavaScript uploader..."
371-
399+
372400
# Make upload script executable
373401
chmod +x ./scripts/upload-assets.js
374-
402+
375403
# Convert comma-separated asset files to array for JavaScript uploader
376404
IFS=',' read -ra ASSET_FILES <<< "${{ steps.download-assets.outputs.asset_files }}"
377-
405+
378406
# Upload assets using the JavaScript uploader
379407
node ./scripts/upload-assets.js \
380408
--token "${{ secrets.GITCODE_ACCESS_TOKEN }}" \
@@ -384,7 +412,7 @@ jobs:
384412
--concurrency 3 \
385413
--retry 3 \
386414
"${ASSET_FILES[@]}"
387-
415+
388416
upload_exit_code=$?
389417
if [ $upload_exit_code -eq 0 ]; then
390418
echo "✅ All assets uploaded successfully to GitCode"

0 commit comments

Comments
 (0)