@@ -15,23 +15,18 @@ permissions:
1515jobs :
1616 changes :
1717 name : Detect changed paths
18- if : github.event_name == 'pull_request'
1918 runs-on : ubuntu-latest
2019 permissions :
2120 contents : read
2221 pull-requests : read
2322 outputs :
24- java : ${{ steps.filter.outputs.java }}
25- js : ${{ steps.filter.outputs.js }}
26- python : ${{ steps.filter.outputs.python }}
27- go : ${{ steps.filter.outputs.go }}
28- rust : ${{ steps.filter.outputs.rust }}
29- csharp : ${{ steps.filter.outputs.csharp }}
30- actions : ${{ steps.filter.outputs.actions }}
23+ matrix : ${{ steps.build-matrix.outputs.matrix }}
3124 steps :
3225 - uses : actions/checkout@v4
26+
3327 - uses : dorny/paths-filter@v3
3428 id : filter
29+ if : github.event_name == 'pull_request'
3530 with :
3631 filters : |
3732 java:
@@ -52,51 +47,56 @@ jobs:
5247 - '.github/workflows/**'
5348 - '.github/actions/**'
5449
50+ - name : Build language matrix
51+ id : build-matrix
52+ run : |
53+ # On push/schedule, analyse ALL languages.
54+ # On pull_request, only those whose paths changed.
55+ if [[ "${{ github.event_name }}" != "pull_request" ]]; then
56+ matrix='{"include":[{"language":"java-kotlin"},{"language":"javascript-typescript"},{"language":"python"},{"language":"go"},{"language":"rust"},{"language":"csharp"},{"language":"actions"}]}'
57+ else
58+ entries=()
59+ [[ "${{ steps.filter.outputs.java }}" == "true" ]] && entries+=('{"language":"java-kotlin"}')
60+ [[ "${{ steps.filter.outputs.js }}" == "true" ]] && entries+=('{"language":"javascript-typescript"}')
61+ [[ "${{ steps.filter.outputs.python }}" == "true" ]] && entries+=('{"language":"python"}')
62+ [[ "${{ steps.filter.outputs.go }}" == "true" ]] && entries+=('{"language":"go"}')
63+ [[ "${{ steps.filter.outputs.rust }}" == "true" ]] && entries+=('{"language":"rust"}')
64+ [[ "${{ steps.filter.outputs.csharp }}" == "true" ]] && entries+=('{"language":"csharp"}')
65+ [[ "${{ steps.filter.outputs.actions }}" == "true" ]] && entries+=('{"language":"actions"}')
66+
67+ if [[ ${#entries[@]} -eq 0 ]]; then
68+ matrix='{"include":[]}'
69+ else
70+ joined=$(IFS=,; echo "${entries[*]}")
71+ matrix="{\"include\":[${joined}]}"
72+ fi
73+ fi
74+ echo "matrix=${matrix}" >> "$GITHUB_OUTPUT"
75+
5576 analyze :
5677 name : Analyze (${{ matrix.language }})
5778 needs : changes
58- # Run even if 'changes' is skipped (e.g. on push/schedule where paths-filter
59- # may not flag changes). Each step has its own gate condition.
60- if : always()
79+ if : ${{ fromJson(needs.changes.outputs.matrix).include[0] != null }}
6180 runs-on : ubuntu-latest
6281 permissions :
6382 security-events : write
6483 contents : read
6584 strategy :
6685 fail-fast : false
67- matrix :
68- include :
69- - language : java-kotlin
70- gate : java
71- - language : javascript-typescript
72- gate : js
73- - language : python
74- gate : python
75- - language : go
76- gate : go
77- - language : rust
78- gate : rust
79- - language : csharp
80- gate : csharp
81- - language : actions
82- gate : actions
86+ matrix : ${{ fromJson(needs.changes.outputs.matrix) }}
8387 steps :
8488 - name : Checkout repository
85- if : ${{ needs.changes.outputs[matrix.gate] == 'true' || github.event_name == 'schedule' || github.event_name == 'push' }}
8689 uses : actions/checkout@v4
8790
8891 - name : Initialize CodeQL
89- if : ${{ needs.changes.outputs[matrix.gate] == 'true' || github.event_name == 'schedule' || github.event_name == 'push' }}
9092 uses : github/codeql-action/init@v3
9193 with :
9294 languages : ${{ matrix.language }}
9395
9496 - name : Autobuild
95- if : ${{ needs.changes.outputs[matrix.gate] == 'true' || github.event_name == 'schedule' || github.event_name == 'push' }}
9697 uses : github/codeql-action/autobuild@v3
9798
9899 - name : Perform CodeQL Analysis
99- if : ${{ needs.changes.outputs[matrix.gate] == 'true' || github.event_name == 'schedule' || github.event_name == 'push' }}
100100 uses : github/codeql-action/analyze@v3
101101 with :
102102 category : " /language:${{ matrix.language }}"
0 commit comments