forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (72 loc) · 2.49 KB
/
Copy pathlesson-gate.yml
File metadata and controls
80 lines (72 loc) · 2.49 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
name: Lesson Quality Gate
# Structural gate (issue #889): blocks PRs whose NEW/CHANGED lessons fail the
# quality checks (required frontmatter fields, min content length, duplicate
# titles, allowed domain, tag format). Runs only on lessons/ changes.
on:
pull_request:
paths:
- 'lessons/**'
- 'scripts/lesson_gate.py'
- 'tests/test_lesson_gate.py'
permissions:
contents: read
pull-requests: write
jobs:
gate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Get changed lesson files
id: changed
uses: tj-actions/changed-files@v47.0.6
with:
files: |
lessons/**/*.md
- name: Run lesson quality gate
if: steps.changed.outputs.any_changed == 'true'
id: gate
run: |
FILES="${{ steps.changed.outputs.all_changed_files }}"
# Convert space-separated list to args (paths have no spaces in this repo)
python3 scripts/lesson_gate.py $FILES > gate_report.txt 2>&1
GATE_EXIT=$?
cat gate_report.txt
echo "gate_exit=$GATE_EXIT" >> "$GITHUB_OUTPUT"
if [ "$GATE_EXIT" -ne 0 ]; then
echo "❌ Lesson quality gate FAILED — see report below."
exit 1
fi
- name: Run unit tests for the gate
if: steps.changed.outputs.any_changed == 'true'
run: |
pip install -q pytest
python3 -m pytest tests/test_lesson_gate.py -q
- name: Comment gate result on PR
if: steps.changed.outputs.any_changed == 'true'
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
let report = '✅ **Lesson Quality Gate passed.**';
let icon = '✅';
try {
const gateReport = fs.readFileSync('gate_report.txt', 'utf8');
if (gateReport.includes('FAIL')) {
icon = '❌';
report = '❌ **Lesson Quality Gate failed.** Check the report below.';
}
report += '\n\n```\n' + gateReport + '\n```';
} catch (e) {}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: report,
});