|
| 1 | +name: CodeQL |
| 2 | + |
| 3 | +# ============================================================================= |
| 4 | +# CodeQL — ADVANCED setup. |
| 5 | +# |
| 6 | +# WHY THIS FILE EXISTS AT ALL. Until now CodeQL ran through GitHub's |
| 7 | +# code-scanning DEFAULT setup: no workflow in the repo, and a single check |
| 8 | +# named `CodeQL` posted by the `github-advanced-security` App (integration id |
| 9 | +# 57789). That check has one disqualifying property — it does not report on |
| 10 | +# `merge_group` refs (github/codeql-action#1537, open since 2023). A merge |
| 11 | +# queue therefore waits forever on a required `CodeQL` context that will never |
| 12 | +# arrive, and the pull request looks queued rather than broken until it is |
| 13 | +# evicted. Advanced setup runs CodeQL as an ordinary Actions workflow, so its |
| 14 | +# checks are posted by `github-actions` (integration id 15368) and DO run on |
| 15 | +# merge groups. Same analysis, same alerts, a check the queue can see. |
| 16 | +# |
| 17 | +# THE JOB NAME IS A LOAD-BEARING STRING. Each matrix job publishes a check run |
| 18 | +# named after the job — `Analyze (actions)`, `Analyze (javascript-typescript)` |
| 19 | +# — and those exact names are what the `byo-full-public` ruleset requires on |
| 20 | +# `main` (recorded in de-otio/dot-work `inventory/repo-register.json` under |
| 21 | +# trellis's `extra_required_checks`, which is what asserts they have not |
| 22 | +# drifted). Renaming the job, or adding/removing a language, CHANGES THE CHECK |
| 23 | +# NAMES: a removed name is a required context nothing will ever report and |
| 24 | +# every pull request hangs with no error anywhere. Change this matrix and the |
| 25 | +# ruleset + register in the same change, never one without the other. |
| 26 | +# |
| 27 | +# NO `paths:` FILTER, DELIBERATELY. Same rule as ci.yml: a skipped JOB |
| 28 | +# satisfies a required check, a skipped WORKFLOW reports nothing at all. For as |
| 29 | +# long as these are required contexts this workflow must fire on every pull |
| 30 | +# request to `main`. |
| 31 | +# |
| 32 | +# LANGUAGES AND SUITE reproduce what default setup was configured with, read |
| 33 | +# live from `GET /repos/de-otio/trellis/code-scanning/default-setup` before the |
| 34 | +# switch: languages `actions`, `javascript`, `javascript-typescript`, |
| 35 | +# `typescript` (the last three are aliases of the one `javascript-typescript` |
| 36 | +# extractor), query suite `default`, threat model `remote`. `queries:` is |
| 37 | +# therefore deliberately unset — setting it would change the suite — and the |
| 38 | +# weekly `schedule:` below reproduces default setup's weekly full scan. |
| 39 | +# ============================================================================= |
| 40 | + |
| 41 | +on: |
| 42 | + push: |
| 43 | + branches: [main] |
| 44 | + pull_request: |
| 45 | + branches: [main] |
| 46 | + # See ci.yml: the merge queue validates a speculative merge on a |
| 47 | + # `refs/heads/gh-readonly-queue/main/...` ref. Without this trigger the |
| 48 | + # workflow never fires there and the required contexts never arrive. |
| 49 | + merge_group: |
| 50 | + schedule: |
| 51 | + # Weekly full scan, matching what default setup ran. Catches newly |
| 52 | + # published queries against code that has not changed. |
| 53 | + - cron: "27 4 * * 1" |
| 54 | + workflow_dispatch: |
| 55 | + |
| 56 | +permissions: |
| 57 | + contents: read |
| 58 | + |
| 59 | +concurrency: |
| 60 | + group: codeql-${{ github.ref }} |
| 61 | + # A cancelled merge-queue run reports no result, which the queue reads the |
| 62 | + # same way as a failure — so merge_group is never cancel-eligible, alongside |
| 63 | + # main. Identical reasoning to ci.yml. |
| 64 | + cancel-in-progress: ${{ github.event_name != 'merge_group' && github.ref != 'refs/heads/main' }} |
| 65 | + |
| 66 | +jobs: |
| 67 | + analyze: |
| 68 | + name: Analyze (${{ matrix.language }}) |
| 69 | + runs-on: ubuntu-latest |
| 70 | + timeout-minutes: 30 |
| 71 | + |
| 72 | + permissions: |
| 73 | + # Least privilege, per language job: read the tree, read workflow run |
| 74 | + # metadata (the action queries it), write the SARIF back as code-scanning |
| 75 | + # alerts. Nothing else. |
| 76 | + contents: read |
| 77 | + actions: read |
| 78 | + security-events: write |
| 79 | + |
| 80 | + strategy: |
| 81 | + fail-fast: false |
| 82 | + matrix: |
| 83 | + include: |
| 84 | + - language: actions |
| 85 | + build-mode: none |
| 86 | + - language: javascript-typescript |
| 87 | + build-mode: none |
| 88 | + |
| 89 | + steps: |
| 90 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 91 | + |
| 92 | + - name: Initialize CodeQL |
| 93 | + uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9 |
| 94 | + with: |
| 95 | + languages: ${{ matrix.language }} |
| 96 | + build-mode: ${{ matrix.build-mode }} |
| 97 | + |
| 98 | + - name: Perform CodeQL analysis |
| 99 | + uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9 |
| 100 | + with: |
| 101 | + category: "/language:${{ matrix.language }}" |
0 commit comments