Skip to content

Commit 622a72a

Browse files
kotakanbeclaude
andauthored
chore(ci): add Diet PR metrics workflow (#2469)
* ci: add Diet PR metrics workflow Automatically reports go.sum lines, direct dependency count, and binary size before/after on PRs that touch go.mod or go.sum. Results appear in GitHub Actions Step Summary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci: fix heredoc indentation and dep counting per Copilot review - Remove leading spaces from heredoc content so Step Summary renders as a proper markdown table instead of a code block - Count direct deps correctly by subtracting indirect from total (grep '// indirect' vs grep all tab-indented lines) - Add || echo 0 to grep -c to prevent exit code 1 on zero matches - Add indirect deps row to the metrics table Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci: add scanner-only binary size to diet metrics Build with -tags=scanner (cmd/scanner) in addition to the full build (cmd/vuls) to show the size impact on both build targets. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci: pin GitHub Actions to commit SHAs Pin actions/checkout and actions/setup-go to full commit SHAs to prevent supply chain attacks via tag mutation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3fbd296 commit 622a72a

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

.github/workflows/diet-check.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Diet PR Check
2+
on:
3+
pull_request:
4+
paths: ['go.mod', 'go.sum']
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
diet-metrics:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
14+
with:
15+
fetch-depth: 0
16+
17+
- uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
18+
with:
19+
go-version-file: go.mod
20+
21+
- name: Metrics (PR branch)
22+
run: |
23+
echo "AFTER_GOSUM=$(wc -l < go.sum)" >> "$GITHUB_ENV"
24+
echo "AFTER_DEPS=$(grep -c '// indirect' go.mod | tr -d ' ' || echo 0)" >> "$GITHUB_ENV"
25+
echo "AFTER_TOTAL=$(grep -cP $'^\t' go.mod || echo 0)" >> "$GITHUB_ENV"
26+
CGO_ENABLED=0 GOEXPERIMENT=jsonv2 go build -trimpath -o /tmp/vuls-after ./cmd/vuls
27+
echo "AFTER_SIZE=$(stat -c%s /tmp/vuls-after)" >> "$GITHUB_ENV"
28+
CGO_ENABLED=0 GOEXPERIMENT=jsonv2 go build -tags=scanner -trimpath -o /tmp/scanner-after ./cmd/scanner
29+
echo "AFTER_SCANNER_SIZE=$(stat -c%s /tmp/scanner-after)" >> "$GITHUB_ENV"
30+
31+
- name: Metrics (base branch)
32+
run: |
33+
git checkout "${{ github.event.pull_request.base.sha }}"
34+
echo "BEFORE_GOSUM=$(wc -l < go.sum)" >> "$GITHUB_ENV"
35+
echo "BEFORE_DEPS=$(grep -c '// indirect' go.mod | tr -d ' ' || echo 0)" >> "$GITHUB_ENV"
36+
echo "BEFORE_TOTAL=$(grep -cP $'^\t' go.mod || echo 0)" >> "$GITHUB_ENV"
37+
CGO_ENABLED=0 GOEXPERIMENT=jsonv2 go build -trimpath -o /tmp/vuls-before ./cmd/vuls
38+
echo "BEFORE_SIZE=$(stat -c%s /tmp/vuls-before)" >> "$GITHUB_ENV"
39+
CGO_ENABLED=0 GOEXPERIMENT=jsonv2 go build -tags=scanner -trimpath -o /tmp/scanner-before ./cmd/scanner
40+
echo "BEFORE_SCANNER_SIZE=$(stat -c%s /tmp/scanner-before)" >> "$GITHUB_ENV"
41+
42+
- name: Report
43+
run: |
44+
before_direct=$((BEFORE_TOTAL - BEFORE_DEPS))
45+
after_direct=$((AFTER_TOTAL - AFTER_DEPS))
46+
delta_gosum=$((AFTER_GOSUM - BEFORE_GOSUM))
47+
delta_direct=$((after_direct - before_direct))
48+
delta_indirect=$((AFTER_DEPS - BEFORE_DEPS))
49+
delta_kb=$(( (AFTER_SIZE - BEFORE_SIZE) / 1024 ))
50+
delta_scanner_kb=$(( (AFTER_SCANNER_SIZE - BEFORE_SCANNER_SIZE) / 1024 ))
51+
before_mb=$(awk "BEGIN{printf \"%.1f\", $BEFORE_SIZE/1048576}")
52+
after_mb=$(awk "BEGIN{printf \"%.1f\", $AFTER_SIZE/1048576}")
53+
before_scanner_mb=$(awk "BEGIN{printf \"%.1f\", $BEFORE_SCANNER_SIZE/1048576}")
54+
after_scanner_mb=$(awk "BEGIN{printf \"%.1f\", $AFTER_SCANNER_SIZE/1048576}")
55+
cat <<EOF >> "$GITHUB_STEP_SUMMARY"
56+
## Diet Metrics
57+
| Metric | Before | After | Delta |
58+
|--------|--------|-------|-------|
59+
| go.sum lines | $BEFORE_GOSUM | $AFTER_GOSUM | ${delta_gosum} |
60+
| Direct deps | ${before_direct} | ${after_direct} | ${delta_direct} |
61+
| Indirect deps | $BEFORE_DEPS | $AFTER_DEPS | ${delta_indirect} |
62+
| Binary size (full) | ${before_mb}MB | ${after_mb}MB | ${delta_kb}KB |
63+
| Binary size (scanner) | ${before_scanner_mb}MB | ${after_scanner_mb}MB | ${delta_scanner_kb}KB |
64+
EOF

0 commit comments

Comments
 (0)