-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
118 lines (101 loc) Β· 4.6 KB
/
Copy pathaction.yml
File metadata and controls
118 lines (101 loc) Β· 4.6 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
name: 'GitScout Security Auditor'
description: 'Statically audits your repository code and package lockfiles for security threats and malicious dependencies.'
author: 'adityazzzzz'
inputs:
path:
description: 'The directory path to audit (relative to the repo root).'
required: false
default: '.'
github-token:
description: 'Optional GitHub API token to bypass rate limits during remote dependency checks.'
required: false
fail-on-warnings:
description: 'Set to true to fail the build if high or critical warnings are found.'
required: false
default: 'true'
runs:
using: 'composite'
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '>=1.21'
cache: false # Disable caching inside composite action to prevent conflict with outer workflows
- name: Build GitScout CLI
shell: bash
run: |
cd "${{ github.action_path }}/backend"
go build -o gitscout ./cmd/cli
cp gitscout "${{ github.workspace }}/gitscout"
chmod +x "${{ github.workspace }}/gitscout"
- name: Run GitScout Audit
id: audit
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
echo "Running GitScout Security Audit..."
# Run scan and capture json output. Ignore exit code temporarily so we can generate step summary.
"${{ github.workspace }}/gitscout" "${{ inputs.path }}" -json > gitscout-report.json || true
cat gitscout-report.json
- name: Generate Job Summary
shell: node {0}
env:
REPORT_FILE: gitscout-report.json
FAIL_ON_WARNINGS: ${{ inputs.fail-on-warnings }}
run: |
const fs = require('fs');
const path = require('path');
try {
const reportPath = path.resolve(process.env.REPORT_FILE);
if (!fs.existsSync(reportPath)) {
console.error("GitScout report file not found.");
process.exit(1);
}
const raw = fs.readFileSync(reportPath, 'utf8');
const report = JSON.parse(raw);
// Generate Markdown Summary for GITHUB_STEP_SUMMARY
let md = `## π‘οΈ GitScout Security Audit Results\n\n`;
let scoreEmoji = "π’";
if (report.score < 70) scoreEmoji = "π΄";
else if (report.score < 90) scoreEmoji = "π‘";
md += `### Summary\n`;
md += `- **Verdict**: **${report.verdict.toUpperCase()}** ${scoreEmoji}\n`;
md += `- **Security Rating**: **${report.score}/100**\n`;
md += `- **Files Inspected**: ${report.files_scanned}\n`;
md += `- **Duration**: ${report.duration_ms}ms\n\n`;
md += `### Threat Metrics\n`;
md += `| Critical | High | Medium | Low |\n`;
md += `| --- | --- | --- | --- |\n`;
md += `| π₯ **${report.critical}** | π§ **${report.high}** | π¨ **${report.medium}** | π¦ **${report.low}** |\n\n`;
if (report.findings && report.findings.length > 0) {
md += `### Detailed Findings\n`;
md += `| Severity | Check ID | File | Description |\n`;
md += `| --- | --- | --- | --- |\n`;
report.findings.forEach(f => {
let sevEmoji = "π¦";
if (f.severity === 'critical') sevEmoji = "π₯";
else if (f.severity === 'high') sevEmoji = "π§";
else if (f.severity === 'medium') sevEmoji = "π¨";
md += `| ${sevEmoji} **${f.severity.toUpperCase()}** | \`${f.check_id}\` | \`${f.file || 'Local repository'}\` | ${f.description} |\n`;
});
md += `\n`;
} else {
md += `β
**No security threats or suspicious patterns detected. Clean codebase!**\n\n`;
}
md += `*Report generated statically by [GitScout](https://gitscout.meadityazzzz.in)*\n`;
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, md);
// Clean up the binary
try {
fs.unlinkSync(path.resolve('gitscout'));
} catch(e) {}
// Determine if we should fail the workflow run
const failed = report.score < 80 || report.verdict === 'dangerous';
if (failed && process.env.FAIL_ON_WARNINGS === 'true') {
console.log("::error::GitScout security rating is below threshold. Failing build step.");
process.exit(1);
}
} catch (err) {
console.error("Failed to parse GitScout audit output:", err);
process.exit(1);
}