name: Code Quality permissions: contents: read on: merge_group: push: branches: [main] pull_request: branches: [main] # Superseded PR pushes cancel their older run. Every main push gets its own # group (run_id), so no main commit's run is ever cancelled or dropped as pending. concurrency: group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.run_id }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: # Sorts the change by the files it touches (tools/ci/change_class.py, #639): "inert" (nothing reads # them), "docs" (a Python test reads them) or "code" (anything else, and every case of doubt). The # jobs below skip what the class cannot affect. A job skipped by its condition reports Success, so # the required context still reports. This workflow has no gate job, so the scan runs whenever the # class is not "docs" or "inert": a classifier that fails or prints nothing means a full scan. The clone has every commit but no file contents (blob:none): the # script only compares file names between the base and the head. changes: name: change class runs-on: ubuntu-latest timeout-minutes: 5 outputs: class: ${{ steps.classify.outputs.class }} steps: - uses: actions/checkout@v7 with: fetch-depth: 0 filter: blob:none persist-credentials: false - name: Classify the changed files id: classify env: EVENT_NAME: ${{ github.event_name }} BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.before }} HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha || github.sha }} run: python3 tools/ci/change_class.py | tee -a "$GITHUB_OUTPUT" security: name: bandit (high severity) needs: changes if: ${{ !cancelled() && needs.changes.outputs.class != 'docs' && needs.changes.outputs.class != 'inert' }} runs-on: ubuntu-latest # ceil(1.5 x slowest of three green main runs) + 3, never under 5 (test.yml): runs 40257217665, # 40254137380, 40240706583 took 23s / 16s / 23s -> 5 min. change class (#639): 5 min, the floor. timeout-minutes: 5 steps: - uses: actions/checkout@v7 - name: Set up Python 3.12 uses: actions/setup-python@v7 with: python-version: "3.12" - name: Install bandit run: pip install bandit[toml] # Medium findings are reported without failing until they are triaged. # High severity is a hard gate. - name: Security report (medium and above, informational) run: bandit -r . -ll -q --exclude ./tests,./reference,./venv,./tools/vendor/node_modules --exit-zero - name: Security scan (high severity gate) run: bandit -r . -lll -q --exclude ./tests,./reference,./venv,./tools/vendor/node_modules