-
-
Notifications
You must be signed in to change notification settings - Fork 4k
303 lines (258 loc) · 9.55 KB
/
Copy pathpr-validation.yml
File metadata and controls
303 lines (258 loc) · 9.55 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
name: PR Validation and Review
on:
pull_request:
types: [opened, edited, synchronize, ready_for_review, reopened]
paths:
- 'README.md'
- 'company-profiles/**'
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to validate (optional)'
required: false
type: string
permissions:
contents: read
pull-requests: write
issues: write
statuses: write
checks: write
env:
VALIDATION_BOT_NAME: "🤖 Remote Jobs Validator"
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
has-changes: ${{ steps.changes.outputs.has-changes }}
readme-changed: ${{ steps.changes.outputs.readme-changed }}
profiles-changed: ${{ steps.changes.outputs.profiles-changed }}
new-companies: ${{ steps.changes.outputs.new-companies }}
changed-profiles: ${{ steps.changes.outputs.changed-profiles }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v46
with:
files_yaml: |
readme:
- README.md
profiles:
- 'company-profiles/**'
- name: Analyze changes
id: changes
run: |
echo "readme-changed=${{ steps.changed-files.outputs.readme_any_changed }}" >> $GITHUB_OUTPUT
echo "profiles-changed=${{ steps.changed-files.outputs.profiles_any_changed }}" >> $GITHUB_OUTPUT
echo "changed-profiles=${{ steps.changed-files.outputs.profiles_all_changed_files }}" >> $GITHUB_OUTPUT
if [[ "${{ steps.changed-files.outputs.readme_any_changed }}" == "true" ]] && [[ "${{ steps.changed-files.outputs.profiles_any_changed }}" == "true" ]]; then
echo "new-companies=true" >> $GITHUB_OUTPUT
else
echo "new-companies=false" >> $GITHUB_OUTPUT
fi
if [[ "${{ steps.changed-files.outputs.readme_any_changed }}" == "true" ]] || [[ "${{ steps.changed-files.outputs.profiles_any_changed }}" == "true" ]]; then
echo "has-changes=true" >> $GITHUB_OUTPUT
else
echo "has-changes=false" >> $GITHUB_OUTPUT
fi
validate-readme:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.readme-changed == 'true'
outputs:
validation-result: ${{ steps.validate.outputs.result }}
errors: ${{ steps.validate.outputs.errors }}
warnings: ${{ steps.validate.outputs.warnings }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm install axios
- name: Validate README
id: validate
run: |
node .github/scripts/validate-readme.js
- name: Upload README validation results
uses: actions/upload-artifact@v4
with:
name: readme-validation-results
path: readme-result.json
retention-days: 1
validate-profiles:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.profiles-changed == 'true'
outputs:
validation-result: ${{ steps.validate.outputs.result }}
errors: ${{ steps.validate.outputs.errors }}
warnings: ${{ steps.validate.outputs.warnings }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm install axios
- name: Validate profiles
id: validate
run: |
export CHANGED_PROFILES="${{ needs.detect-changes.outputs.changed-profiles }}"
node .github/scripts/validate-profiles.js
- name: Upload profile validation results
uses: actions/upload-artifact@v4
with:
name: profile-validation-results
path: profiles-result.json
retention-days: 1
generate-report:
runs-on: ubuntu-latest
needs: [detect-changes, validate-readme, validate-profiles]
if: always() && needs.detect-changes.outputs.has-changes == 'true'
outputs:
success: ${{ steps.report.outputs.success }}
has-warnings: ${{ steps.report.outputs.has-warnings }}
total-errors: ${{ steps.report.outputs.total-errors }}
total-warnings: ${{ steps.report.outputs.total-warnings }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download validation results
uses: actions/download-artifact@v4
with:
path: validation-results
- name: Generate comprehensive report
id: report
run: |
export NEW_COMPANIES="${{ needs.detect-changes.outputs.new-companies }}"
node .github/scripts/generate-report.js
- name: Read validation report
id: read-report
run: |
if [ -f validation-report.md ]; then
echo "REPORT<<EOF" >> $GITHUB_OUTPUT
cat validation-report.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const report = `${{ steps.read-report.outputs.REPORT }}`;
if (!report) {
console.log('No report generated');
return;
}
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🤖 Remote Jobs Validator')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: report
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: report
});
}
- name: Update PR labels
uses: actions/github-script@v7
with:
script: |
const success = '${{ steps.report.outputs.success }}' === 'true';
const hasWarnings = '${{ steps.report.outputs.has-warnings }}' === 'true';
const isNewCompany = '${{ needs.detect-changes.outputs.new-companies }}' === 'true';
const labelsToRemove = ['validation-passed', 'validation-failed', 'has-warnings', 'new-company'];
const labelsToAdd = [];
if (success) {
labelsToAdd.push('validation-passed');
} else {
labelsToAdd.push('validation-failed');
}
if (hasWarnings) labelsToAdd.push('has-warnings');
if (isNewCompany) labelsToAdd.push('new-company');
for (const label of labelsToRemove) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: label
});
} catch (error) {}
}
for (const label of labelsToAdd) {
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [label]
});
} catch (error) {
console.log(`Could not add label ${label}`);
}
}
- name: Set commit status
uses: actions/github-script@v7
with:
script: |
const success = '${{ steps.report.outputs.success }}' === 'true';
const hasWarnings = '${{ steps.report.outputs.has-warnings }}' === 'true';
const totalErrors = parseInt('${{ steps.report.outputs.total-errors }}') || 0;
const totalWarnings = parseInt('${{ steps.report.outputs.total-warnings }}') || 0;
let state, description;
if (success && !hasWarnings) {
state = 'success';
description = '✅ All validation checks passed';
} else if (success && hasWarnings) {
state = 'success';
description = `⚠️ Passed with ${totalWarnings} warnings`;
} else {
state = 'failure';
description = `❌ Failed: ${totalErrors} errors, ${totalWarnings} warnings`;
}
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.payload.pull_request.head.sha,
state: state,
target_url: `${context.payload.repository.html_url}/actions/runs/${context.runId}`,
description: description,
context: 'remote-jobs-validation'
});
final-status:
runs-on: ubuntu-latest
needs: [detect-changes, generate-report]
if: always() && needs.detect-changes.outputs.has-changes == 'true'
steps:
- name: Final validation status
run: |
SUCCESS="${{ needs.generate-report.outputs.success }}"
if [ "$SUCCESS" = "true" ]; then
echo "✅ All validations passed!"
exit 0
else
echo "❌ Validation failed. Check PR comments for details."
exit 1
fi