Skip to content

Commit b5ff2c7

Browse files
chore: [SDK-4534] harden release workflow input handling
Route step outputs through env: instead of inline interpolation in run: and actions/github-script script: bodies, and add a least-privilege top-level permissions: block. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent fa233ba commit b5ff2c7

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

.github/workflows/create-release-pr.yml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Create Release PR
33
on:
44
workflow_dispatch:
55

6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
610
jobs:
711
bump-version:
812
runs-on: ubuntu-latest
@@ -30,16 +34,20 @@ jobs:
3034
3135
- name: Get last release commit
3236
id: last_commit
37+
env:
38+
CURRENT_VERSION: ${{ steps.current_version.outputs.current }}
3339
run: |
34-
LAST_RELEASE_DATE=$(git show -s --format=%cI "${{ steps.current_version.outputs.current }}")
40+
LAST_RELEASE_DATE=$(git show -s --format=%cI "$CURRENT_VERSION")
3541
echo "date=$LAST_RELEASE_DATE" >> $GITHUB_OUTPUT
3642
3743
- name: Get merged PRs since last release
3844
id: get_prs
3945
uses: actions/github-script@v8
46+
env:
47+
LAST_RELEASE_DATE: ${{ steps.last_commit.outputs.date }}
4048
with:
4149
script: |
42-
const lastReleaseDate = '${{ steps.last_commit.outputs.date }}';
50+
const lastReleaseDate = process.env.LAST_RELEASE_DATE;
4351
4452
// Get merged PRs
4553
const { data: prs } = await github.rest.pulls.list({
@@ -64,11 +72,10 @@ jobs:
6472
6573
- name: Calculate new version
6674
id: new_version
75+
env:
76+
CURRENT: ${{ steps.current_version.outputs.current }}
77+
IS_FEATURE: ${{ steps.get_prs.outputs.isFeature }}
6778
run: |
68-
CURRENT="${{ steps.current_version.outputs.current }}"
69-
PRS='${{ steps.get_prs.outputs.prs }}'
70-
IS_FEATURE='${{ steps.get_prs.outputs.isFeature }}'
71-
7279
MAJOR=${CURRENT:0:2}
7380
MINOR=${CURRENT:2:2}
7481
PATCH=${CURRENT:4:2}
@@ -84,13 +91,16 @@ jobs:
8491
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
8592
8693
- name: Create release branch on main
94+
env:
95+
NEW_VERSION: ${{ steps.new_version.outputs.version }}
8796
run: |
88-
git checkout -b rel/${{ steps.new_version.outputs.version }}
89-
git push -u origin rel/${{ steps.new_version.outputs.version }}
97+
git checkout -b "rel/$NEW_VERSION"
98+
git push -u origin "rel/$NEW_VERSION"
9099
91100
- name: Update package.json sdk version
101+
env:
102+
NEW_VERSION: ${{ steps.new_version.outputs.version }}
92103
run: |
93-
NEW_VERSION="${{ steps.new_version.outputs.version }}"
94104
npm pkg set config.sdkVersion="$NEW_VERSION"
95105
git config user.name "github-actions[bot]"
96106
git config user.email "github-actions[bot]@users.noreply.github.com"
@@ -101,10 +111,12 @@ jobs:
101111
- name: Generate release notes
102112
id: release_notes
103113
uses: actions/github-script@v8
114+
env:
115+
PRS_JSON: ${{ steps.get_prs.outputs.prs }}
104116
with:
105117
script: |
106118
// Trim whitespace from PR titles
107-
const prs = JSON.parse('${{ steps.get_prs.outputs.prs }}').map(pr => ({
119+
const prs = JSON.parse(process.env.PRS_JSON).map(pr => ({
108120
...pr,
109121
title: pr.title.trim()
110122
}));
@@ -132,10 +144,11 @@ jobs:
132144
core.setOutput('notes', releaseNotes);
133145
134146
- name: Create release PR
147+
env:
148+
NEW_VERSION: ${{ steps.new_version.outputs.version }}
135149
run: |
136-
NEW_VERSION="${{ steps.new_version.outputs.version }}"
137-
138-
# Write release notes to file to avoid shell interpretation
150+
# Quoted heredoc ('EOF') disables shell expansion, so the interpolated
151+
# release notes cannot be re-parsed as shell. Keep the quotes.
139152
cat > release_notes.md << 'EOF'
140153
Channels: Current, Stable
141154

0 commit comments

Comments
 (0)