Skip to content

Commit 3aa1c37

Browse files
authored
Create entropy-beauty-scan.yml
the yml for entropy + beauty scanning
1 parent dc11e37 commit 3aa1c37

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Entropy Beauty + TruffleHog Scan
2+
3+
on: [push, pull_request, release]
4+
5+
permissions:
6+
contents: read
7+
pull-requests: write
8+
9+
jobs:
10+
scan:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code (full history)
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Run TruffleHog
19+
uses: trufflesecurity/trufflehog@main
20+
with:
21+
path: .
22+
extra_args: --results=verified,unknown --filter-entropy=3.5 --json
23+
24+
- name: Compute mid-4 beauty entropy
25+
run: python .github/workflows/compute-entropy.py
26+
27+
- name: Post summary comment (PR only)
28+
if: github.event_name == 'pull_request'
29+
uses: actions/github-script@v7
30+
with:
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
script: |
33+
const fs = require('fs');
34+
35+
// Read TruffleHog output — it prints one JSON object per line (NDJSON)
36+
let findings = [];
37+
if (fs.existsSync('trufflehog.json')) {
38+
try {
39+
const lines = fs.readFileSync('trufflehog.json', 'utf8').trim().split('\n');
40+
findings = lines.map(line => {
41+
try { return JSON.parse(line); } catch(e) { return null; }
42+
}).filter(Boolean);
43+
} catch(e) {}
44+
} else {
45+
// Fallback: the action also logs to GITHUB_STEP_SUMMARY, but we use the file from the Python step
46+
console.log("No trufflehog.json found, using empty findings");
47+
}
48+
49+
const beauty = JSON.parse(fs.readFileSync('/tmp/beauty.json', 'utf8'));
50+
51+
let body = `## 🐷 TruffleHog + Entropy Beauty Scan\n\n`;
52+
body += `**Average entropy of changed code:** ${beauty.average_entropy} bits/char\n`;
53+
body += `**Verdict:** ${beauty.verdict}\n\n`;
54+
55+
if (beauty.files && beauty.files.length) {
56+
body += `**Changed files entropy:**\n\`\`\`\n${beauty.files.join('\n')}\n\`\`\`\n\n`;
57+
}
58+
59+
if (findings.length > 0) {
60+
body += `⚠️ **TruffleHog found ${findings.length} potential issue(s)**\n`;
61+
} else {
62+
body += `✅ No secrets or suspicious high-entropy strings found.\n`;
63+
}
64+
65+
body += `\n*Mid-4 beauty heuristic in action — powered by our entropy chats! 😊*`;
66+
67+
await github.rest.issues.createComment({
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
issue_number: context.issue.number,
71+
body: body
72+
});

0 commit comments

Comments
 (0)