Skip to content

feat: reuse the goreleaser binary from the runner tool cache - #577

Merged
caarlos0 merged 8 commits into
masterfrom
cache
Sep 3, 2026
Merged

caarlos0 merged 8 commits into
masterfrom
cache

Conversation

@caarlos0

@caarlos0 caarlos0 commented Aug 29, 2026 •

Copy link
Copy Markdown
Member

Makes the action reuse a GoReleaser binary it already installed, instead of downloading and verifying it again.

Closes #476.

What it does

The action already wrote to the runner tool cache, but never read from it, so every run downloaded again. It now calls tc.find() before it downloads.

A second use of the action in the same job, or any job on a self-hosted runner that already has the version, now installs immediately.

The tool cache entry is keyed by distribution (goreleaser / goreleaser-pro) and verification level (checksum / cosign). Both parts are required:

  • OSS and Pro can resolve to the same version, so a shared distribution key could return the OSS binary for a Pro install.
  • A checksum-only entry must not suppress cosign verification when cosign becomes available later.
OSS latest tag: v2.18.0
Pro latest tag: v2.18.0

Nothing read the tool cache before this PR, so these collisions were not reachable on master. Adding tc.find() is what makes them reachable, so the keying ships with it. Both other open PRs miss the distribution part: #528 and #510 each call tc.find('goreleaser-action', ...).

What it saves

Measured on a GitHub-hosted ubuntu runner, in this repository's own ci job, which uses the action twice:

20:57:06.252  Downloading ...goreleaser_Linux_x86_64.tar.gz   <- 1st use
20:57:06.537  Checksum verified
20:57:06.540  Extracting
20:57:07.469  found in the runner tool cache                  <- 2nd use, 0 ms
case saving
action used once per job (most users) none — a fresh VM has an empty tool cache
action used 2+ times in one job, same distribution, version, and verification level ~0.3 s per extra use
self-hosted runner full download and verification, on every job after the first

Be clear about this: a normal single-use release job on a GitHub-hosted runner gets no speed-up. The benefit is for self-hosted runners, which is what #476 asked for, and for repeated use in one job.

Why there is no GitHub Actions cache

The first version of this PR added an opt-in cache-binary input backed by @actions/cache. It was measured and removed. On ubuntu-latest, same job, same version:

path time
cold: download + checksum + cosign + extract 0.93 s
cache hit: restore the 24 MB entry 1.28 s
first run also pays a save +2.26 s

It is slower than a download in every configuration measured. A GitHub-hosted runner reaches the release CDN in about 0.4 s for the 15 MB archive, and the cached entry is the larger extracted directory.

It was also wrong on three other counts:

  • It skipped the sha256 and cosign verification on a hit — the control it was meant to protect. The only case where it wins on time is when cosign is installed, which is exactly the case where skipping is wrong.
  • It cost 875 KB (+120%) of dist/index.js for every user, and 24 MB of repository cache quota per version and platform.
  • The restore and save wrappers were dead code. @actions/cache catches everything except ValidationError internally, and logs ReserveCacheError at info level itself, so the try/catch and the instanceof classification could never run.

Trust

A binary taken from the tool cache is not verified again. Cache entries record whether checksum or checksum and cosign verification completed. When cosign is available for a release with a sigstore bundle, the action only accepts a cosign-verified entry. If the checksum file cannot be downloaded, the binary can run for that invocation under the existing best-effort policy, but it is not stored in the persistent tool cache.

On a self-hosted runner the tool cache is kept between jobs, so it must be trusted like the runner itself. GitHub-hosted runners start with an empty tool cache in every job.

Tests

The first version asserted that two installs return the same path. That path is a pure function of the tool, version and architecture, so the assertion passed even with the tool cache wiped between the two calls — it could not fail.

The tests now cover:

  • a second install reports a tool cache hit and does not download;
  • OSS and Pro do not share entries;
  • a checksum-download failure does not create a reusable entry;
  • enabling cosign after a checksum-only install performs signature verification;
  • releases without sigstore bundles still reuse checksum-verified entries.

Credits

Builds on #510 (@timbretimber) and #528 (@akkuman), both added as co-authors.

Look for GoReleaser in the runner tool cache before a download. This
makes a second use of the action in the same job, or any job on a
self-hosted runner, install immediately.

Add an opt-in `cache-binary` input that also stores the binary in the
GitHub Actions cache. When it hits, the action does not download the
release archive, the checksums and the signature bundle again. Cache
errors are not fatal and fall back to a download.

The runner tool cache entry is now keyed by distribution, so a Pro
binary is no longer returned for an OSS install of the same version.

Closes #476

Co-authored-by: timbretimber <105982513+timbretimber@users.noreply.github.com>
Co-authored-by: Akkuman <akkumans@qq.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@caarlos0
caarlos0 requested a review from crazy-max as a code owner August 29, 2026 18:33
caarlos0 and others added 3 commits August 29, 2026 15:37
Both branches called extractZip with the same destination after the
install rewrite, so only the source path differs now.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4eaf86fa-a85b-41f6-8763-612acc1ccc39
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

# Conflicts:
#	dist/index.js
Review found that the GitHub Actions cache layer cost more than it
saved. Measured on ubuntu-latest, same job, same version:

  cold: download + checksum + cosign + extract   0.93 s
  cache hit: restore the 24 MB entry             1.28 s
  first run also pays a save                    +2.26 s

It is slower than a download in every configuration measured, because a
GitHub-hosted runner reaches the release CDN in about 0.4 s for a 15 MB
archive, and the cached entry is the larger extracted directory.

It also skipped the sha256 and cosign verification on a hit, which is
the control it was supposed to protect, and the only case where it wins
on time is when cosign is installed, which is exactly the case where
skipping is wrong. It cost 875 KB (+120%) of dist/index.js for every
user and 24 MB of repository cache quota per version and platform.

The restore and save wrappers were also dead code: @actions/cache
catches everything except ValidationError internally, so the try/catch
and the ReserveCacheError classification could never run.

What remains is the runner tool cache lookup, which is what #476 asked
for, and the distribution-keyed tool name that stops a Pro binary being
returned for an OSS install.

The tool cache test asserted that two installs return the same path, but
that path is a pure function of the tool, version and architecture: it
passed even with the tool cache wiped between the calls. It now asserts
that the second install reports a tool cache hit and does not download,
and it was verified to fail when the lookup is removed.

Co-authored-by: timbretimber <105982513+timbretimber@users.noreply.github.com>
Co-authored-by: Akkuman <akkumans@qq.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4eaf86fa-a85b-41f6-8763-612acc1ccc39
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@caarlos0 caarlos0 changed the title feat: cache the goreleaser binary feat: reuse the goreleaser binary from the runner tool cache Aug 29, 2026

@caarlos0 caarlos0 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking review from GitHub Copilot. These findings can make a self-hosted runner trust binaries with less verification than the documented contract. GitHub does not allow REQUEST_CHANGES on the author account, so this review uses COMMENT, but both findings are blocking. The refreshed master also conflicts in generated dist/index.js; merge master and regenerate the bundle from the merged sources. Per request, no local build was run.

Comment thread src/goreleaser.ts Resolved
Comment thread src/goreleaser.ts Resolved
caarlos0 and others added 3 commits September 3, 2026 00:14
Review feedback: the paragraph explaining why the action does not use the
GitHub Actions cache is not needed. The measurements stay in the pull
request for anyone who asks again.

Also rebuilds dist for js-yaml 5.4.1, merged from master in #578.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4eaf86fa-a85b-41f6-8763-612acc1ccc39
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

# Conflicts:
#	dist/index.js
Keep checksum-skipped downloads out of the persistent tool cache and separate checksum-only entries from cosign-verified entries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5abc512e-338c-4459-98ea-d3606438d56a
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Action isn't using the previously cached download

1 participant