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: 5

    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 ./...)
