Skip to content

Commit e982224

Browse files
authored
ci: stop saving Go build cache outside of main (#5345)
## Why `push.yml` saves many setup-go caches per run, but PR / merge_group / schedule saves are scoped to refs no other run can read. They still count against the 10 GB per-repo quota and evict main's caches via LRU, so most PRs miss the cache entirely. See the [GitHub Actions dependency-caching docs](https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching) for the scope and eviction rules. ## What ### `setup-build-environment` composite The composite now manages the Go cache explicitly instead of relying on `setup-go`'s built-in caching. `setup-go` runs with `cache: false`. On `refs/heads/main` (push + the scheduled wipe-and-repopulate cron from #2092) the unified `actions/cache@v5.0.5` restores immediately and its post-step saves at the calling job's end — composite-action post-steps fire at the job's end, not the composite's, so this works inside the composite. On every other ref, `actions/cache/restore@v5.0.5` restores only. `restore-keys` provides prefix fallback so PR runs with a changed `go.sum` still restore main's most recent cache and rebuild only the delta. The `cache.txt` workaround is gone — `inputs.cache-key` goes directly into the cache key string. ### Drop `task cover` from CI `task cover` was a smoke check on main pushes. Cover-instrumented test binaries land in a different `GOCACHE` slot than the non-cover binaries PRs need, so a `go.sum` bump landing on a main push would leave the cache holding cover artifacts until the next 00:00 UTC wipe-and-repopulate fixed it (up to 24h of PRs missing the test-binary slot). Running `task test` on every event eliminates that hole; coverage stays in `Taskfile.yml` for local use and can come back to CI when there's a real consumer. ### Scheduled cache wipe: twice daily → once daily The cron from #2092 wiped the cache at 00:00 and 12:00 UTC. The noon wipe was harmless when every PR repopulated; now that only main runs repopulate, it creates an unnecessary cold-cache window during the workday. Trimmed to 00:00 UTC. ## Potential follow-ups - `check.yml` lint cache - Three standalone `setup-go` invocations in `push.yml` (`testmask`, `validate-generated-is-up-to-date`, `validate-python-codegen`) - `~/.cache/golangci-lint` analyzer cache This pull request and its description were written by Isaac.
1 parent dd23604 commit e982224

2 files changed

Lines changed: 48 additions & 21 deletions

File tree

.github/actions/setup-build-environment/action.yml

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,55 @@ runs:
1515
- name: Setup JFrog
1616
uses: ./.github/actions/setup-jfrog
1717

18-
- name: Create cache identifier
19-
run: echo "${{ inputs.cache-key }}" > cache.txt
20-
shell: bash
21-
22-
- name: Setup Go
18+
- id: setup-go
19+
name: Setup Go
2320
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
2421
with:
2522
go-version-file: go.mod
26-
cache-dependency-path: |
27-
go.sum
28-
cache.txt
23+
# Disable setup-go's built-in cache; the steps below manage the
24+
# cache so that only push-to-main runs save it. PR / merge_group /
25+
# schedule saves are scoped to refs no other run can read, and
26+
# they evict main's caches from the 10 GB GHA cache quota via LRU.
27+
#
28+
# See: https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching
29+
cache: false
30+
31+
- name: Resolve Go cache paths
32+
id: go-paths
33+
shell: bash
34+
run: |
35+
echo "build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
36+
echo "mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
37+
38+
# On runs against main (push + the scheduled wipe-and-repopulate
39+
# cron added in #2092): restore now, save at job end via the
40+
# unified action's post-step (which fires at the calling job's
41+
# end, even when invoked from a composite).
42+
- name: Restore and save Go cache (main)
43+
if: github.ref == 'refs/heads/main'
44+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
45+
with:
46+
path: |
47+
${{ steps.go-paths.outputs.mod }}
48+
${{ steps.go-paths.outputs.build }}
49+
key: setup-go-${{ inputs.cache-key }}-${{ runner.os }}-go${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.sum') }}
50+
restore-keys: |
51+
setup-go-${{ inputs.cache-key }}-${{ runner.os }}-go${{ steps.setup-go.outputs.go-version }}-
52+
53+
# On every other ref (PR / merge_group): restore only. Prefix
54+
# fallback via restore-keys means runs whose go.sum differs from
55+
# main still restore main's most recent cache and rebuild only
56+
# the delta.
57+
- name: Restore Go cache (non-main)
58+
if: github.ref != 'refs/heads/main'
59+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
60+
with:
61+
path: |
62+
${{ steps.go-paths.outputs.mod }}
63+
${{ steps.go-paths.outputs.build }}
64+
key: setup-go-${{ inputs.cache-key }}-${{ runner.os }}-go${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.sum') }}
65+
restore-keys: |
66+
setup-go-${{ inputs.cache-key }}-${{ runner.os }}-go${{ steps.setup-go.outputs.go-version }}-
2967
3068
- name: Setup Python
3169
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0

.github/workflows/push.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
branches:
1515
- main
1616
schedule:
17-
- cron: '0 0,12 * * *' # Runs at 00:00 and 12:00 UTC daily
17+
- cron: '0 0 * * *' # Runs at 00:00 UTC daily
1818

1919
env:
2020
GOTESTSUM_FORMAT: github-actions
@@ -137,22 +137,11 @@ jobs:
137137
with:
138138
cache-key: test-${{ matrix.deployment }}
139139

140-
- name: Run tests without coverage
141-
# We run tests without coverage on PR, merge_group, and schedule because we don't make use of coverage information
142-
# and would like to run the tests as fast as possible. We run it on schedule as well, because that is what
143-
# populates the cache and cache may include test results.
144-
if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'schedule' }}
140+
- name: Run tests
145141
env:
146142
ENVFILTER: DATABRICKS_BUNDLE_ENGINE=${{ matrix.deployment }}
147143
run: go tool -modfile=tools/task/go.mod task test
148144

149-
- name: Run tests with coverage
150-
# Only run 'task cover' on push to main to make sure it does not get broken.
151-
if: ${{ github.event_name == 'push' }}
152-
env:
153-
ENVFILTER: DATABRICKS_BUNDLE_ENGINE=${{ matrix.deployment }}
154-
run: go tool -modfile=tools/task/go.mod task cover
155-
156145
- name: Upload gotestsum JSON output
157146
# Always upload so we can inspect timing even if tests fail.
158147
if: ${{ always() }}

0 commit comments

Comments
 (0)