Skip to content

Commit 04a02dc

Browse files
committed
bash version
1 parent 6153273 commit 04a02dc

3 files changed

Lines changed: 38 additions & 55 deletions

File tree

.github/workflows/semgrep.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
ref: ${{ github.repository == 'grafana/security-github-actions' && (github.head_ref || github.ref_name) || '' }}
3434
sparse-checkout: |
3535
semgrep/custom-rules.yaml
36-
semgrep/format-results.py
36+
semgrep/format-results.sh
3737
path: security-github-actions
3838
# Run semgrep with: auto rules + org-wide shared rules
3939
- id: semgrep
@@ -46,7 +46,7 @@ jobs:
4646
echo "has_findings=true" >> "$GITHUB_OUTPUT"
4747
{
4848
echo 'SEMGREP_OUTPUT<<SEMGREP_EOF'
49-
python3 security-github-actions/semgrep/format-results.py /tmp/semgrep-results.json
49+
bash security-github-actions/semgrep/format-results.sh /tmp/semgrep-results.json
5050
echo 'SEMGREP_EOF'
5151
} >> "$GITHUB_ENV"
5252
fi

semgrep/format-results.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

semgrep/format-results.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Format semgrep JSON results into a GitHub-flavored markdown comment.
3+
set -euo pipefail
4+
5+
INPUT_FILE="$1"
6+
7+
RESULTS_COUNT=$(jq '.results | length' "$INPUT_FILE")
8+
9+
if [ "$RESULTS_COUNT" -eq 0 ]; then
10+
exit 0
11+
fi
12+
13+
echo "## Semgrep Findings"
14+
echo ""
15+
echo "**${RESULTS_COUNT}** finding(s) detected."
16+
echo ""
17+
echo "| Severity | Rule | File | Message |"
18+
echo "|----------|------|------|---------|"
19+
20+
jq -r '.results[] | {
21+
sev: .extra.severity,
22+
rule: (.check_id | split(".")[-1]),
23+
path: .path,
24+
line: .start.line,
25+
msg: (.extra.message | gsub("\n"; " ") | ltrimstr(" ") | rtrimstr(" "))
26+
} | {
27+
icon: (if .sev == "ERROR" then "🔴"
28+
elif .sev == "WARNING" then "🟡"
29+
elif .sev == "INFO" then "🔵"
30+
else "⚪" end),
31+
sev: .sev,
32+
rule: .rule,
33+
path: .path,
34+
line: .line,
35+
msg: .msg
36+
} | "| \(.icon) \(.sev) | `\(.rule)` | `\(.path):\(.line)` | \(.msg) |"' "$INPUT_FILE"

0 commit comments

Comments
 (0)