diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e49e0cb..354958e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,13 +26,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - - uses: actions/cache@v4 - with: - path: | - ~/go/pkg/mod - ~/go/bin - ~/.cache - key: media-sdk - name: Set up SoX resampler and Opus run: | @@ -43,6 +36,23 @@ jobs: uses: actions/setup-go@v5 with: go-version: 1.26 + # setup-go's own cache restores on an exact key only, so any go.sum + # change is a full cold build. Restored below instead. + cache: false + + # The run_id suffix never pre-exists, so a push always writes a fresh + # entry rather than one frozen at the go.sum that first created it. + - name: Restore Go caches + id: go-cache + uses: actions/cache/restore@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: go-${{ runner.os }}-${{ hashFiles('go.sum') }}-${{ github.run_id }} + restore-keys: | + go-${{ runner.os }}-${{ hashFiles('go.sum') }}- + go-${{ runner.os }}- - name: Set up gotestfmt run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest @@ -67,3 +77,14 @@ jobs: run: | set -euo pipefail go test -json -v ./... 2>&1 | gotestfmt + + # Only main writes. Pull requests read main's entry, which keeps ~1 GB + # per PR run out of the repo's 10 GB cache budget. + - name: Save Go caches + if: github.event_name == 'push' + uses: actions/cache/save@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ steps.go-cache.outputs.cache-primary-key }}