|
| 1 | +name: CodeQL |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: ["main"] |
| 7 | + pull_request: |
| 8 | + # The branches below must be a subset of the branches above |
| 9 | + branches: ["main"] |
| 10 | + schedule: |
| 11 | + - cron: "16 7 * * 5" |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: codeql-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +permissions: read-all |
| 18 | + |
| 19 | +jobs: |
| 20 | + analyze: |
| 21 | + name: Analyze (${{ matrix.language }}) |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + actions: read |
| 25 | + contents: read |
| 26 | + security-events: write |
| 27 | + strategy: |
| 28 | + fail-fast: false |
| 29 | + matrix: |
| 30 | + include: |
| 31 | + - language: actions |
| 32 | + build-mode: none |
| 33 | + queries: security-extended # can be 'default' (use empty for 'default'), 'security-and-quality', 'security-extended' |
| 34 | + - language: go |
| 35 | + build-mode: manual |
| 36 | + queries: "" # will be used 'default' queries |
| 37 | + defaults: |
| 38 | + run: |
| 39 | + shell: bash |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 43 | + |
| 44 | + - name: Set-up Go |
| 45 | + uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 46 | + if: matrix.language == 'go' |
| 47 | + with: |
| 48 | + go-version-file: go.mod |
| 49 | + cache: true |
| 50 | + |
| 51 | + - name: Initialize CodeQL |
| 52 | + uses: github/codeql-action/init@fdbfb4d2750291e159f0156def62b853c2798ca2 # v4.31.5 |
| 53 | + with: |
| 54 | + languages: ${{ matrix.language }} |
| 55 | + build-mode: ${{ matrix.build-mode }} |
| 56 | + queries: ${{ matrix.queries }} |
| 57 | + |
| 58 | + - name: Build Go |
| 59 | + if: ${{ matrix.language == 'go' }} |
| 60 | + run: go build ./... |
| 61 | + |
| 62 | + - name: Perform CodeQL Analysis |
| 63 | + uses: github/codeql-action/analyze@fdbfb4d2750291e159f0156def62b853c2798ca2 # v4.31.5 |
| 64 | + with: |
| 65 | + category: "/language:${{matrix.language}}" |
| 66 | + |
| 67 | + check: |
| 68 | + name: Check CodeQL Analysis |
| 69 | + if: always() && github.event_name == 'pull_request' |
| 70 | + needs: |
| 71 | + - analyze |
| 72 | + runs-on: ubuntu-latest |
| 73 | + defaults: |
| 74 | + run: |
| 75 | + shell: bash |
| 76 | + steps: |
| 77 | + - name: Check |
| 78 | + env: |
| 79 | + INPUT_RESULTS: ${{ join(needs.*.result, ' ') }} |
| 80 | + run: | |
| 81 | + set -euo pipefail |
| 82 | + read -a results <<< "${INPUT_RESULTS}" |
| 83 | + for result in "${results[@]}"; do |
| 84 | + if [[ "${result}" == "failure" ]] || [[ "${result}" == "cancelled" ]]; then |
| 85 | + echo "::error::Workflow failed!" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | + done |
0 commit comments