grafana/.github/workflows/codeql-analysis.yml

98 lines
3.5 KiB
YAML

# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL checks"
on:
workflow_dispatch:
push:
branches: ['**'] # run on all branches
paths-ignore:
- '**/*.cue'
- '**/*.json'
- '**/*.md'
- '**/*.txt'
- '**/*.yml'
- pkg/storage/unified/sql/db/dbimpl/db.go # Ignoring warnings on the whole file for now while inline comments is not supported in Go (https://github.com/github/codeql/issues/11427)
schedule:
- cron: '0 4 * * 6'
permissions:
security-events: write
jobs:
detect-changes:
name: Detect whether code changed
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
javascript: ${{ steps.detect-changes.outputs.frontend }}
go: ${{ steps.detect-changes.outputs.backend }}
actions: 'true'
steps:
- uses: actions/checkout@v5
with:
persist-credentials: true # required to get more history in the changed-files action
fetch-depth: 2
- name: Detect changes
id: detect-changes
uses: ./.github/actions/change-detection
with:
self: .github/workflows/codeql-analysis.yml
analyze:
needs: detect-changes
name: Analyze
runs-on: ubuntu-latest
continue-on-error: true # doesn't block PRs from being merged if this fails
if: github.repository == 'grafana/grafana'
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are listed here
# https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning#changing-the-languages-that-are-analyzed
language: ['actions', 'javascript', 'go']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
steps:
- name: Checkout repository
if: needs.detect-changes.outputs[matrix.language] == 'true'
uses: actions/checkout@v5
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
persist-credentials: false
- if: matrix.language == 'go' && needs.detect-changes.outputs.go == 'true'
name: Set go version
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5
with:
go-version-file: go.mod
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
if: needs.detect-changes.outputs[matrix.language] == 'true'
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
- if: matrix.language == 'go' && needs.detect-changes.outputs.go == 'true'
name: Build go files
run: |
go mod verify
make build-go
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3