name: Changeset check # # Warns (never fails) when a pull request changes publishable source in # 1st-gen or gen2 without adding a changeset to that generation's # `.changeset` directory. # on: pull_request: branches: - main types: - opened - synchronize - reopened - ready_for_review - auto_merge_enabled permissions: contents: read pull-requests: write concurrency: group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' cancel-in-progress: true defaults: run: shell: bash jobs: changeset_check: name: Check for changesets if: ${{ !startsWith(github.head_ref, 'changeset-release/') }} runs-on: ubuntu-26.04 steps: - name: Checkout uses: actions/checkout@v7 with: fetch-depth: 0 - name: Check for changesets id: changesets env: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | # --no-renames reports a move as a delete plus an add, so moving source into an ignored path is still caught. changed=$(git diff --name-only --no-renames --diff-filter=AMD "$BASE_SHA...$HEAD_SHA") # Only newly added files count as a changeset; edits or deletions of existing ones don't. added=$(git diff --name-only --no-renames --diff-filter=A "$BASE_SHA...$HEAD_SHA") # Source changes that ship to consumers; tests, stories, and docs don't need a changeset. ignore_pattern='(/test/|/tests/|/stories/|/\.storybook/|/public/|\.(test|stories|vrt)\.[jt]sx?$|\.mdx?$)' config_pattern='/(\.gitignore|(vitest|playwright|chromatic)\.config\.([cm]?[jt]s|json))$' private_pattern='^gen2/packages/tools/' missing='' for gen in 1st-gen gen2; do source_changes=$(echo "$changed" | grep -E "^${gen}/(packages|tools)/" | grep -Ev "$ignore_pattern|$config_pattern|$private_pattern" || true) if [ -z "$source_changes" ]; then continue fi changesets=$(echo "$added" | grep -E "^${gen}/\.changeset/.+\.md$" | grep -v "/README\.md$" || true) if [ -n "$changesets" ]; then echo "✅ $gen: changeset found." continue fi missing="${missing:+$missing }$gen" echo "::warning title=Missing changeset ($gen)::This PR changes $gen source but doesn't add a changeset in $gen/.changeset/. Run 'yarn changeset:$gen' if the change needs to be published." { echo "### ⚠️ Missing changeset for \`$gen\`" echo "This PR changes \`$gen\` source but doesn't add a changeset to \`$gen/.changeset/\`." echo "If the change needs to be published, add one. Otherwise, you can ignore this warning." echo } >> "$GITHUB_STEP_SUMMARY" done if [ -z "$missing" ]; then echo "No missing changesets." fi echo "missing=$missing" >> "$GITHUB_OUTPUT" - name: Manage changeset comment id: comment if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} continue-on-error: true uses: actions/github-script@v9 env: MISSING: ${{ steps.changesets.outputs.missing }} with: script: | const marker = ''; const { owner, repo } = context.repo; const issue_number = context.issue.number; const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number, per_page: 100, }); const comment = comments.find( (item) => item.user.login === 'github-actions[bot]' && item.body.includes(marker) ); const missing = process.env.MISSING.split(' ').filter(Boolean); if (missing.length === 0) { if (comment) { await github.rest.issues.deleteComment({ owner, repo, comment_id: comment.id }); } return; } const entries = missing.map( (gen) => `- \`${gen}\`: run \`yarn changeset:${gen}\` if this change needs to be published.` ).join('\n'); const body = `${marker} ### Missing changeset This PR changes source without adding a changeset for: ${entries} This is a warning based on changed file paths, not a requirement to add a changeset for every change.`; if (comment) { if (comment.body !== body) { await github.rest.issues.updateComment({ owner, repo, comment_id: comment.id, body }); } } else { await github.rest.issues.createComment({ owner, repo, issue_number, body }); } - name: Warn if comment management fails if: ${{ steps.comment.outcome == 'failure' }} run: | echo "::warning title=Changeset comment unavailable::Could not update the PR comment. See the comment management step for details." echo "⚠️ Could not update the changeset PR comment. See the comment management step for details." >> "$GITHUB_STEP_SUMMARY"