-
-
Notifications
You must be signed in to change notification settings - Fork 10
249 lines (215 loc) · 9.59 KB
/
validate-module-submission.yml
File metadata and controls
249 lines (215 loc) · 9.59 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
name: Validate Module Submission
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- "module-submissions/pending/**"
permissions:
pull-requests: write
contents: read
checks: write
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v47
with:
files: |
module-submissions/pending/**/*.json
- name: Validate submission files
id: validate
run: |
node scripts/module-submission/validate.ts
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
- name: Check for duplicates
id: duplicate-check
run: |
node scripts/module-submission/check-duplicates.ts
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
- name: Validate repository
id: repo-check
run: |
node scripts/module-submission/check-repository.ts
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check module quality
id: quality-check
run: |
node scripts/module-submission/quality-check.ts
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
- name: Generate validation report
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
// Read validation results
const results = {
schema: JSON.parse(fs.readFileSync('validation-results/schema.json', 'utf8')),
duplicates: JSON.parse(fs.readFileSync('validation-results/duplicates.json', 'utf8')),
repository: JSON.parse(fs.readFileSync('validation-results/repository.json', 'utf8')),
quality: JSON.parse(fs.readFileSync('validation-results/quality.json', 'utf8'))
};
// Generate report
let report = '## 🤖 Automated Validation Report\n\n';
// Schema validation
report += '### ✅ JSON Schema Validation\n';
if (results.schema.valid) {
report += '- ✅ All submission files are valid\n\n';
} else {
report += '- ❌ Schema validation failed:\n';
results.schema.errors.forEach(err => {
report += ` - ${err}\n`;
});
report += '\n';
}
// Duplicate check
report += '### 🔍 Duplicate Check\n';
if (results.duplicates.duplicates.length === 0) {
report += '- ✅ No duplicates found\n\n';
} else {
report += '- ⚠️ Possible duplicates detected:\n';
results.duplicates.duplicates.forEach(dup => {
report += ` - ${dup.name} (${dup.existingUrl})\n`;
});
report += '\n';
}
// Repository validation
report += '### 📦 Repository Validation\n';
const repo = results.repository;
report += `- ${repo.accessible ? '✅' : '❌'} Repository is accessible\n`;
report += `- ${repo.hasPackageJson ? '✅' : '❌'} Contains \`package.json\`\n`;
report += `- ${repo.hasLicense ? '✅' : '❌'} Contains LICENSE file\n`;
report += `- ${repo.hasReadme ? '✅' : '❌'} Contains README.md\n`;
report += `- ${repo.validLicense ? '✅' : '⚠️'} License is ${repo.license || 'not specified'}\n`;
report += '\n';
// Quality checks
report += '### 🎯 Quality Checks\n';
const quality = results.quality;
report += `- ${quality.hasScreenshot ? '✅' : '⚠️'} Screenshot ${quality.hasScreenshot ? 'found' : 'not found'}\n`;
report += `- ${quality.followsNaming ? '✅' : '⚠️'} Module name ${quality.followsNaming ? 'follows' : 'does not follow'} MMM-* convention\n`;
report += `- ${quality.hasKeywords ? '✅' : '⚠️'} Package.json ${quality.hasKeywords ? 'contains' : 'missing'} keywords\n`;
report += `- ${quality.recentActivity ? '✅' : '⚠️'} Last commit: ${quality.lastCommit}\n`;
report += '\n';
// Overall status
const allPassed = results.schema.valid &&
results.duplicates.duplicates.length === 0 &&
repo.accessible &&
repo.hasPackageJson &&
repo.hasLicense &&
repo.hasReadme;
if (allPassed) {
report += '---\n\n';
report += '## ✅ **All Required Checks Passed!**\n\n';
report += 'This submission meets all requirements and is ready for maintainer review.\n\n';
// Check if auto-merge eligible
const author = context.payload.pull_request.user.login;
const isTrusted = false; // TODO: Implement trusted user check
if (isTrusted) {
report += '🎉 **Auto-merge eligible** - This user is a trusted contributor.\n';
} else {
report += '👀 **Awaiting maintainer approval**\n';
}
} else {
report += '---\n\n';
report += '## ⚠️ **Action Required**\n\n';
report += 'Please address the issues marked with ❌ above before this submission can be approved.\n';
}
// Post comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: report
});
// Update check status
if (allPassed) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['validation-passed', 'ready-for-review']
});
} else {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['validation-failed', 'needs-changes']
});
}
check-trusted-user:
needs: validate
if: contains(github.event.pull_request.labels.*.name, 'validation-passed')
runs-on: ubuntu-latest
steps:
- name: Check if user is in trusted-contributors team
id: check-trusted
uses: actions/github-script@v9
with:
script: |
const author = context.payload.pull_request.user.login;
// Check if user is in trusted-contributors team
try {
const teamMembership = await github.rest.teams.getMembershipForUserInOrg({
org: context.repo.owner,
team_slug: 'trusted-contributors',
username: author
});
const isTrusted = teamMembership.data.state === 'active';
if (isTrusted) {
// Auto-approve the PR
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
event: 'APPROVE',
body: '✅ **Auto-approved**\n\nThis submission passed all validation checks and was submitted by a trusted contributor.'
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['auto-approved', 'trusted-contributor']
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '🎉 This PR has been **auto-approved** and is ready to merge!\n\nThanks for your contribution, @' + author + '!'
});
} else {
// Regular user - request maintainer review
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '✅ All validation checks passed! This PR is ready for maintainer review.\n\n**Note:** Trusted contributors get auto-approval. Keep up the good work to become a trusted contributor!'
});
}
return isTrusted;
} catch (error) {
// User is not in team - this is fine, just needs manual review
console.log('User is not in trusted-contributors team (this is normal for new contributors)');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '✅ All validation checks passed! This PR is ready for maintainer review.'
});
return false;
}