File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
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
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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 "
You can’t perform that action at this time.
0 commit comments