← back to Cli Printing Press
fix(ci): shared build cache and Go module caching to prevent test timeouts (#33)
03a19223bd036ca4eb0828261b0e443b1cd73c96 · 2026-03-28 17:41:51 -0700 · Trevin Chow
* fix(ci): shared build cache and Go module caching to prevent test timeouts
The generator tests run 4+ parallel Go compilations (stytch, clerk,
loops, noauth) on CI's 2-vCPU runner. Each was using a per-project
build cache (SHA of output dir), forcing every test to compile the Go
standard library from scratch. Combined with no Go module caching in
the workflow, this caused go vet to timeout after 2 minutes.
Fixes:
- Share a single build cache across all generated CLIs
- Add `cache: true` to setup-go action for module caching
- Use `go-version-file: go.mod` instead of hardcoded 1.22
- Limit test parallelism to 2 packages (`-p 2`) to match CI vCPUs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore(ci): bump actions/checkout from v4 to v6
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore(ci): bump actions/setup-go from v5 to v6
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Files touched
M .github/workflows/validate-catalog.ymlM internal/generator/validate.go
Diff
commit 03a19223bd036ca4eb0828261b0e443b1cd73c96
Author: Trevin Chow <trevin@trevinchow.com>
Date: Sat Mar 28 17:41:51 2026 -0700
fix(ci): shared build cache and Go module caching to prevent test timeouts (#33)
* fix(ci): shared build cache and Go module caching to prevent test timeouts
The generator tests run 4+ parallel Go compilations (stytch, clerk,
loops, noauth) on CI's 2-vCPU runner. Each was using a per-project
build cache (SHA of output dir), forcing every test to compile the Go
standard library from scratch. Combined with no Go module caching in
the workflow, this caused go vet to timeout after 2 minutes.
Fixes:
- Share a single build cache across all generated CLIs
- Add `cache: true` to setup-go action for module caching
- Use `go-version-file: go.mod` instead of hardcoded 1.22
- Limit test parallelism to 2 packages (`-p 2`) to match CI vCPUs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore(ci): bump actions/checkout from v4 to v6
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore(ci): bump actions/setup-go from v5 to v6
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
.github/workflows/validate-catalog.yml | 16 +++++++++-------
internal/generator/validate.go | 17 ++++++++---------
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/.github/workflows/validate-catalog.yml b/.github/workflows/validate-catalog.yml
index f6f4dcb2..b9c01a78 100644
--- a/.github/workflows/validate-catalog.yml
+++ b/.github/workflows/validate-catalog.yml
@@ -9,11 +9,12 @@ jobs:
validate:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v4
+ - uses: actions/checkout@v6
- - uses: actions/setup-go@v5
+ - uses: actions/setup-go@v6
with:
- go-version: '1.22'
+ go-version-file: go.mod
+ cache: true
- name: Build printing-press
run: go build -o ./printing-press ./cmd/printing-press
@@ -60,11 +61,12 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v4
+ - uses: actions/checkout@v6
- - uses: actions/setup-go@v5
+ - uses: actions/setup-go@v6
with:
- go-version: '1.22'
+ go-version-file: go.mod
+ cache: true
- name: Run all tests
- run: go test ./...
+ run: go test -p 2 ./...
diff --git a/internal/generator/validate.go b/internal/generator/validate.go
index be9bb74b..30820a4d 100644
--- a/internal/generator/validate.go
+++ b/internal/generator/validate.go
@@ -3,8 +3,6 @@ package generator
import (
"bytes"
"context"
- "crypto/sha256"
- "encoding/hex"
"fmt"
"os"
"os/exec"
@@ -146,13 +144,12 @@ func runCommand(dir string, timeout time.Duration, name string, args ...string)
}
func goBuildCacheDir(dir string) (string, error) {
- absDir, err := filepath.Abs(dir)
- if err != nil {
- return "", fmt.Errorf("resolving build cache path: %w", err)
- }
-
homeDir, err := os.UserHomeDir()
if err != nil {
+ absDir, absErr := filepath.Abs(dir)
+ if absErr != nil {
+ return "", fmt.Errorf("resolving build cache path: %w", absErr)
+ }
fallback := filepath.Join(absDir, ".cache", "go-build")
if mkErr := os.MkdirAll(fallback, 0o755); mkErr != nil {
return "", fmt.Errorf("creating fallback build cache dir: %w", mkErr)
@@ -160,8 +157,10 @@ func goBuildCacheDir(dir string) (string, error) {
return fallback, nil
}
- sum := sha256.Sum256([]byte(absDir))
- cacheDir := filepath.Join(homeDir, ".cache", "printing-press", "go-build", hex.EncodeToString(sum[:]))
+ // Use a single shared cache for all generated CLIs.
+ // Per-project caches forced each parallel test to compile the Go
+ // standard library from scratch, causing CI timeouts.
+ cacheDir := filepath.Join(homeDir, ".cache", "printing-press", "go-build")
if err := os.MkdirAll(cacheDir, 0o755); err != nil {
return "", fmt.Errorf("creating build cache dir: %w", err)
}
← 03882623 feat(templates): add flag suggestions, sync NDJSON events, a
·
back to Cli Printing Press
·
feat(ci): automated releases, linting, and commit convention c779648a →