-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (173 loc) Β· 7.1 KB
/
pr-validation.yml
File metadata and controls
208 lines (173 loc) Β· 7.1 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
name: PR Validation
on:
pull_request:
branches: [master]
types: [opened, synchronize, reopened]
concurrency:
group: pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
validate:
name: π Validate Pull Request
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Comment in progress
uses: actions/github-script@v9
with:
script: |
const marker = '<!-- pr-validation-bot -->';
const body = `${marker}
β³ **PR Validation IN PROGRESS**
**Commit:** \`${{ github.event.pull_request.head.sha }}\`
**Branch:** \`${{ github.head_ref }}\`
**Checks:**
- β³ Release guard (no version/changelog changes)
- β³ Dependencies installed
- β³ Type check passed
- β³ Linting passed
- β³ Format check passed
- β³ Tests + coverage passed
- β³ Build successful
---
π [View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
β° Started at: \`${new Date().toISOString()}\``;
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.user.login === 'github-actions[bot]' && c.body.startsWith(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body,
});
}
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'npm'
- name: Install dependencies
id: install
run: npm ci
- name: π Release guard
id: release-guard
run: |
# Skip check for release/* branches β those are created by release-prepare
if [[ "${{ github.head_ref }}" == release/* ]]; then
echo "outcome=success" >> $GITHUB_OUTPUT
echo "β
Release branch β version/changelog changes allowed"
exit 0
fi
ERRORS=""
# Check if package.json version was changed
VERSION_DIFF=$(git diff origin/${{ github.base_ref }}...HEAD -- package.json | grep -E '^\+.*"version"' || true)
if [ -n "$VERSION_DIFF" ]; then
ERRORS="${ERRORS}\n- β \`package.json\` version was modified β use \`release-prepare\` workflow instead"
fi
# Check if CHANGELOG.md was changed
CHANGELOG_DIFF=$(git diff origin/${{ github.base_ref }}...HEAD --name-only | grep -E '^CHANGELOG\.md$' || true)
if [ -n "$CHANGELOG_DIFF" ]; then
ERRORS="${ERRORS}\n- β \`CHANGELOG.md\` was modified β changelog is auto-generated by \`release-prepare\` workflow"
fi
if [ -n "$ERRORS" ]; then
echo "outcome=failure" >> $GITHUB_OUTPUT
echo -e "β Release guard failed:${ERRORS}"
echo -e "message=${ERRORS}" >> $GITHUB_OUTPUT
exit 1
else
echo "outcome=success" >> $GITHUB_OUTPUT
echo "β
No version or changelog changes detected"
fi
- name: Type check
id: type-check
if: always() && steps.install.outcome == 'success'
run: npm run type-check
- name: Lint
id: lint
if: always() && steps.install.outcome == 'success'
run: npm run lint
- name: Format check
id: format
if: always() && steps.install.outcome == 'success'
run: npm run format:check
- name: Test with coverage
id: test
if: always() && steps.install.outcome == 'success'
run: npm run test:coverage
- name: Build
id: build
if: always() && steps.install.outcome == 'success'
run: npm run build
- name: Comment on PR
if: always()
uses: actions/github-script@v9
with:
script: |
const marker = '<!-- pr-validation-bot -->';
const checks = [
{ name: 'Release guard (no version/changelog changes)', outcome: '${{ steps.release-guard.outcome }}' },
{ name: 'Dependencies installed', outcome: '${{ steps.install.outcome }}' },
{ name: 'Type check passed', outcome: '${{ steps.type-check.outcome }}' },
{ name: 'Linting passed', outcome: '${{ steps.lint.outcome }}' },
{ name: 'Format check passed', outcome: '${{ steps.format.outcome }}' },
{ name: 'Tests + coverage passed', outcome: '${{ steps.test.outcome }}' },
{ name: 'Build successful', outcome: '${{ steps.build.outcome }}' },
];
const allPassed = checks.every(c => c.outcome === 'success');
const status = allPassed ? 'β
PASSED' : 'β FAILED';
const emoji = allPassed ? 'π' : 'π₯';
const checkLines = checks
.map(c => `- ${c.outcome === 'success' ? 'β
' : c.outcome === 'skipped' ? 'βοΈ' : 'β'} ${c.name}`)
.join('\n');
const body = `${marker}
${emoji} **PR Validation ${status}**
**Commit:** \`${{ github.event.pull_request.head.sha }}\`
**Branch:** \`${{ github.head_ref }}\`
**Checks:**
${checkLines}
${allPassed ? '**Ready to merge!** β¨' : '**Please fix the failing checks.**'}
---
π [View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
β° Generated at: \`${new Date().toISOString()}\``;
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.user.login === 'github-actions[bot]' && c.body.startsWith(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body,
});
}