forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (142 loc) · 5.66 KB
/
Copy pathpr-checks.yml
File metadata and controls
168 lines (142 loc) · 5.66 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
name: 🚨 Misaka Network Agent Auditor
on:
pull_request:
types: [opened, synchronize]
paths:
- '**.py'
- '**.js'
- '**.json'
- 'core/**'
- 'scripts/**'
- 'tests/**'
- 'misakanet/**'
- 'docs/**'
jobs:
audit:
permissions:
contents: read
issues: write
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🛑 DCO Pre-flight Gate
id: dco
run: |
bad=0
for commit in $(git log --format='%H' origin/${{ github.base_ref }}..HEAD 2>/dev/null || git log --format='%H' HEAD~${{ github.event.pull_request.commits }}..HEAD); do
msg=$(git log --format='%B' -1 "$commit")
if ! echo "$msg" | grep -qi 'Signed-off-by:'; then
echo "❌ Commit $commit is missing Signed-off-by:"
echo " $(git log --format='%s' -1 "$commit")"
bad=$((bad + 1))
fi
done
if [ "$bad" -gt 0 ]; then
echo "dco_passed=false" >> $GITHUB_OUTPUT
echo "⚠️ DCO FAILED — $bad commits missing Signed-off-by. Skipping expensive checks."
else
echo "dco_passed=true" >> $GITHUB_OUTPUT
echo "✅ DCO PASSED"
fi
- name: 🐍 Setup Python
if: steps.dco.outputs.dco_passed == 'true'
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: 📦 Install Dependencies
if: steps.dco.outputs.dco_passed == 'true'
run: |
pip install -r requirements.txt 2>/dev/null || true
pip install pytest pytest-cov
- name: 🔍 Check PR Size
if: steps.dco.outputs.dco_passed == 'true'
id: prsize
run: |
CHANGED=${{ github.event.pull_request.changed_files }}
ADDITIONS=${{ github.event.pull_request.additions }}
SUSPICIOUS=false
NOTES=""
if [ "$CHANGED" -gt 10 ]; then
SUSPICIOUS=true
NOTES="⚠️ ${CHANGED} files changed (threshold: 10)"
fi
if [ "$ADDITIONS" -gt 500 ]; then
SUSPICIOUS=true
NOTES="${NOTES}; ${ADDITIONS} lines added (threshold: 500)"
fi
echo "suspicious=${SUSPICIOUS}" >> $GITHUB_OUTPUT
echo "notes=${NOTES}" >> $GITHUB_OUTPUT
- name: 🧪 Run Test Suite
if: steps.dco.outputs.dco_passed == 'true'
id: pytest
run: |
pytest --cov=scripts --cov=misakanet --cov-report=term --cov-fail-under=70 tests/ > pytest_report.txt 2>&1
cat pytest_report.txt
continue-on-error: true
- name: 📊 Parse Coverage
if: steps.dco.outputs.dco_passed == 'true'
id: coverage
run: |
coverage=$(grep -oP 'TOTAL\s+\d+\s+\d+\s+\K\d+(?=%)' pytest_report.txt || echo "0")
echo "rate=$coverage" >> $GITHUB_OUTPUT
echo "Coverage: ${coverage}%"
- name: 🛡️ Frontend Shield Regression
if: steps.dco.outputs.dco_passed == 'true'
run: |
npm ci && npm test
continue-on-error: true
- name: 💬 Post Audit Report to PR
uses: actions/github-script@v7
with:
script: |
const dcoPassed = '${{ steps.dco.outputs.dco_passed }}' === 'true';
const fs = require('fs');
if (!dcoPassed) {
const body = `### 🤖 Misaka Audit Bot Report
❌ **DCO PRE-FLIGHT FAILED** — One or more commits are missing \`Signed-off-by:\`.
Expensive checks (tests, coverage, frontend QA) were skipped to conserve CI budget.
Please amend your commit with \`--signoff\` and push again.
*Triggered by: ${context.payload.pull_request.head.sha.slice(0, 7)}*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
core.setFailed('DCO pre-flight failed: commits missing Signed-off-by.');
return;
}
const report = fs.readFileSync('pytest_report.txt', 'utf8');
const success = '${{ steps.pytest.outcome }}' === 'success';
const coverage = '${{ steps.coverage.outputs.rate }}';
const threshold = 70;
const sizeSuspicious = '${{ steps.prsize.outputs.suspicious }}' === 'true';
const sizeNotes = '${{ steps.prsize.outputs.notes }}';
const header = success
? `✅ **PASS**: All tests passed (${coverage}% coverage)`
: `❌ **FAIL**: Test suite has failures`;
const coverageNote = parseInt(coverage) < threshold
? `\n⚠️ Coverage ${coverage}% is below ${threshold}% threshold.`
: '';
const sizeWarning = sizeSuspicious
? `\n🕵️ **SUSPICIOUS**: ${sizeNotes}`
: '';
const body = `### 🤖 Misaka Audit Bot Report
${header}${coverageNote}${sizeWarning}
\`\`\`text
${report.slice(0, 3000)}
\`\`\`
*Triggered by: ${context.payload.pull_request.head.sha.slice(0, 7)}*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
if (!success || parseInt(coverage) < threshold) {
core.setFailed('PR audit failed: tests or coverage below threshold.');
}