Files
cozystack/.github/workflows/codeql.yml
Myasnikov DaniilandClaude Opus 4.8 71dd0516ef ci(codeql): build Go with manual mode instead of autobuild
CodeQL's Go autobuild runs `make` from the repo root, whose included
hack/common-envs.mk does a `$(shell git fetch upstream --tags)` at parse
time — a network call to a non-origin remote that has nothing to do with the
analysis and is a flake vector. Switch to build-mode: manual and compile each
first-party module explicitly (the root module, api/apps/v1alpha1, and the
three nested image modules); the _repos/* upstream clones are gitignored and
absent on a clean checkout, so they drop out for free. Same coverage, no
upstream fetch.

Keeping the pull_request trigger is deliberate. Per-PR analysis is the only
mode that diffs newly introduced alerts against the base branch and annotates
them on the changed lines — the basis for promoting CodeQL to a required
pre-merge check. No paths filter: a required check that is path-skipped is
reported as never-arriving and would block PRs that touch no Go.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
2026-06-26 18:11:06 +05:00

96 lines
3.4 KiB
YAML

name: CodeQL
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
# Weekly on Monday 03:27 UTC — off-peak and offset from the other
# scheduled jobs (scorecard 06:00 Mon, labels 04:17 Mon, stale 04:37
# daily).
- cron: '27 3 * * 1'
# Default to read-only; the analyze job opts into security-events: write.
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
# Upload CodeQL results to the code-scanning dashboard. On pull_request
# this is also what lets CodeQL post new-alert annotations on the diff.
security-events: write
# Check out the repository.
contents: read
# Read workflow run metadata (required by codeql-action on private
# repos; harmless on a public repo).
actions: read
strategy:
fail-fast: false
matrix:
include:
# Go uses build-mode: manual. The alternative, autobuild, runs `make`
# from the repo root, whose included hack/common-envs.mk does a
# `$(shell git fetch upstream --tags)` at parse time — a network call
# to a non-origin remote that has no bearing on the analysis and is a
# flake vector. Instead the "Build Go modules" step below compiles
# each first-party module explicitly. This keeps the same coverage
# autobuild aimed for — the root module, api/apps/v1alpha1, and the
# three nested image modules — while the _repos/* upstream clones are
# gitignored and absent on a clean checkout, so they are excluded for
# free. setup-go pins the toolchain to the root go.mod version.
- language: go
build-mode: manual
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version-file: go.mod
cache: false
- name: Initialize CodeQL
uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# CodeQL traces these compiler invocations to build its database. Each
# first-party module is a separate go.mod, so `go build ./...` from the
# root never reaches the nested ones — build each explicitly. No `make`,
# so no upstream fetch.
- name: Build Go modules
if: matrix.build-mode == 'manual'
shell: bash
run: |
set -euxo pipefail
for mod in \
. \
api/apps/v1alpha1 \
packages/apps/kubernetes/images/kubevirt-csi-driver \
packages/system/dashboard/images/token-proxy \
packages/system/kubeovn-webhook/images/kubeovn-webhook; do
echo "::group::go build ${mod}"
( cd "${mod}" && go build ./... )
echo "::endgroup::"
done
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
with:
category: "/language:${{ matrix.language }}"