.github/workflows: give golangci-lint its own Go build cache

The golangci-lint job's setup-go cache key collided with the CodeQL
workflow's, so PRs restored CodeQL's main-branch build cache, which
lacks the test packages and export data golangci-lint loads. Package
loading thus ran nearly cold every time (~9 of ~10 minutes), and jobs
now regularly hit the 10m timeout. Use a dedicated cache key, and run
on pushes to main so there's a cache for PRs to restore.

Updates #18366
Updates tailscale/corp#28679

Change-Id: I7a23a66dc7198c030d6a378aa2733d558c8c37d9
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Signed-off-by: Guy J Grigsby <guy@tailscale.com>
This commit is contained in:
Brad Fitzpatrick authored and Guy J Grigsby committed 2026-12-03 16:59:49 -07:00
1 parent ac87e868a2
commit 4f4f99dcca
1 file changed
+36 -7
+36 -7
View File
@@ -1,16 +1,20 @@
name: golangci-lint
on:
# For now, only lint pull requests, not the main branches.
pull_request:
paths:
- ".github/workflows/golangci-lint.yml"
- "**.go"
- "go.mod"
- "go.sum"
# TODO(andrew): enable for main branch after an initial waiting period.
#push:
# branches:
# - main
# Runs on main populate the Go build cache that pull requests restore.
push:
branches:
- main
paths:
- ".github/workflows/golangci-lint.yml"
- "**.go"
- "go.mod"
- "go.sum"
workflow_dispatch:
@@ -29,10 +33,25 @@ jobs:
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# setup-go's own cache is disabled because its key collides with the
# one used by the CodeQL workflow, whose saved build cache lacks the
# test packages and export data that golangci-lint needs. We manage
# our own cache below instead.
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version-file: go.mod
cache: true
cache: false
- name: Restore Go cache
id: restore-cache
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golangci-lint-${{ hashFiles('go.mod', 'go.sum') }}
restore-keys: |
${{ runner.os }}-golangci-lint-
- name: golangci-lint
uses: golangci/golangci-lint-action@b7bcab6379029e905e3f389a6bf301f1bc220662 # head as of 2026-03-04
@@ -44,4 +63,14 @@ jobs:
# Loading packages with a cold cache takes a while:
args: --timeout=10m
- name: Save Go cache
# Save even on lint failure, but only on main and only once per
# go.mod/go.sum hash, as each entry is several GB.
if: always() && steps.restore-cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/main'
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golangci-lint-${{ hashFiles('go.mod', 'go.sum') }}