-
Notifications
You must be signed in to change notification settings - Fork 3
212 lines (181 loc) · 8.14 KB
/
validate.yml
File metadata and controls
212 lines (181 loc) · 8.14 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
name: Validate Submission
on:
pull_request_target:
types: [opened, synchronize]
paths:
- 'commands/**'
permissions:
contents: read
pull-requests: write
issues: write
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: |
cd .github/scripts
npm ci
- name: Get changed files
id: files
uses: tj-actions/changed-files@v46
- name: Debug changed files
run: |
echo "All changed files:"
echo "${{ steps.files.outputs.all_changed_files }}"
echo "Commands dir changes:"
for file in ${{ steps.files.outputs.all_changed_files }}; do
if [[ "$file" == commands/* ]]; then
echo "- $file"
fi
done
- name: Run validation
id: validation
run: |
node .github/scripts/validate.js ${{ steps.files.outputs.all_changed_files }}
- name: Post validation results
if: failure()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
// Read validation results file
let validationResults;
try {
validationResults = JSON.parse(fs.readFileSync('.github/validation-results.json', 'utf8'));
} catch (error) {
console.error('Error reading validation results:', error);
validationResults = { errors: { general: ['Validation process failed'] } };
}
// Format error message
let message = '## Validation Failed ❌\n\n';
if (validationResults.errors) {
message += 'There are issues with your submission:\n\n';
for (const [file, errors] of Object.entries(validationResults.errors)) {
message += `### ${file}\n`;
for (const error of errors) {
message += `- ${error}\n`;
}
message += '\n';
}
}
message += 'Please make sure you follow the contribution guidelines:\n\n';
message += '1. Create your file at `commands/your-app-name/docker-run.md`\n';
message += '2. Include a valid GitHub repository URL\n';
message += '3. Add a proper Docker run command\n\n';
message += 'See [CONTRIBUTING.md](../../CONTRIBUTING.md) for more details.';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
# Handle validation failure - remove label if it exists
- name: Handle validation failure
if: failure()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Check if there were changes in commands directory
const changedFiles = '${{ steps.files.outputs.all_changed_files }}'.split(' ');
const commandsChanged = changedFiles.some(file => file.startsWith('commands/'));
if (!commandsChanged) {
console.log('No changes in commands directory. Skipping label removal.');
return;
}
try {
// Check if the validation-passed label exists on this PR
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const hasValidationLabel = labels.some(label => label.name === 'validation-passed');
// If the validation-passed label exists, remove it
if (hasValidationLabel) {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'validation-passed'
});
console.log('Removed validation-passed label due to validation failure');
// Add a comment notifying about the label removal
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## Validation Status Changed ❌\n\nYour submission has failed validation. The "validation-passed" label has been removed. Please check the validation errors and make the necessary corrections.'
});
}
} catch (error) {
console.error('Error handling validation failure:', error);
}
- name: Mark validation success
if: success()
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Check if there were changes in commands directory
const changedFiles = '${{ steps.files.outputs.all_changed_files }}'.split(' ');
const commandsChanged = changedFiles.some(file => file.startsWith('commands/'));
if (!commandsChanged) {
console.log('No changes in commands directory. Skipping success comment.');
return;
}
// Add a success comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## Validation Passed ✅\n\nYour submission has passed the automated validation checks. A maintainer will review your PR soon.'
});
// Add the "validation-passed" label
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['validation-passed']
});
// Check if this is an update to an existing command
try {
const fs = require('fs');
let validationResults;
try {
validationResults = JSON.parse(fs.readFileSync('.github/validation-results.json', 'utf8'));
} catch (error) {
console.error('Error reading validation results:', error);
return;
}
// If there are updates detected, add the command-update label
if (validationResults.updates && validationResults.updates.length > 0) {
console.log('Command updates detected:', validationResults.updates);
// Add the "command-update" label
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['command-update']
});
// Add a comment about the update
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## Command Update Detected 🔄\n\nThis PR updates an existing Docker run command. The validation has passed and the PR has been labeled accordingly.'
});
}
} catch (error) {
console.error('Error checking for command updates:', error);
}