Skip to content

Commit

Permalink
ci: handle multiline commit messages in release workflow
Browse files Browse the repository at this point in the history
Use base64 encoding/decoding to safely pass commit messages through environment variables in the latest-prerelease workflow.
egegungordu committed Jan 31, 2025
1 parent db33876 commit 813ed22
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/latest-prerelease.yml
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ jobs:
id: commit_info
run: |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_ENV
echo "message=$(git log -1 --pretty=%B)" >> $GITHUB_ENV
echo "message=$(git log -1 --pretty=%B | base64 -w 0)" >> $GITHUB_ENV
# Check if "latest" prerelease exists
- name: Check for Existing Latest Prerelease
@@ -61,15 +61,16 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
decoded_message=$(echo "$message" | base64 -d)
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d "$(jq -n --arg sha "$sha" --arg message "$message" '{
-d "$(jq -n --arg sha "$sha" --arg message "$decoded_message" '{
tag_name: "latest",
target_commitish: $sha,
name: "Latest Prerelease",
body: "Automatically updated to latest commit:\n\n\($message)",
body: "Automatically updated to latest commit:\n\n" + $message,
draft: false,
prerelease: true
}')"
@@ -80,11 +81,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
decoded_message=$(echo "$message" | base64 -d)
curl -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/releases/${{ env.release_id }} \
-d "$(jq -n --arg sha "$sha" --arg message "$message" '{
-d "$(jq -n --arg sha "$sha" --arg message "$decoded_message" '{
tag_name: "latest",
target_commitish: $sha,
name: "Latest Prerelease",

0 comments on commit 813ed22

Please sign in to comment.