Repository navigation
Expand file tree
/
Copy pathgithub-workflow.yml
More file actions
90 lines (74 loc) · 2.84 KB
/
Copy pathgithub-workflow.yml
File metadata and controls
90 lines (74 loc) · 2.84 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
# KarpeSlop workflow for GitHub Actions.
# Copy this file to your project's .github/workflows/ directory.
# It runs on pull requests to main, master or develop and comments on the PR
# when the check fails. Pull requests from forks get a read-only token, so the
# comment is skipped for them; the failed check and the report still show.
name: KarpeSlop Check
on:
pull_request:
branches: [main, master, develop]
push:
branches: [main, master]
jobs:
slop-check:
name: KarpeSlop
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Run KarpeSlop
run: npx karpeslop@latest --quiet --strict
continue-on-error: false
- name: Upload Slop Report
if: always()
uses: actions/upload-artifact@v4
with:
name: ai-slop-report
path: ai-slop-report.json
if-no-files-found: ignore
retention-days: 7
# Optional: Comment on PR with slop summary
comment-on-pr:
name: Comment Results
runs-on: ubuntu-latest
needs: slop-check
permissions:
pull-requests: write
if: github.event_name == 'pull_request' && failure() && github.event.pull_request.head.repo.full_name == github.repository
steps:
# Missing when the run failed before the report was written.
- name: Download Slop Report
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: ai-slop-report
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
if (!fs.existsSync('ai-slop-report.json')) {
core.info('No KarpeSlop report: the check failed before writing one.');
return;
}
const report = JSON.parse(fs.readFileSync('ai-slop-report.json', 'utf8'));
const body = `## KarpeSlop report
| Severity | Count |
|----------|-------|
| Critical | ${report.bySeverity.critical} |
| High | ${report.bySeverity.high} |
| Medium | ${report.bySeverity.medium} |
| Low | ${report.bySeverity.low} |
**Total Issues:** ${report.totalOccurrences}
${report.bySeverity.critical > 0 ? '❌ **BLOCKING:** Critical findings (imports or packages that do not exist)' : ''}
See the full report in the Actions artifacts.`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});