From a54bdf2bf286eda9f845ed38039ec777731aa5c1 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 21 Nov 2026 19:17:02 +0000 Subject: [PATCH] .github/actions/go-cache: cache the cigocacher binary Building cigocacher took most of the ~15-27s "Set up cigocacher" step on every Windows job. Cache the binary in actions/cache, keyed on cmd/cigocacher, go.mod, and go.sum, and add a test that cigocacher has no other tailscale.com dependencies so that key stays complete. Updates tailscale/corp#34812 Updates tailscale/corp#28679 Change-Id: I2def6f28a045249b2e87331a1f42c621e161031f Signed-off-by: Brad Fitzpatrick --- .github/actions/go-cache/action.sh | 14 ++++++++++++-- .github/actions/go-cache/action.yml | 17 +++++++++++++++++ cmd/cigocacher/deps_test.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 cmd/cigocacher/deps_test.go diff --git a/.github/actions/go-cache/action.sh b/.github/actions/go-cache/action.sh index 5cfafe476..2cca33cf5 100755 --- a/.github/actions/go-cache/action.sh +++ b/.github/actions/go-cache/action.sh @@ -8,6 +8,7 @@ # Inputs: # URL: The cigocached server URL. # HOST: The cigocached server host to dial. +# BIN_DIR: Optional directory to find or build the cigocacher binary in. # Outputs: # success: Whether cigocacher was set up successfully. @@ -25,7 +26,16 @@ fi BIN_PATH="$(PATH="$PATH:$HOME/bin" command -v cigocacher || true)" if [ -z "${BIN_PATH}" ]; then - echo "cigocacher not found in PATH, attempting to build or fetch it" + EXE="" + if [ "${RUNNER_OS:-}" = "Windows" ]; then + EXE=".exe" + fi + BIN_PATH="${BIN_DIR:-${RUNNER_TEMP:-/tmp}}/cigocacher${EXE}" +fi +if [ -f "${BIN_PATH}" ]; then + echo "Using cigocacher at ${BIN_PATH}" +else + echo "cigocacher not found in PATH or cache, attempting to build or fetch it" GOPATH=$(command -v go || true) if [ -z "${GOPATH}" ]; then @@ -36,7 +46,7 @@ if [ -z "${BIN_PATH}" ]; then GOPATH="./tool/go" fi - BIN_PATH="${RUNNER_TEMP:-/tmp}/cigocacher$(${GOPATH} env GOEXE)" + mkdir -p "$(dirname "${BIN_PATH}")" if [ -d "cmd/cigocacher" ]; then echo "cmd/cigocacher found locally, building from local source" "${GOPATH}" build -o "${BIN_PATH}" ./cmd/cigocacher diff --git a/.github/actions/go-cache/action.yml b/.github/actions/go-cache/action.yml index 7f5a66de1..41b1e4e13 100644 --- a/.github/actions/go-cache/action.yml +++ b/.github/actions/go-cache/action.yml @@ -23,6 +23,22 @@ outputs: runs: using: composite steps: + # cigocacher has no tailscale.com dependencies outside cmd/cigocacher + # (see TestDeps), so its binary depends only on these files. + - name: Compute cigocacher cache key + id: key + if: inputs.cigocached-url != '' + shell: bash + working-directory: ${{ inputs.checkout-path }} + run: echo "key=cigocacher-$RUNNER_OS-$RUNNER_ARCH-$(cat cmd/cigocacher/*.go go.mod go.sum | sha256sum | cut -c1-32)" >> "$GITHUB_OUTPUT" + + - name: Restore cigocacher binary + if: inputs.cigocached-url != '' + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # zizmor: ignore[cache-poisoning] v5.0.4 + with: + path: ${{ runner.temp }}/cigocacher-bin + key: ${{ steps.key.outputs.key }} + - name: Setup cigocacher id: setup shell: bash @@ -30,6 +46,7 @@ runs: URL: ${{ inputs.cigocached-url }} HOST: ${{ inputs.cigocached-host }} CACHE_DIR: ${{ inputs.cache-dir }} + BIN_DIR: ${{ runner.temp }}/cigocacher-bin working-directory: ${{ inputs.checkout-path }} # https://github.com/orgs/community/discussions/25910 run: $GITHUB_ACTION_PATH/action.sh diff --git a/cmd/cigocacher/deps_test.go b/cmd/cigocacher/deps_test.go new file mode 100644 index 000000000..cf9e31329 --- /dev/null +++ b/cmd/cigocacher/deps_test.go @@ -0,0 +1,28 @@ +// Copyright (c) Tailscale Inc & contributors +// SPDX-License-Identifier: BSD-3-Clause + +package main + +import ( + "strings" + "testing" + + "tailscale.com/tstest/deptest" +) + +// TestDeps checks that cigocacher depends on no other tailscale.com +// packages. The .github/actions/go-cache action caches the cigocacher +// binary keyed on only cmd/cigocacher, go.mod, and go.sum. +func TestDeps(t *testing.T) { + for _, goos := range []string{"linux", "darwin", "windows"} { + deptest.DepChecker{ + GOOS: goos, + GOARCH: "amd64", + OnDep: func(dep string) { + if strings.HasPrefix(dep, "tailscale.com/") { + t.Errorf("GOOS=%s: unexpected dependency %q; update the cache key in .github/actions/go-cache/action.yml", goos, dep) + } + }, + }.Check(t) + } +}