-
Notifications
You must be signed in to change notification settings - Fork 3
135 lines (115 loc) · 4.35 KB
/
Copy pathtemplate-check.yml
File metadata and controls
135 lines (115 loc) · 4.35 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
name: Template Check
on:
pull_request:
paths:
- 'vup/srcpkgs/**/*'
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: actions/checkout@v7
with:
path: pr
fetch-depth: 0
- name: Checkout Base Scripts
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
fetch-depth: 0
- name: Validate Templates
id: validate
run: |
cd pr
git fetch origin main
CHANGED=$(git diff --name-only origin/main...HEAD -- 'vup/srcpkgs/*/*/template')
if [ -z "$CHANGED" ]; then
echo "No template changes detected."
echo "passed=true" >> "$GITHUB_OUTPUT"
echo "No template changes detected." > /tmp/validation-output.txt
exit 0
fi
echo "Validating changed templates:"
echo "$CHANGED"
# Capture both stdout and exit code
OUTPUT=$(python3 ../base/vup/scripts/validate_template.py $CHANGED 2>&1) && RC=$? || RC=$?
echo "$OUTPUT"
if [ $RC -ne 0 ]; then
echo "passed=false" >> "$GITHUB_OUTPUT"
# Save output for the job summary
echo "$OUTPUT" > /tmp/validation-errors.txt
exit 0 # Don't fail the step, we want to report the errors cleanly
else
echo "passed=true" >> "$GITHUB_OUTPUT"
echo "$OUTPUT" > /tmp/validation-output.txt
fi
- name: Report Failure
if: steps.validate.outputs.passed == 'false'
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const errors = fs.readFileSync('/tmp/validation-errors.txt', 'utf8');
const prNumber = context.payload.pull_request.number;
const body = [
'### :x: Template Validation Failed',
'',
'Your template has issues that must be fixed before this PR can be built:',
'',
'```',
errors.trim(),
'```',
'',
'Fix the errors above, push your changes, and the check will re-run automatically.',
].join('\n');
const reportDir = 'pr-check-report';
fs.mkdirSync(reportDir, { recursive: true });
fs.writeFileSync(`${reportDir}/pr_number.txt`, `${prNumber}\n`);
fs.writeFileSync(`${reportDir}/status.txt`, 'failure\n');
fs.writeFileSync(`${reportDir}/details.txt`, `${errors.trim()}\n`);
await core.summary
.addRaw(body)
.write();
core.setFailed('Template validation failed.');
- name: Report Success
if: steps.validate.outputs.passed == 'true'
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const output = fs.readFileSync('/tmp/validation-output.txt', 'utf8');
const prNumber = context.payload.pull_request.number;
const hasWarnings = output.includes('WARNING:');
const body = hasWarnings
? [
'### :warning: Template Validation Passed (with warnings)',
'',
'```',
output.trim(),
'```',
].join('\n')
: [
'### :white_check_mark: Template Validation Passed',
'',
'All required fields are present.',
].join('\n');
const reportDir = 'pr-check-report';
fs.mkdirSync(reportDir, { recursive: true });
fs.writeFileSync(`${reportDir}/pr_number.txt`, `${prNumber}\n`);
fs.writeFileSync(`${reportDir}/status.txt`, hasWarnings ? 'warning\n' : 'success\n');
fs.writeFileSync(`${reportDir}/details.txt`, `${output.trim()}\n`);
await core.summary
.addRaw(body)
.write();
- name: Upload PR Check Report
if: always()
uses: actions/upload-artifact@v7
with:
name: pr-check-report
path: pr-check-report/*
if-no-files-found: ignore