diff --git a/.github/workflows/flake-go.yaml b/.github/workflows/flake-go.yaml index be9b000556..117efe4a8d 100644 --- a/.github/workflows/flake-go.yaml +++ b/.github/workflows/flake-go.yaml @@ -70,6 +70,21 @@ jobs: with: install-args: "terraform" + # Exports EMBEDDED_PG_CACHE_DIR, which startBuiltinPostgres uses as a + # shared binary archive cache in tests. + - name: Setup Embedded Postgres Cache Paths + id: embedded-pg-cache + if: ${{ fromJSON(steps.selector.outputs.matrix).include[0] != null }} + uses: ./.github/actions/setup-embedded-pg-cache-paths + + - name: Download Embedded Postgres Cache + id: download-embedded-pg-cache + if: ${{ fromJSON(steps.selector.outputs.matrix).include[0] != null }} + uses: ./.github/actions/embedded-pg-cache/download + with: + key-prefix: embedded-pg-${{ runner.os }}-${{ runner.arch }} + cache-path: ${{ steps.embedded-pg-cache.outputs.cached-dirs }} + - name: Run targeted Go flake checks id: flake_check if: ${{ fromJSON(steps.selector.outputs.matrix).include[0] != null }} @@ -84,6 +99,15 @@ jobs: test-shuffle: "on" gotestsum-json-file: default + # The upload action only saves on main, so this is a no-op for PRs. + # A workflow_dispatch run on main seeds the cache that PR runs restore. + - name: Upload Embedded Postgres Cache + if: ${{ fromJSON(steps.selector.outputs.matrix).include[0] != null }} + uses: ./.github/actions/embedded-pg-cache/upload + with: + cache-key: ${{ steps.download-embedded-pg-cache.outputs.cache-key }} + cache-path: "${{ steps.embedded-pg-cache.outputs.embedded-pg-cache }}" + - name: Publish Go test failure report if: failure() && steps.flake_check.outcome == 'failure' && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) uses: ./.github/actions/go-test-failure-report diff --git a/cli/server.go b/cli/server.go index 21f26c1dc0..6524d9d6d2 100644 --- a/cli/server.go +++ b/cli/server.go @@ -2412,6 +2412,15 @@ func startBuiltinPostgres(ctx context.Context, cfg config.Root, logger slog.Logg if customCacheDir != "" { cachePath = filepath.Join(customCacheDir, "postgres") } + // Tests get a fresh config root per invocation, so the default cache path + // never hits and each test re-downloads the archive from Maven, which + // rate-limits CI runners. EMBEDDED_PG_CACHE_DIR (restored from the actions + // cache) lets them share one copy. + if flag.Lookup("test.v") != nil { + if dir := os.Getenv("EMBEDDED_PG_CACHE_DIR"); dir != "" { + cachePath = dir + } + } stdlibLogger := slog.Stdlib(ctx, logger.Named("postgres"), slog.LevelDebug) // If the port is not defined, an available port will be found dynamically. This has