-
Notifications
You must be signed in to change notification settings - Fork 8
119 lines (105 loc) · 3.83 KB
/
Copy pathchangeset-check.yml
File metadata and controls
119 lines (105 loc) · 3.83 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
name: Changeset Check
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review, labeled]
branches: [master, develop]
jobs:
verify:
name: Verify Changeset
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-changeset') && !contains(github.event.pull_request.labels.*.name, 'dependencies') }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check for changeset
id: check
run: |
if pnpm changeset status --since=origin/${{ github.base_ref }}; then
echo "has_changeset=true" >> $GITHUB_OUTPUT
else
echo "has_changeset=false" >> $GITHUB_OUTPUT
exit 1
fi
- name: Comment on PR (success)
if: steps.check.outputs.has_changeset == 'true' && !github.event.pull_request.head.repo.fork
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- changeset-check -->';
const body = marker + '\n✅ Changeset file detected.';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body
});
}
- name: Comment on PR (failure)
if: failure() && !github.event.pull_request.head.repo.fork
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- changeset-check -->';
const body = [
marker,
'❌ **Missing Changeset**',
'',
'Please add a changeset describing your changes:',
'```bash',
'pnpm changeset',
'```',
'',
'If your changes do not need a version bump (docs, CI, refactoring),',
'add the `skip-changeset` label to this PR.',
'',
'For dependency updates, use the `dependencies` label.'
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});
}
skipped:
name: Changeset Check (Skipped)
if: ${{ contains(github.event.pull_request.labels.*.name, 'skip-changeset') || contains(github.event.pull_request.labels.*.name, 'dependencies') }}
runs-on: ubuntu-latest
steps:
- run: echo "⏭️ Changeset check skipped via label"