forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (81 loc) · 3.04 KB
/
Copy pathmanual-audit.yml
File metadata and controls
96 lines (81 loc) · 3.04 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
name: Manual PR Audit
on:
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to audit'
required: true
type: string
jobs:
audit:
permissions:
contents: read
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout PR
uses: actions/checkout@v7
with:
ref: refs/pull/${{ github.event.inputs.pr_number }}/head
fetch-depth: 0
- name: 🐍 Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: 📦 Install Dependencies
run: |
pip install -r requirements.txt 2>/dev/null || true
pip install pytest pytest-cov
echo "PYTHONPATH=$(pwd):$PYTHONPATH" >> $GITHUB_ENV
- name: 🧪 Run Test Suite
id: pytest
run: |
pytest --cov=scripts --cov=misakanet --cov-report=term --cov-fail-under=20 tests/ > pytest_report.txt 2>&1
cat pytest_report.txt
continue-on-error: true
- name: 📊 Parse Coverage
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: 💬 Post Report to PR
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const prNumber = parseInt('${{ github.event.inputs.pr_number }}');
let reportBody = '';
let failed = false;
try {
const report = fs.readFileSync('pytest_report.txt', 'utf8');
const success = '${{ steps.pytest.outcome }}' === 'success';
const coverage = '${{ steps.coverage.outputs.rate }}';
const threshold = 20;
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.'
: '';
reportBody = header + coverageNote + '\n\n```text\n' + report.slice(0, 3000) + '\n```';
failed = !success || parseInt(coverage) < threshold;
} catch {
reportBody = '*Test suite did not produce a report.*';
}
const body = '### 🤖 Manual Audit Report\n\n' + reportBody + '\n\n*Triggered manually*';
try {
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
} catch (err) {
console.log('Failed to post comment:', err.message);
}
if (failed) {
core.setFailed('Audit failed: tests or coverage below threshold.');
}