mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-03 13:56:36 +09:00
.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 <bradfitz@tailscale.com>
This commit is contained in:
1 parent
a33097932f
commit
a54bdf2bf2
3 files changed
+57
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user