Skip to content

Commit 7d586fd

Browse files
committed
feat: enhance CodeQL workflow to trigger on specific file changes for multiple languages
1 parent 3ab29e2 commit 7d586fd

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

.github/workflows/codeql.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,63 @@ on: # zizmor: ignore[cache-poisoning]
1616
permissions: {} # No permissions by default on workflow level
1717

1818
jobs:
19+
check_paths:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
modified_keys: ${{ steps.changed-files-yaml.outputs.modified_keys }}
23+
steps:
24+
- name: Get all paths that should trigger the workflow
25+
id: changed-files-yaml
26+
if: ${{ github.event_name == 'pull_request' }}
27+
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46.0.5
28+
with:
29+
files_yaml: |
30+
python:
31+
- libs/**
32+
- platform/**
33+
- docker/**
34+
- interactive_ai/**
35+
javascript-typescript:
36+
- web_ui/**
37+
actions:
38+
- .github/workflows/**
39+
go:
40+
- libs/**
41+
- interactive_ai/**
42+
- platform/**
43+
1944
analyze:
2045
name: Analyze (${{ matrix.language }})
2146
runs-on: ubuntu-latest
2247
permissions:
2348
security-events: write # required to publish sarif
24-
49+
needs: check_paths
2550
strategy:
2651
fail-fast: false
2752
matrix:
2853
include:
2954
- language: actions
3055
build-mode: none
56+
run: ${{ contains(needs.check_paths.outputs.modified_keys, 'actions') || github.event_name != 'pull_request' }}
3157
- language: javascript-typescript
3258
build-mode: none
59+
run: ${{ contains(needs.check_paths.outputs.modified_keys, 'javascript-typescript') || github.event_name != 'pull_request' }}
3360
- language: python
3461
build-mode: none
62+
run: ${{ contains(needs.check_paths.outputs.modified_keys, 'python') || github.event_name != 'pull_request' }}
3563
- language: go
3664
build-mode: autobuild
65+
run: ${{ contains(needs.check_paths.outputs.modified_keys, 'go') || github.event_name != 'pull_request' }}
3766

3867
steps:
3968
- name: Harden the runner (audit all outbound calls)
4069
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
70+
if: ${{ matrix.run == true }}
4171
with:
4272
egress-policy: audit
4373

4474
- name: Free space on runner (delete unnecessary tools)
75+
if: ${{ matrix.run == true }}
4576
shell: bash
4677
run: |
4778
echo "Free space before deletion:"
@@ -56,23 +87,27 @@ jobs:
5687
5788
- name: Checkout repository
5889
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
90+
if: ${{ matrix.run == true }}
5991
with:
6092
persist-credentials: false
6193

6294
- name: Setup GO
6395
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
96+
if: ${{ matrix.run == true && matrix.language == 'go' }}
6497
with:
6598
go-version: "1.23"
6699

67100
# Initializes the CodeQL tools for scanning.
68101
- name: Initialize CodeQL
69102
uses: github/codeql-action/init@f1f6e5f6af878fb37288ce1c627459e94dbf7d01 # v3.30.1
103+
if: ${{ matrix.run == true }}
70104
with:
71105
languages: ${{ matrix.language }}
72106
build-mode: ${{ matrix.build-mode }}
73107
queries: security-extended
74108

75109
- name: Perform CodeQL Analysis
76110
uses: github/codeql-action/analyze@f1f6e5f6af878fb37288ce1c627459e94dbf7d01 # v3.30.1
111+
if: ${{ matrix.run == true }}
77112
with:
78113
category: "/language:${{matrix.language}}"

0 commit comments

Comments
 (0)