Skip to content

Commit 5b081f7

Browse files
committed
fix(ci): fix slack release announcement json payload
- JSON-escape release notes (backslashes, quotes, newlines) via sed pipeline before storing in $GITHUB_ENV as SLACK_RELEASE_NOTES - Add 2700-char truncation with link to full release notes - Wrap payload block in {} to form a valid JSON object - Reference pre-escaped env var as a quoted JSON string value
1 parent 668526c commit 5b081f7

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

.github/workflows/_package-publish.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,30 +237,36 @@ jobs:
237237
release: ${{ github.ref_name }}
238238

239239
- name: Convert release notes from Markdown to Slack mrkdwn
240-
id: slack-notes
241240
shell: bash
242241
env:
243242
GIT_CLIFF_CONTENT: ${{ steps.git-cliff.outputs.content }}
244243
run: |
245244
# Convert Markdown links [text](url) to Slack mrkdwn <url|text>
246245
# Convert bold **text** to *text*
247-
SLACK_RELEASE_NOTES=$(printf '%s\n' "$GIT_CLIFF_CONTENT" | \
246+
NOTES_CONVERTED=$(printf '%s\n' "$GIT_CLIFF_CONTENT" | \
248247
sed -E 's/\[([^]]+)\]\(([^)]+)\)/<\2|\1>/g' | \
249248
sed -E 's/\*\*([^*]+)\*\*/*\1*/g')
250-
echo "content<<SLACKEOF" >> "$GITHUB_OUTPUT"
251-
echo "$SLACK_RELEASE_NOTES" >> "$GITHUB_OUTPUT"
252-
echo "SLACKEOF" >> "$GITHUB_OUTPUT"
249+
RELEASE_URL="${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.ref_name }}"
250+
if [ "$(printf '%s' "$NOTES_CONVERTED" | wc -c)" -gt 2700 ]; then
251+
NOTES_TRUNCATED=$(printf '%s' "$NOTES_CONVERTED" | head -c 2700)
252+
NOTES_CONVERTED="${NOTES_TRUNCATED}"$'\n'"...<${RELEASE_URL}|Read full release notes>"
253+
fi
254+
# JSON-escape: backslashes first, then double quotes, then collapse newlines to \n
255+
NOTES=$(printf '%s' "$NOTES_CONVERTED" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
256+
echo "SLACK_RELEASE_NOTES=$NOTES" >> "$GITHUB_ENV"
253257
254258
- name: Release Announcement
255259
uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
256260
with:
257261
webhook: ${{ secrets.SLACK_WEBHOOK_URL_RELEASE_ANNOUNCEMENT }}
258262
webhook-type: webhook-trigger
259263
payload: |
260-
"repository": "${{ github.repository }}",
261-
"version": "${{ steps.git-cliff.outputs.version }}",
262-
"release_notes": ${{ steps.slack-notes.outputs.content }},
263-
"channel_id": "${{ secrets.SLACK_CHANNEL_ID_RELEASE_ANNOUNCEMENT }}"
264+
{
265+
"repository": "${{ github.repository }}",
266+
"version": "${{ steps.git-cliff.outputs.version }}",
267+
"release_notes": "${{ env.SLACK_RELEASE_NOTES }}",
268+
"channel_id": "${{ secrets.SLACK_CHANNEL_ID_RELEASE_ANNOUNCEMENT }}"
269+
}
264270
265271
- name: Allow other workflows to trigger on release
266272
env:

0 commit comments

Comments
 (0)