forked from ChelseaKR/outcome-receipts
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (72 loc) · 2.7 KB
/
Copy pathcodeql.yml
File metadata and controls
79 lines (72 loc) · 2.7 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
name: codeql
on:
# CI-CD-STANDARD §11e: PRs into main + weekly schedule; the former push:main
# trigger was redundant with the pull_request run and is dropped.
pull_request:
branches: [main]
schedule:
- cron: "19 4 * * 3"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: codeql-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
analyze:
name: codeql (python · actions)
runs-on: ubuntu-latest
permissions:
contents: read
actions: read # analyze repository Actions workflows without granting write access
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
persist-credentials: false
- uses: github/codeql-action/init@f205ea1c3313d32999d8d6a48b4f6530d4437b38 # v4.37.4
with:
languages: python,actions
queries: security-and-quality
config-file: ./.github/codeql-config.yml
- uses: github/codeql-action/analyze@f205ea1c3313d32999d8d6a48b4f6530d4437b38 # v4.37.4
with:
upload: never
output: codeql-results
- name: Enforce zero CodeQL findings
shell: bash
run: |
set -euo pipefail
mapfile -d '' sarif_files < <(
find codeql-results -type f -name '*.sarif' -print0
)
if (( ${#sarif_files[@]} == 0 )); then
printf '%s\n' \
'::error::CodeQL produced no SARIF files; refusing to pass without scan evidence.'
exit 1
fi
for sarif_file in "${sarif_files[@]}"; do
if ! jq -e '
.version == "2.1.0"
and ((.runs | type) == "array")
and ((.runs | length) > 0)
and all(.runs[]; .results == null or ((.results | type) == "array"))
' "$sarif_file" >/dev/null; then
printf '::error::Invalid or empty CodeQL SARIF: %s\n' "$sarif_file"
exit 1
fi
done
finding_count=$(jq -s '[.[] | .runs[]?.results[]?] | length' "${sarif_files[@]}")
if (( finding_count != 0 )); then
jq -rs \
'.[] | .runs[]?.results[]? | "\(.ruleId // "unknown rule"): \(.message.text // "finding")"' \
"${sarif_files[@]}"
printf '::error::CodeQL reported %s finding(s).\n' "$finding_count"
exit 1
fi
printf 'CodeQL SARIF gate: %s file(s), zero findings.\n' "${#sarif_files[@]}"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: always()
with:
name: codeql-results
path: codeql-results
if-no-files-found: error