mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-03 23:22:23 -08:00
cmd/tsvet: replace cmd/vet, staticcheck, golangci-lint, and checklocks
We ran overlapping checks in four tools at different versions: golangci-lint only reported problems on changed lines, vet only ran for linux, and staticcheck took seven CI jobs, each compiling the tree from scratch. cmd/tsvet now runs the go vet suite, staticcheck, checklocks, and our own analyzers as a single vettool, for linux, windows, and darwin, plus a goimports check of all Go files. Small analyzers replace the golangci-lint and revive checks that nothing else covered, and lint:ignore directives work for every check. CI runs it with the next toolchain (tailscale.go1.28), whose go vet type checks dependencies instead of compiling them. Pushes to main save one cache that per-GOOS PR jobs restore, and go test no longer runs its own vet in jobs that tsvet covers. Over the past 30 days, these checks cost about 43 runner-minutes per PR (29 of them staticcheck's). On a 4-core machine, tsvet checks the whole tree for all three GOOS values in 3m27s from an empty cache and 10s when nothing changed. Its cache for all three is 1.3 GB (176 MB compressed), versus 5 GB for just linux when vet compiles with Go 1.27. Dropping golangci-lint also removes 161 lines from go.mod. Fixes #22645 Fixes #22653 Signed-off-by: Brad Fitzpatrick <[email protected]> Change-Id: Idf8779d8d3e1f5e87a8a431a53949db9c143d236
This commit is contained in:
1 parent
08caf267a0
commit
b21f560533
47 files changed
+1311
-962
No files matched your search
@@ -1,34 +0,0 @@
|
||||
name: checklocks
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
paths:
|
||||
- '**/*.go'
|
||||
- '.github/workflows/checklocks.yml'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
checklocks:
|
||||
runs-on: [ ubuntu-latest ]
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
|
||||
- name: Build checklocks
|
||||
run: ./tool/go build -o /tmp/checklocks gvisor.dev/gvisor/tools/checklocks/cmd/checklocks
|
||||
|
||||
- name: Run checklocks vet
|
||||
# TODO(#12625): add more packages as we add annotations
|
||||
run: |-
|
||||
./tool/go vet -vettool=/tmp/checklocks \
|
||||
./envknob \
|
||||
./ipn/store/mem \
|
||||
./net/stun/stuntest \
|
||||
./net/wsconn \
|
||||
./proxymap
|
||||
@@ -1,76 +0,0 @@
|
||||
name: golangci-lint
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- ".github/workflows/golangci-lint.yml"
|
||||
- "**.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
# 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:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
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: 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
|
||||
with:
|
||||
version: v2.14.0
|
||||
|
||||
# Show only new issues if it's a pull request.
|
||||
only-new-issues: true
|
||||
|
||||
# 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') }}
|
||||
+43
-42
@@ -69,6 +69,8 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 30
|
||||
needs: gomod-cache
|
||||
env:
|
||||
GOFLAGS: -vet=off # the tsvet job does vetting
|
||||
strategy:
|
||||
fail-fast: false # don't abort the entire matrix if one element fails
|
||||
matrix:
|
||||
@@ -116,6 +118,8 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 60
|
||||
needs: gomod-cache
|
||||
env:
|
||||
GOFLAGS: -vet=off # the tsvet job does vetting
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
@@ -219,6 +223,8 @@ jobs:
|
||||
runs-on: ci-windows-github-1
|
||||
timeout-minutes: 60
|
||||
name: Windows (${{ matrix.name || matrix.shard}})
|
||||
env:
|
||||
GOFLAGS: -vet=off # the tsvet job does vetting
|
||||
strategy:
|
||||
fail-fast: false # don't abort the entire matrix if one element fails
|
||||
matrix:
|
||||
@@ -299,6 +305,8 @@ jobs:
|
||||
runs-on: macos-latest
|
||||
timeout-minutes: 30
|
||||
needs: gomod-cache
|
||||
env:
|
||||
GOFLAGS: -vet=off # the tsvet job does vetting
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
@@ -357,6 +365,8 @@ jobs:
|
||||
needs: gomod-cache
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 20
|
||||
env:
|
||||
GOFLAGS: -vet=off # the tsvet job does vetting
|
||||
container:
|
||||
image: golang:latest # zizmor: ignore[unpinned-images]
|
||||
options: --privileged
|
||||
@@ -778,44 +788,20 @@ jobs:
|
||||
grep -q TestLicenseHeaders *.go || (echo "Expected a test named TestLicenseHeaders"; exit 1)
|
||||
./tool/go test -v -run=TestLicenseHeaders
|
||||
|
||||
staticcheck:
|
||||
tsvet:
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 30
|
||||
needs: gomod-cache
|
||||
name: staticcheck (${{ matrix.name }})
|
||||
name: tsvet (${{ matrix.goos }})
|
||||
strategy:
|
||||
fail-fast: false # don't abort the entire matrix if one element fails
|
||||
matrix:
|
||||
include:
|
||||
- name: "macOS"
|
||||
goos: "darwin"
|
||||
goarch: "arm64"
|
||||
flags: "--with-tags-all=darwin"
|
||||
- name: "Windows"
|
||||
goos: "windows"
|
||||
goarch: "amd64"
|
||||
flags: "--with-tags-all=windows"
|
||||
- name: "Linux"
|
||||
goos: "linux"
|
||||
goarch: "amd64"
|
||||
flags: "--with-tags-all=linux"
|
||||
- name: "Portable (1/4)"
|
||||
goos: "linux"
|
||||
goarch: "amd64"
|
||||
flags: "--without-tags-any=windows,darwin,linux --shard=1/4"
|
||||
- name: "Portable (2/4)"
|
||||
goos: "linux"
|
||||
goarch: "amd64"
|
||||
flags: "--without-tags-any=windows,darwin,linux --shard=2/4"
|
||||
- name: "Portable (3/4)"
|
||||
goos: "linux"
|
||||
goarch: "amd64"
|
||||
flags: "--without-tags-any=windows,darwin,linux --shard=3/4"
|
||||
- name: "Portable (4/4)"
|
||||
goos: "linux"
|
||||
goarch: "amd64"
|
||||
flags: "--without-tags-any=windows,darwin,linux --shard=4/4"
|
||||
|
||||
# Pushes check all platforms in one job, so that main saves one
|
||||
# cache. PRs check each platform concurrently, all restoring it.
|
||||
goos: ${{ fromJSON(github.event_name == 'push' && '["linux,windows,darwin"]' || '["linux","windows","darwin"]') }}
|
||||
env:
|
||||
# The next toolchain (Go 1.28) vets without compiling dependencies.
|
||||
TS_GO_NEXT: "1"
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
@@ -827,14 +813,29 @@ jobs:
|
||||
path: gomodcache
|
||||
key: ${{ needs.gomod-cache.outputs.cache-key }}
|
||||
enableCrossOsArchive: true
|
||||
- name: run staticcheck (${{ matrix.name }})
|
||||
- name: Restore build cache
|
||||
id: restore-cache
|
||||
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
|
||||
with:
|
||||
path: ~/.cache/go-build
|
||||
key: tsvet-${{ hashFiles('src/go.toolchain.next.rev', 'src/go.sum') }}-${{ github.run_id }}
|
||||
restore-keys: |
|
||||
tsvet-${{ hashFiles('src/go.toolchain.next.rev', 'src/go.sum') }}-
|
||||
tsvet-
|
||||
- name: tsvet
|
||||
working-directory: src
|
||||
run: |
|
||||
export GOROOT=$(./tool/go env GOROOT)
|
||||
./tool/go run -exec \
|
||||
"env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }}" \
|
||||
honnef.co/go/tools/cmd/staticcheck -- \
|
||||
$(./tool/go run ./tool/listpkgs --ignore-3p --goos=${{ matrix.goos }} --goarch=${{ matrix.goarch }} ${{ matrix.flags }} ./...)
|
||||
run: ./tool/go run ./cmd/tsvet --goos=${{ matrix.goos }}
|
||||
- name: Tidy build cache
|
||||
if: always() && github.ref == 'refs/heads/main'
|
||||
working-directory: src
|
||||
run: find $(./tool/go env GOCACHE) -type f -mmin +90 -delete
|
||||
- name: Save build cache
|
||||
# Save even on failure, but only on main; PRs only restore.
|
||||
if: always() && github.ref == 'refs/heads/main'
|
||||
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
|
||||
with:
|
||||
path: ~/.cache/go-build
|
||||
key: tsvet-${{ hashFiles('src/go.toolchain.next.rev', 'src/go.sum') }}-${{ github.run_id }}
|
||||
|
||||
notify_slack:
|
||||
if: always()
|
||||
@@ -852,7 +853,7 @@ jobs:
|
||||
- go_generate
|
||||
- make_tidy
|
||||
- licenses
|
||||
- staticcheck
|
||||
- tsvet
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
@@ -937,7 +938,7 @@ jobs:
|
||||
- go_generate
|
||||
- make_tidy
|
||||
- licenses
|
||||
- staticcheck
|
||||
- tsvet
|
||||
steps:
|
||||
- name: Decide if change is okay to merge
|
||||
if: github.event_name != 'push'
|
||||
@@ -962,7 +963,7 @@ jobs:
|
||||
- go_generate
|
||||
- make_tidy
|
||||
- licenses
|
||||
- staticcheck
|
||||
- tsvet
|
||||
steps:
|
||||
- name: Decide if change is okay to merge
|
||||
if: github.event_name != 'push'
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
name: tailscale.com/cmd/vet
|
||||
|
||||
env:
|
||||
HOME: ${{ github.workspace }}
|
||||
# GOMODCACHE is the same definition on all OSes. Within the workspace, we use
|
||||
# toplevel directories "src" (for the checked out source code), and "gomodcache"
|
||||
# and other caches as siblings to follow.
|
||||
GOMODCACHE: ${{ github.workspace }}/gomodcache
|
||||
CMD_GO_USE_GIT_HASH: "true"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- "release-branch/*"
|
||||
paths:
|
||||
- .github/workflows/vet.yml
|
||||
- "**.go"
|
||||
pull_request:
|
||||
paths:
|
||||
- .github/workflows/vet.yml
|
||||
- "**.go"
|
||||
|
||||
jobs:
|
||||
vet:
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 10
|
||||
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
path: src
|
||||
|
||||
- name: Build 'go vet' tool
|
||||
working-directory: src
|
||||
run: ./tool/go build -o /tmp/vettool tailscale.com/cmd/vet
|
||||
|
||||
- name: Run 'go vet'
|
||||
working-directory: src
|
||||
# Use listpkgs --ignore-3p to skip tempfork/ packages, which
|
||||
# intentionally match upstream and may not follow our style rules.
|
||||
# Must use ./... instead of tailscale.com/... because the latter will
|
||||
# include the v2 go client (tailscale.com/client/tailscale/v2) if it's
|
||||
# a dependency in our go.mod file. Possibly a go vet bug, but avoid
|
||||
# cross-repo vetting for now so we can safely add the dependency.
|
||||
run: ./tool/go vet -vettool=/tmp/vettool $(./tool/go run ./tool/listpkgs --ignore-3p ./...)
|
||||
Reference in new issue
Block a user