Skip to content

Commit 2fbb8b0

Browse files
committed
fix(ci): Fix CodeQL workflow to properly analyze Go code
- Change condition from '== pull_request' to '!= merge_group' This enables scans on push/schedule while avoiding duplicate runs - Replace Autobuild with explicit 'go build ./...' for Go language - Add setup-go action to ensure Go is properly configured - Add submodules: true to checkout for complete codebase - Keep Autobuild for Python as it works for interpreted languages - Update action versions to match repository conventions: - harden-runner: v2.14.0 - checkout: v6.0.0 - setup-go: v6.2.0 - codeql-action: v4.31.8 Fixes: Go files were found but not processed Fixes: Code Scanning results may be out of date Refs: github/codeql-action#1537 Signed-off-by: Jonah Kowall <[email protected]>
1 parent ceaa39d commit 2fbb8b0

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: stable
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)