name: Require Changeset on: pull_request: types: [opened, synchronize, reopened, labeled, unlabeled] merge_group: branches: [dev] permissions: {} jobs: require-changeset: runs-on: ubuntu-latest if: github.head_ref != 'release' && github.event_name != 'merge_group' permissions: contents: read pull-requests: write steps: - name: Check for internal label id: labels shell: bash env: LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} run: | if echo "$LABELS" | grep -q '"internal"'; then echo "skip=true" >> "$GITHUB_OUTPUT" else echo "skip=false" >> "$GITHUB_OUTPUT" fi - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 if: steps.labels.outputs.skip == 'false' with: fetch-depth: 0 persist-credentials: false - name: Check for changeset added by this PR if: steps.labels.outputs.skip == 'false' id: check shell: bash env: BASE_REF: ${{ github.event.pull_request.base.ref }} run: | # Only count changeset files this PR added, ignoring pre-existing ones on the base branch. count=$(git diff --name-only --diff-filter=A "origin/${BASE_REF}...HEAD" | grep -E '^\.changeset/.+\.md$' | grep -cv README.md || true) if [[ "$count" -eq 0 ]]; then echo "found=false" >> "$GITHUB_OUTPUT" else echo "found=true" >> "$GITHUB_OUTPUT" echo "Found $count new changeset file(s)." fi - name: Manage changeset comment uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: SKIP: ${{ steps.labels.outputs.skip }} CHANGESET_FOUND: ${{ steps.check.outputs.found }} with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const marker = ''; const skip = process.env.SKIP === 'true'; const found = process.env.CHANGESET_FOUND === 'true'; const { owner, repo } = context.repo; const issue_number = context.issue.number; const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number, }); const existing = comments.find( (c) => c.user.type === 'Bot' && c.body.includes(marker), ); if (skip || found) { // Clean up the warning comment — changeset added or PR marked internal if (existing) { await github.rest.issues.deleteComment({ owner, repo, comment_id: existing.id, }); } return; } const body = `${marker} ## ⚠️ Missing changeset This pull request does not include a changeset. Please add one before requesting review so the change is properly documented and included in the release notes. **How to add a changeset:** 1. Run \`pnpm run document-change\` (interactive) and commit the generated file, or 2. Manually create \`.changeset/.md\`: \`\`\`md --- default: patch --- Short user-facing summary of the change. \`\`\` Replace \`patch\` with \`major\`, \`minor\`, \`patch\`, \`docs\`, or \`note\` as appropriate. 📖 Read more in [CONTRIBUTING.md](https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md#release-notes-and-versioning-knope). > If this PR is internal/maintenance with no user-facing impact, a maintainer can add the \`internal\` label to skip this check.`; if (existing) { await github.rest.issues.deleteComment({ owner, repo, comment_id: existing.id, }); } await github.rest.issues.createComment({ owner, repo, issue_number, body }); core.setFailed('No changeset found. Add a changeset file or apply the "internal" label to skip.');