Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,28 @@ jobs:
npm ci
npm run build

# Untrusted job: it executes PR-supplied lockfile code (npm ci install
# scripts, npm exec, node) with only a read token. It never sees the write
# token, and because the token-holding job below runs on a fresh runner,
# GITHUB_PATH/GITHUB_ENV tampering here cannot capture it either.
release-notes:
if: github.event_name == 'pull_request' && !startsWith(github.head_ref, 'changeset-release/')
permissions:
# contents: write pushes the automatic changeset created below.
contents: write
contents: read
outputs:
# Boolean flag only. A hijacked dependency could forge "true", but the
# worst case is the commit job below PUTting attacker-controlled bytes
# to the attacker's own PR branch — which the PR author can already do.
created: ${{ steps.changeset.outputs.created }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
# Keep the token out of .git/config, where PR-controlled install
# scripts could read it and push. The repository is public, so the
# git fetch below needs no credentials.
persist-credentials: false

- name: Use Node.js
Expand All @@ -99,12 +110,12 @@ jobs:
run: npm ci

- name: Check release notes
id: changeset
env:
BASE_REF: ${{ github.base_ref }}
HEAD_REF: ${{ github.head_ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
GH_TOKEN: ${{ github.token }}
run: |
git fetch --no-tags origin "${BASE_REF}:refs/remotes/origin/${BASE_REF}"
# Dependabot subjects only; --no-merges skips GitHub's pull/N/merge test commits.
Expand Down Expand Up @@ -143,10 +154,49 @@ jobs:
git add "${changeset_path}"
npm exec -- changeset status --since="origin/${BASE_REF}"

echo "created=true" >> "${GITHUB_OUTPUT}"

- name: Upload changeset
if: steps.changeset.outputs.created == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: changeset
path: .changeset/dependabot-${{ github.event.pull_request.number }}.md
if-no-files-found: error
retention-days: 1

# Trusted job: fresh runner, so PATH/ENV state from the untrusted job is
# gone. It holds the job's write token and runs no PR-supplied code —
# only GitHub-hosted actions, gh, and shell. The commit path is derived
# from PR context, not from the untrusted job's outputs.
release-notes-commit:
if: >-
github.event_name == 'pull_request' &&
!startsWith(github.head_ref, 'changeset-release/') &&
needs.release-notes.outputs.created == 'true'
needs: release-notes
permissions:
# contents: write pushes the automatic changeset created above.
contents: write
runs-on: ubuntu-latest
steps:
- name: Download changeset
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: changeset
path: changeset

- name: Commit changeset
env:
HEAD_REF: ${{ github.head_ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GH_TOKEN: ${{ github.token }}
run: |
changeset_path=".changeset/dependabot-${PR_NUMBER}.md"
encoded_path="${changeset_path//\//%2F}"
put_args=(
-f message="chore: add patch changeset for Dependabot PR #${PR_NUMBER}"
-f content="$(base64 -w0 "${changeset_path}")"
-f content="$(base64 -w0 changeset/*.md)"
-f branch="${HEAD_REF}"
)
# The file already exists when a run is re-executed.
Expand All @@ -155,7 +205,6 @@ jobs:
fi
gh api -X PUT "repos/${GITHUB_REPOSITORY}/contents/${encoded_path}" "${put_args[@]}"
echo "Created ${changeset_path} on ${HEAD_REF}"

deploy-demo:
name: deploy demo
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
Expand Down