Fixes #1443: per-language CodeQL targeting #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "CodeQL" | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| schedule: | |
| - cron: "0 6 * * 1" # Weekly on Monday at 06:00 UTC | |
| permissions: | |
| contents: read | |
| security-events: write | |
| jobs: | |
| changes: | |
| name: Detect changed paths | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| outputs: | |
| matrix: ${{ steps.build-matrix.outputs.matrix }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dorny/paths-filter@v3 | |
| id: filter | |
| if: github.event_name == 'pull_request' | |
| with: | |
| filters: | | |
| java: | |
| - 'java/**' | |
| js: | |
| - 'nodejs/**' | |
| - 'scripts/**' | |
| - 'test/harness/**' | |
| python: | |
| - 'python/**' | |
| go: | |
| - 'go/**' | |
| rust: | |
| - 'rust/**' | |
| csharp: | |
| - 'dotnet/**' | |
| actions: | |
| - '.github/workflows/**' | |
| - '.github/actions/**' | |
| - name: Build language matrix | |
| id: build-matrix | |
| run: | | |
| # On push/schedule, analyse ALL languages. | |
| # On pull_request, only those whose paths changed. | |
| if [[ "${{ github.event_name }}" != "pull_request" ]]; then | |
| matrix='{"include":[{"language":"java-kotlin"},{"language":"javascript-typescript"},{"language":"python"},{"language":"go"},{"language":"rust"},{"language":"csharp"},{"language":"actions"}]}' | |
| else | |
| entries=() | |
| [[ "${{ steps.filter.outputs.java }}" == "true" ]] && entries+=('{"language":"java-kotlin"}') | |
| [[ "${{ steps.filter.outputs.js }}" == "true" ]] && entries+=('{"language":"javascript-typescript"}') | |
| [[ "${{ steps.filter.outputs.python }}" == "true" ]] && entries+=('{"language":"python"}') | |
| [[ "${{ steps.filter.outputs.go }}" == "true" ]] && entries+=('{"language":"go"}') | |
| [[ "${{ steps.filter.outputs.rust }}" == "true" ]] && entries+=('{"language":"rust"}') | |
| [[ "${{ steps.filter.outputs.csharp }}" == "true" ]] && entries+=('{"language":"csharp"}') | |
| [[ "${{ steps.filter.outputs.actions }}" == "true" ]] && entries+=('{"language":"actions"}') | |
| if [[ ${#entries[@]} -eq 0 ]]; then | |
| matrix='{"include":[]}' | |
| else | |
| joined=$(IFS=,; echo "${entries[*]}") | |
| matrix="{\"include\":[${joined}]}" | |
| fi | |
| fi | |
| echo "matrix=${matrix}" >> "$GITHUB_OUTPUT" | |
| analyze: | |
| name: Analyze (${{ matrix.language }}) | |
| needs: changes | |
| if: ${{ fromJson(needs.changes.outputs.matrix).include[0] != null }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| security-events: write | |
| contents: read | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.changes.outputs.matrix) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Initialize CodeQL | |
| uses: github/codeql-action/init@v3 | |
| with: | |
| languages: ${{ matrix.language }} | |
| - name: Autobuild | |
| uses: github/codeql-action/autobuild@v3 | |
| - name: Perform CodeQL Analysis | |
| uses: github/codeql-action/analyze@v3 | |
| with: | |
| category: "/language:${{ matrix.language }}" |