|
8 | 8 | branches: [main, master] |
9 | 9 | schedule: |
10 | 10 | - cron: '0 6 * * 1' |
| 11 | +# Estate guardrail: cancel superseded runs so re-pushes don't pile up |
| 12 | +# queued runs across the estate. Safe here because this workflow only |
| 13 | +# performs read-only checks/lint/test/scan with no publish or mutation. |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
11 | 17 |
|
12 | 18 | permissions: |
13 | 19 | contents: read |
14 | 20 |
|
15 | 21 | jobs: |
| 22 | + # The estate is heterogeneous (Rust, Idris2, Agda, Elixir, ReScript, |
| 23 | + # occasional JS/TS/Python). A hard-coded `javascript-typescript` matrix |
| 24 | + # made CodeQL exit with a "no source / configuration error" on every |
| 25 | + # non-JS/TS repo — a permanent false-red `analyze` on most repos' main. |
| 26 | + # Detect the languages the repo ACTUALLY contains and only analyse the |
| 27 | + # CodeQL-supported, buildless-safe ones; skip entirely when none apply. |
| 28 | + detect: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + outputs: |
| 31 | + langs: ${{ steps.pick.outputs.langs }} |
| 32 | + steps: |
| 33 | + - name: Pick CodeQL languages from repo language stats |
| 34 | + id: pick |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ github.token }} |
| 37 | + run: | |
| 38 | + stats=$(gh api "repos/${{ github.repository }}/languages" --jq 'keys[]' 2>/dev/null || echo "") |
| 39 | + out="" |
| 40 | + add() { out="$out $1"; } |
| 41 | + echo "$stats" | grep -qix 'Rust' && add rust |
| 42 | + echo "$stats" | grep -qixE 'JavaScript|TypeScript' && add javascript-typescript |
| 43 | + echo "$stats" | grep -qix 'Python' && add python |
| 44 | + echo "$stats" | grep -qix 'Ruby' && add ruby |
| 45 | + echo "$stats" | grep -qix 'Go' && add go |
| 46 | + arr=$(printf '%s\n' $out | grep . | sort -u | jq -R . | jq -s -c .) |
| 47 | + [ -z "$arr" ] && arr='[]' |
| 48 | + echo "Detected CodeQL languages: $arr" |
| 49 | + echo "langs=$arr" >> "$GITHUB_OUTPUT" |
| 50 | +
|
16 | 51 | analyze: |
| 52 | + needs: detect |
| 53 | + if: needs.detect.outputs.langs != '[]' |
17 | 54 | runs-on: ubuntu-latest |
18 | 55 | permissions: |
19 | 56 | contents: read |
20 | 57 | security-events: write |
21 | 58 | strategy: |
22 | 59 | fail-fast: false |
23 | 60 | matrix: |
24 | | - include: |
25 | | - # verisimiser is a Rust crate with zero JS/TS source. The estate |
26 | | - # template's default `javascript-typescript` made CodeQL fail with |
27 | | - # a "no source / configuration error" on every run (pre-existing |
28 | | - # red on main, not introduced by #102). Analyse the language that |
29 | | - # actually exists. `build-mode: none` is the correct (buildless) |
30 | | - # extraction mode for Rust in CodeQL. |
31 | | - - language: rust |
32 | | - build-mode: none |
| 61 | + language: ${{ fromJSON(needs.detect.outputs.langs) }} |
33 | 62 |
|
34 | 63 | steps: |
35 | 64 | - name: Checkout |
|
39 | 68 | uses: github/codeql-action/init@0d579ffd059c29b07949a3cce3983f0780820c98 # v3.28.1 |
40 | 69 | with: |
41 | 70 | languages: ${{ matrix.language }} |
42 | | - build-mode: ${{ matrix.build-mode }} |
| 71 | + build-mode: none |
43 | 72 |
|
44 | 73 | - name: Perform CodeQL Analysis |
45 | 74 | uses: github/codeql-action/analyze@0d579ffd059c29b07949a3cce3983f0780820c98 # v3.28.1 |
|
0 commit comments