Skip to content

Commit b0e83f3

Browse files
jkowallManik2708
authored andcommitted
fix(ci): Fix CodeQL workflow to properly analyze Go code (jaegertracing#7885)
## Which problem is this PR solving? This PR fixes two CodeQL security scanning issues visible at: https://github.com/jaegertracing/jaeger/security/code-scanning/tools/CodeQL/status/configurations/actions-FZTWS5DIOVRC653POJVWM3DPO5ZS6Y3PMRSXC3BOPFWWY ### Issue 1: "Go files were found but not processed" CodeQL's `Autobuild` step was unable to properly compile the Go codebase, preventing security analysis. ### Issue 2: "Code Scanning results may be out of date" The last successful scan was Feb 13, 2025. This was caused by PR jaegertracing#6719 which added: ```yaml if: ${{ github.event_name == 'pull_request' }} ``` This condition was intended to prevent duplicate runs in merge queue, but it also disabled scans for: - Push events to `main` - Scheduled weekly runs ## Description of the changes ### Fix for Autobuild failure - Replace `Autobuild` with explicit `go build ./...` for Go (Autobuild is kept for Python) - Add `setup-go` action to ensure Go is properly configured - Add `submodules: true` to checkout for complete codebase ### Fix for stale scan results - Change condition from `== 'pull_request'` to `!= 'merge_group'` - This preserves the merge queue optimization while enabling scans on all other triggers ### Updated trigger behavior | Event | CodeQL Runs? | Reason | |-------|-------------|--------| | `pull_request` | ✅ Yes | Primary scan when code is submitted | | `push` to main | ✅ Yes | Catches direct commits & validates merged code | | `schedule` (weekly) | ✅ Yes | Catches new vulnerabilities in dependencies | | `merge_group` | ❌ Skipped | Already scanned on `pull_request` | ## How was this change tested? - Manual review of workflow syntax - Verification that the workflow triggers correctly based on GitHub Actions documentation ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have run lint and test steps successfully (N/A - workflow file only) ## References - Original issue: github/codeql-action#1537 - PR that introduced the restriction: jaegertracing#6719 Signed-off-by: Jonah Kowall <[email protected]>
1 parent 1f304f1 commit b0e83f3

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

‎.github/workflows/codeql.yml‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: "CodeQL"
22

33
on:
4+
merge_group:
45
push:
56
branches: [main]
67

@@ -20,8 +21,9 @@ permissions: # added using https://github.com/step-security/secure-workflows
2021

2122
jobs:
2223
codeql-analyze:
23-
# Run only on pull requests, see https://github.com/github/codeql-action/issues/1537
24-
if: ${{ github.event_name == 'pull_request' }}
24+
# Skip merge_group to avoid duplicate runs (code already scanned on pull_request)
25+
# See https://github.com/github/codeql-action/issues/1537
26+
if: ${{ github.event_name != 'merge_group' }}
2527
name: CodeQL Analyze
2628
runs-on: ubuntu-latest
2729

@@ -33,29 +35,40 @@ jobs:
3335
fail-fast: false
3436
matrix:
3537
language: [ 'go', 'python' ]
36-
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
3738

3839
steps:
3940
- name: Harden Runner
4041
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
4142
with:
42-
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
43+
egress-policy: audit
4344

4445
- name: Checkout repository
4546
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
47+
with:
48+
submodules: true
49+
50+
- name: Setup Go
51+
if: matrix.language == 'go'
52+
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
53+
with:
54+
go-version: 1.25.x
4655

47-
# Initializes the CodeQL tools for scanning.
4856
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4
57+
uses: github/codeql-action/init@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8
5058
with:
5159
languages: ${{ matrix.language }}
52-
# If you wish to specify custom queries, you can do so here or in a config file.
53-
# By default, queries listed here will override any specified in a config file.
54-
# Prefix the list here with "+" to use these queries and those in the config file.
55-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
5660

57-
- name: Autobuild
58-
uses: github/codeql-action/autobuild@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4
61+
# Use Autobuild for Python (it works fine for interpreted languages)
62+
- name: Autobuild (Python)
63+
if: matrix.language == 'python'
64+
uses: github/codeql-action/autobuild@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8
65+
66+
# Explicit build for Go - required for CodeQL to analyze compiled code
67+
- name: Build Go code
68+
if: matrix.language == 'go'
69+
run: |
70+
# Build all Go binaries to ensure CodeQL can analyze them
71+
go build -v ./...
5972
6073
- name: Perform CodeQL Analysis
61-
uses: github/codeql-action/analyze@f443b600d91635bebf5b0d9ebc620189c0d6fba5 # v4
74+
uses: github/codeql-action/analyze@1b168cd39490f61582a9beae412bb7057a6b2c4e # v4.31.8

0 commit comments

Comments
 (0)