name: Changesets # Validate that any PR touching publishable sources (test files aside) includes a changeset entry. # Publishing is automated in release.yml (see docs/release.md). # # Runs on every PR (no workflow-level `paths:` filter) so the `status` check # always reports and can be a required status check in the `main` ruleset. # A path-filtered workflow never reports on docs- or CI-only PRs, which leaves # a required check pending forever. The path filter lives in the first step. on: pull_request: permissions: contents: read jobs: status: runs-on: ubuntu-latest env: BASE_REF: ${{ github.base_ref }} # The Version PR that release.yml opens. Only a branch pushed to this repo counts, # not a fork's. IS_VERSION_PR: ${{ github.head_ref == 'changeset-release/main' && github.event.pull_request.head.repo.full_name == github.repository }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false # The filter that decides which changed paths are publishable (scripts/publishable-paths.sh) # skips test files, which no build ships. This self-test fails the check if it breaks. - name: Self-test the publishable-paths filter run: bash scripts/publishable-paths.test.sh # The guard below runs `pnpm -r ls`, which needs pnpm and Node but no install. No # `cache: pnpm` here: with nothing installed, setup-node's post step fails on the # missing store, so the cached setup runs only before `pnpm install`. - uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 22 # Approving the Version PR is the release approval (ADR 0040), so no other PR may add a # public `name@version` that npm doesn't have: release.yml's `approved` job would refuse # to publish it, and hold up the next release until it's published by hand or reverted. # The script reads the public packages the way release.yml's publish list does # (scripts/release-packages.mjs). - name: Check that only the Version PR adds unpublished versions if: env.IS_VERSION_PR != 'true' run: node scripts/check-unpublished-versions.mjs --since "origin/${BASE_REF}" # The Version PR that release.yml opens applies the pending changesets, so it # changes every bumped package.json but adds no changeset, and # `changeset status --since` fails on it by design. Skip the check there (the job # still reports success). Only a branch pushed to this repo counts, not a fork's. # # A package.json change counts only outside `devDependencies`, which hosts never # install. A dev-only bump, like a Dependabot major of a build or test tool, needs no # changeset; a change to a range hosts install still does (docs/adrs/0015). # A change confined to test files needs none either. - name: Detect changes to publishable sources id: changes run: | if [ "${IS_VERSION_PR}" = "true" ]; then echo "publishable=false" >> "$GITHUB_OUTPUT" echo "Version PR: its changesets are already applied; no new changeset required." exit 0 fi base="$(git merge-base "origin/${BASE_REF}" HEAD)" # Succeeds when the manifest at $1 differs from the base outside `devDependencies`. # An added or deleted manifest, or one jq can't parse, counts as changed. manifest_changed() { local before after before="$(git show "${base}:$1" 2>/dev/null | jq 'del(.devDependencies)')" || return 0 after="$(git show "HEAD:$1" 2>/dev/null | jq 'del(.devDependencies)')" || return 0 [ "${before}" != "${after}" ] } publishable=false changed="$(git diff --name-only "${base}" HEAD | bash scripts/publishable-paths.sh)" while IFS= read -r path; do [ -n "${path}" ] || continue case "${path}" in */package.json) if manifest_changed "${path}"; then publishable=true; fi ;; *) publishable=true ;; esac done <<< "${changed}" if [ "${publishable}" = "true" ]; then echo "publishable=true" >> "$GITHUB_OUTPUT" else echo "publishable=false" >> "$GITHUB_OUTPUT" echo "No publishable sources changed (devDependencies don't count); no changeset required." fi - if: steps.changes.outputs.publishable == 'true' uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 22 cache: pnpm - if: steps.changes.outputs.publishable == 'true' run: pnpm install --frozen-lockfile - name: Verify a changeset is present for this PR if: steps.changes.outputs.publishable == 'true' run: pnpm changeset status --since="origin/${BASE_REF}"