Skip to content

Commit 5f0233d

Browse files
Copilotlgallard
andauthored
fix: Add GitHub Action step to remove "v" prefix from release titles (#68)
* Initial plan for issue * Add GitHub Action step to remove v prefix from release titles Co-authored-by: lgallard <6194359+lgallard@users.noreply.github.com> * Fix JSON interpolation vulnerability in release title update Co-authored-by: lgallard <6194359+lgallard@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lgallard <6194359+lgallard@users.noreply.github.com>
1 parent 1375263 commit 5f0233d

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

.github/workflows/release-please.yml

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,60 @@ jobs:
1515
id: release_please
1616
with:
1717
token: ${{ secrets.GITHUB_TOKEN }}
18-
config-file: .release-please-config.json
18+
config-file: .release-please-config.json
19+
20+
- name: Remove v prefix from release title
21+
if: ${{ steps.release_please.outputs.release_created }}
22+
run: |
23+
# Get the release ID
24+
RELEASE_ID="${{ steps.release_please.outputs.id }}"
25+
26+
if [ -z "$RELEASE_ID" ]; then
27+
echo "Release ID not found, skipping title update"
28+
exit 0
29+
fi
30+
31+
echo "Processing release ID: $RELEASE_ID"
32+
33+
# Get current release data
34+
RELEASE_DATA=$(curl -s \
35+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
36+
-H "Accept: application/vnd.github.v3+json" \
37+
"https://api.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}")
38+
39+
# Extract current title
40+
CURRENT_TITLE=$(echo "$RELEASE_DATA" | jq -r '.name')
41+
42+
if [ "$CURRENT_TITLE" = "null" ] || [ -z "$CURRENT_TITLE" ]; then
43+
echo "Could not retrieve release title, skipping update"
44+
exit 0
45+
fi
46+
47+
echo "Current release title: '$CURRENT_TITLE'"
48+
49+
# Remove 'v' prefix if present (case sensitive, only at the beginning, and only if followed by a digit)
50+
NEW_TITLE=$(echo "$CURRENT_TITLE" | sed 's/^v\([0-9]\)/\1/')
51+
52+
# Only update if the title actually changed
53+
if [ "$CURRENT_TITLE" != "$NEW_TITLE" ]; then
54+
echo "Updating release title from '$CURRENT_TITLE' to '$NEW_TITLE'"
55+
# Use jq to safely construct JSON payload to prevent injection vulnerabilities
56+
JSON_PAYLOAD=$(jq -n --arg name "$NEW_TITLE" '{name: $name}')
57+
RESPONSE=$(curl -s \
58+
-X PATCH \
59+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
60+
-H "Accept: application/vnd.github.v3+json" \
61+
"https://api.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}" \
62+
-d "$JSON_PAYLOAD")
63+
64+
# Check if update was successful
65+
UPDATED_TITLE=$(echo "$RESPONSE" | jq -r '.name')
66+
if [ "$UPDATED_TITLE" = "$NEW_TITLE" ]; then
67+
echo "Successfully updated release title to '$NEW_TITLE'"
68+
else
69+
echo "Failed to update release title. Response: $RESPONSE"
70+
exit 1
71+
fi
72+
else
73+
echo "Release title '$CURRENT_TITLE' does not need updating"
74+
fi

0 commit comments

Comments
 (0)