77 schedule :
88 - cron : " 29 5 * * *"
99 workflow_dispatch :
10+ workflow_call :
11+ inputs :
12+ candidate_ref :
13+ description : Optional pre-release tag to scan instead of the triggering revision
14+ default : " "
15+ type : string
16+ fail-on-findings :
17+ description : Fail on HIGH/CRITICAL security findings (score at least 7.0)
18+ default : false
19+ type : boolean
1020
1121permissions :
1222 contents : read
1323 security-events : write
1424
1525concurrency :
16- group : ${{ github.workflow }}-${{ github.ref }}
26+ group : codeql- ${{ github.workflow }}-${{ inputs.candidate_ref || github.ref }}
1727 cancel-in-progress : true
1828
1929jobs :
3848 build-mode : none
3949 steps :
4050 - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
51+ id : checkout
4152 with :
53+ ref : ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }}
4254 persist-credentials : false
4355
4456 - name : Set up Go
6981 upload : never
7082
7183 - name : Summarize findings
84+ id : findings
7285 if : always()
7386 env :
7487 LANGUAGE : ${{ matrix.language }}
88+ FAIL_ON_FINDINGS : ${{ inputs.fail-on-findings || false }}
7589 shell : bash
7690 run : |
7791 set -euo pipefail
@@ -83,11 +97,23 @@ jobs:
8397 echo
8498 if [ "${#sarif_files[@]}" -eq 0 ]; then
8599 echo "No SARIF report was produced."
100+ exit 1
86101 else
87- finding_count=$(jq -s '[.[].runs[]?.results[]?] | length' "${sarif_files[@]}")
102+ finding_count=$(jq -s '[.[].runs[].results[]] | length' "${sarif_files[@]}")
103+ high_count=$(jq -s '
104+ [ .[].runs[] | . as $run | .results[]
105+ | select(all(.suppressions[]?; .status != "accepted"))
106+ | .ruleId as $id
107+ | ($run.tool.driver, $run.tool.extensions[]?) | .rules[]?
108+ | select(.id == $id)
109+ | select((.properties["security-severity"] // "0" | tonumber) >= 7)
110+ ] | length
111+ ' "${sarif_files[@]}")
112+ echo "high_count=$high_count" >> "$GITHUB_OUTPUT"
88113 echo "Findings: $finding_count"
114+ echo "HIGH/CRITICAL: $high_count"
89115 echo
90- echo "Findings are informational and do not fail CI. "
116+ echo "Fail on HIGH/CRITICAL: $FAIL_ON_FINDINGS "
91117 fi
92118 } >> "$GITHUB_STEP_SUMMARY"
93119
96122 uses : github/codeql-action/upload-sarif@ff2f1c621b7f889edc0d3c761ac2e6a3f8cdb0dd # v4.37.7
97123 with :
98124 sarif_file : codeql-results
125+ ref : ${{ inputs.candidate_ref && format('refs/tags/{0}', inputs.candidate_ref) || '' }}
126+ sha : ${{ inputs.candidate_ref && steps.checkout.outputs.commit || '' }}
99127 category : /language:${{ matrix.language }}
100128
101129 - name : Upload SARIF
@@ -107,8 +135,22 @@ jobs:
107135 if-no-files-found : ignore
108136 retention-days : 14
109137
138+ - name : Enforce HIGH/CRITICAL threshold
139+ if : ${{ !cancelled() && steps.findings.outcome == 'success' }}
140+ env :
141+ HIGH_COUNT : ${{ steps.findings.outputs.high_count }}
142+ FAIL_ON_FINDINGS : ${{ inputs.fail-on-findings || false }}
143+ run : |
144+ if [ "$HIGH_COUNT" -gt 0 ]; then
145+ if [ "$FAIL_ON_FINDINGS" = "true" ]; then
146+ echo "::error::CodeQL reported $HIGH_COUNT HIGH/CRITICAL findings."
147+ exit 1
148+ fi
149+ echo "::warning::CodeQL reported $HIGH_COUNT HIGH/CRITICAL findings; enforcement is disabled."
150+ fi
151+
110152 result :
111- name : OpenShell / CodeQL (informational)
153+ name : ${{ inputs.fail-on-findings && ' OpenShell / CodeQL' || 'OpenShell / CodeQL (informational)' }}
112154 if : always()
113155 needs : analyze
114156 runs-on : ubuntu-latest
@@ -120,7 +162,7 @@ jobs:
120162 shell : bash
121163 run : |
122164 if [ "$ANALYZE_RESULT" != "success" ]; then
123- echo "::error::One or more CodeQL analyzers did not complete successfully ."
165+ echo "::error::CodeQL execution or the configured finding threshold failed ."
124166 exit 1
125167 fi
126- echo "All CodeQL analyzers completed; findings remain informational ."
168+ echo "All CodeQL analyzers completed and the configured finding threshold passed ."
0 commit comments