forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (124 loc) · 4.88 KB
/
Copy pathlesson-quality.yml
File metadata and controls
144 lines (124 loc) · 4.88 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
name: Lesson Quality Score
# Runs on PRs that touch lessons/ directory
on:
pull_request:
paths:
- 'lessons/**'
- 'scripts/quality_scorer.py'
- 'scripts/lesson_lint.py'
permissions:
pull-requests: write
contents: read
jobs:
lint-check:
runs-on: ubuntu-latest
continue-on-error: true # Non-blocking for now
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Run lesson lint
id: lint
run: |
python scripts/lesson_lint.py --lessons-dir lessons --fail-on high --json > lint-output.json 2>&1 || true
HIGH=$(python -c "import json; d=json.load(open('lint-output.json')); print(sum(1 for i in d if i.get('severity')=='high'))" 2>/dev/null || echo "0")
MEDIUM=$(python -c "import json; d=json.load(open('lint-output.json')); print(sum(1 for i in d if i.get('severity')=='medium'))" 2>/dev/null || echo "0")
LOW=$(python -c "import json; d=json.load(open('lint-output.json')); print(sum(1 for i in d if i.get('severity')=='low'))" 2>/dev/null || echo "0")
echo "high=$HIGH" >> $GITHUB_OUTPUT
echo "medium=$MEDIUM" >> $GITHUB_OUTPUT
echo "low=$LOW" >> $GITHUB_OUTPUT
{
echo "### Lesson Lint Report"
echo "High: $HIGH | Medium: $MEDIUM | Low: $LOW"
echo ""
echo "Run locally: \`python scripts/lesson_lint.py --lessons-dir lessons -v\`"
} >> "$GITHUB_STEP_SUMMARY"
quality-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: pip install misakanet-core
- name: Get changed lesson files
id: changed
uses: tj-actions/changed-files@v47.0.6
with:
files: |
lessons/**/*.md
- name: Run quality scorer
if: steps.changed.outputs.any_changed == 'true'
id: quality
run: |
SCORES=""
PASS=true
THRESHOLD=0.5
for file in ${{ steps.changed.outputs.all_changed_files }}; do
if [[ "$file" == lessons/*.md ]]; then
SCORE=$(python3 scripts/quality_scorer.py "$file" --json 2>/dev/null | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('total_score') if d.get('total_score') is not None else (d.get('lessons') or [{}])[0].get('total_score') or (d.get('lessons') or [{}])[0].get('score',0)/100)" 2>/dev/null || echo "0")
SCORES="$SCORES\n$file: $SCORE"
if (( $(echo "$SCORE < $THRESHOLD" | bc -l) )); then
PASS=false
fi
fi
done
echo "scores=$SCORES" >> $GITHUB_OUTPUT
echo "pass=$PASS" >> $GITHUB_OUTPUT
{
echo "### Lesson quality"
echo "pass=$PASS threshold=$THRESHOLD"
echo '```'
echo -e "$SCORES"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- name: Comment on PR
# Fork PRs often get HttpError: Resource not accessible by integration
# when commenting. Scores still ran; don't fail the check for that.
if: steps.changed.outputs.any_changed == 'true'
continue-on-error: true
uses: actions/github-script@v9
with:
script: |
const scores = `${{ steps.quality.outputs.scores }}`;
const pass = `${{ steps.quality.outputs.pass }}` === 'true';
const marker = '<!-- misakanet-lesson-quality -->';
// Find existing comment
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
}
);
const existing = comments.find(c => c.body.includes(marker));
const status = pass ? '✅ PASS' : '⚠️ BELOW THRESHOLD';
const body = `${marker}
## Lesson Quality Report
${status} (threshold: 0.5)
${scores || 'No lessons changed.'}
_Reported by lesson-quality workflow_
`;
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}