-
Notifications
You must be signed in to change notification settings - Fork 1
264 lines (222 loc) · 9.56 KB
/
changeset-check.yml
File metadata and controls
264 lines (222 loc) · 9.56 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
name: Check Changeset
on:
pull_request:
types: [opened, synchronize, edited]
branches:
- main
jobs:
changeset-check:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Check for skip changeset flag
id: skip_check
uses: actions/github-script@v7
with:
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const prBody = pr.body || '';
const shouldSkip = prBody.includes('#skip-changeset');
if (shouldSkip) {
console.log('🔄 Found #skip-changeset in PR description. Skipping changeset check.');
}
return { skip: shouldSkip };
- name: Comment on PR - Skipped
if: fromJSON(steps.skip_check.outputs.result).skip == true
uses: actions/github-script@v7
with:
script: |
const commentBody = `## 🔄 Changeset Check Skipped
This PR has been marked to skip the changeset requirement using \`#skip-changeset\`.
**Note:** This should only be used for changes that don't affect the published package, such as:
- Documentation updates
- CI/CD changes
- Development tooling changes
- README updates
If this PR contains code changes that affect the public API, please remove \`#skip-changeset\` and add a proper changeset.
<!-- changeset-check-comment -->`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.body.includes('<!-- changeset-check-comment -->')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Exit early if skipped
if: fromJSON(steps.skip_check.outputs.result).skip == true
run: |
echo "✅ Changeset check skipped via PR description flag"
exit 0
- name: Install pnpm
if: fromJSON(steps.skip_check.outputs.result).skip != true
uses: pnpm/action-setup@v2
with:
version: 10
run_install: false
- name: Get pnpm store directory
if: fromJSON(steps.skip_check.outputs.result).skip != true
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
if: fromJSON(steps.skip_check.outputs.result).skip != true
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
if: fromJSON(steps.skip_check.outputs.result).skip != true
run: pnpm install --frozen-lockfile
- name: Check for changeset
if: fromJSON(steps.skip_check.outputs.result).skip != true
id: changeset_check
run: |
echo "Checking if this PR added a changeset file..."
# Check if this PR has added any new changeset files compared to main
git fetch origin main:main
# Look for new changeset files added in this PR (excluding README.md)
new_changesets=$(git diff --name-only --diff-filter=A main...HEAD | grep '^\.changeset/.*\.md$' | grep -v 'README\.md' || true)
if [ -n "$new_changesets" ]; then
echo "✅ This PR added the following changeset(s):"
echo "$new_changesets" | while read -r file; do
echo " - $(basename "$file")"
done
echo "status=success" >> $GITHUB_OUTPUT
else
echo "❌ This PR has not added any changeset files."
# Check if there are actually package changes that would require a changeset
status_output=$(pnpm changeset status --since=main 2>&1 || true)
echo "Changeset status output:"
echo "$status_output"
# If changeset status indicates changes but no changesets, we need one
if echo "$status_output" | grep -q "The following packages are changed but have no changesets"; then
echo "❌ Changes detected in packages but no changeset found in this PR!"
echo "status=missing" >> $GITHUB_OUTPUT
elif echo "$status_output" | grep -q "No changesets present"; then
echo "✅ No changeset needed (no package changes detected)"
echo "status=no_changes" >> $GITHUB_OUTPUT
else
echo "❌ Unable to determine status, requiring changeset for safety"
echo "status=missing" >> $GITHUB_OUTPUT
fi
fi
- name: Comment on PR - Missing Changeset
if: fromJSON(steps.skip_check.outputs.result).skip != true && steps.changeset_check.outputs.status == 'missing'
uses: actions/github-script@v7
with:
script: |
const commentBody = `## ❌ Missing Changeset
This PR appears to have changes but is missing a changeset.
**What you need to do:**
1. Run \`pnpm changeset\` in your local repository
2. Follow the prompts to describe your changes
3. Commit the generated changeset file
4. Push the changes to this PR
**Why changesets?**
Changesets help us:
- Track what changed between versions
- Generate accurate changelogs
- Determine appropriate version bumps
- Ensure nothing gets released without proper documentation
[Learn more about changesets](https://github.com/changesets/changesets)
<!-- changeset-check-comment -->`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.body.includes('<!-- changeset-check-comment -->')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Comment on PR - Changeset Found
if: fromJSON(steps.skip_check.outputs.result).skip != true && steps.changeset_check.outputs.status == 'success'
uses: actions/github-script@v7
with:
script: |
const commentBody = `## ✅ Changeset Found
Great! This PR includes the required changeset(s). The changes are properly documented and ready for review.
<!-- changeset-check-comment -->`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.body.includes('<!-- changeset-check-comment -->')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Fail if changeset is missing
if: fromJSON(steps.skip_check.outputs.result).skip != true && steps.changeset_check.outputs.status == 'missing'
run: |
echo "❌ This PR requires a changeset. Please add one and push the changes."
exit 1