|
| 1 | +# CodeQL scans for security vulnerabilities and coding errors across all |
| 2 | +# languages in this repo. Results appear in the "Security" tab under |
| 3 | +# "Code scanning alerts" and are enforced by branch protection rules. |
| 4 | +name: "CodeQL" |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [ "main" ] |
| 9 | + pull_request: |
| 10 | + branches: [ "main" ] |
| 11 | + # Weekly scheduled scan catches newly disclosed vulnerabilities in |
| 12 | + # existing code, not just changes introduced by PRs. |
| 13 | + schedule: |
| 14 | + - cron: '38 11 * * 3' |
| 15 | + |
| 16 | +jobs: |
| 17 | + analyze: |
| 18 | + name: Analyze (${{ matrix.language }}) |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + # Required to upload SARIF results to the "Security" tab. |
| 22 | + security-events: write |
| 23 | + # Required to fetch internal or private CodeQL packs. |
| 24 | + packages: read |
| 25 | + # Only required for workflows in private repositories. |
| 26 | + actions: read |
| 27 | + contents: read |
| 28 | + |
| 29 | + strategy: |
| 30 | + fail-fast: false |
| 31 | + matrix: |
| 32 | + include: |
| 33 | + # GitHub Actions workflow linting — no build needed. |
| 34 | + - language: actions |
| 35 | + build-mode: none |
| 36 | + |
| 37 | + # Go uses "manual" build mode so we control exactly what gets |
| 38 | + # compiled. The default "autobuild" finds the Makefile and runs |
| 39 | + # the full CI pipeline (lint, test, snapshot release, etc.), |
| 40 | + # which is far more work than CodeQL needs. All it requires is |
| 41 | + # compiled Go source so it can build a type-resolved code graph |
| 42 | + # for analysis. |
| 43 | + - language: go |
| 44 | + build-mode: manual |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 49 | + |
| 50 | + with: |
| 51 | + persist-credentials: false |
| 52 | + |
| 53 | + # Pin the Go toolchain to whatever go.mod declares so CodeQL |
| 54 | + # analyzes with the same version the project actually uses. |
| 55 | + # Only runs for the Go matrix entry. |
| 56 | + - name: Setup Go |
| 57 | + if: matrix.language == 'go' |
| 58 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 59 | + with: |
| 60 | + go-version-file: go.mod |
| 61 | + |
| 62 | + - name: Initialize CodeQL |
| 63 | + uses: github/codeql-action/init@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1 |
| 64 | + with: |
| 65 | + languages: ${{ matrix.language }} |
| 66 | + build-mode: ${{ matrix.build-mode }} |
| 67 | + |
| 68 | + # Minimal build for Go. |
| 69 | + # This replaces autobuild, which would have run the entire Makefile |
| 70 | + # (installing tools, linting, testing, goreleaser snapshot, etc.). |
| 71 | + - name: Build (Go) |
| 72 | + if: matrix.build-mode == 'manual' |
| 73 | + shell: bash |
| 74 | + run: go build ./... |
| 75 | + |
| 76 | + - name: Perform CodeQL Analysis |
| 77 | + uses: github/codeql-action/analyze@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1 |
| 78 | + with: |
| 79 | + # The category tag lets GitHub associate SARIF results with the |
| 80 | + # correct language when branch protection checks for required |
| 81 | + # code scanning results. |
| 82 | + category: "/language:${{matrix.language}}" |
0 commit comments