-
Notifications
You must be signed in to change notification settings - Fork 14
112 lines (94 loc) · 4.07 KB
/
require-changeset.yml
File metadata and controls
112 lines (94 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Require Changeset
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches: [dev]
permissions: {}
jobs:
require-changeset:
runs-on: ubuntu-latest
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
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@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
SKIP: ${{ steps.labels.outputs.skip }}
CHANGESET_FOUND: ${{ steps.check.outputs.found }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const marker = '<!-- require-changeset -->';
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/<descriptive-name>.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.');