Skip to content

feat: download trunk-analytics-cli from trunk.io (GitHub as fallback), cache by default - #151

Merged
dfrankland merged 3 commits into
mainfrom
dylan/download-cli-from-trunk-io
Oct 5, 2026
Merged

dfrankland merged 3 commits into
mainfrom
dylan/download-cli-from-trunk-io

Conversation

@dfrankland

@dfrankland dfrankland commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

What

The action now downloads trunk-analytics-cli from our own release host, https://trunk.io/releases/analytics-cli/prod. GitHub releases are kept only as a fallback. Caching the CLI is now on by default.

trunk.io first

  • latest is resolved once, up front, from channel.json ({"latest":"x.y.z"}). The cache key and the download use that version.
  • Downloads use a concrete path, ${base}/${version}/${artifact}. Artifact names are unchanged.
  • Each download is checked against ${base}/${version}/manifest.json. The tarball's sha256 has to match artifacts[<filename>].sha256. This check applies only to the trunk.io source.
  • A 403/404 is not retried. trunk.io returns a missing object as 403, not 404, because CloudFront's origin has no s3:ListBucket. That answer is deterministic, so we go straight to the fallback. Network errors and 5xx responses are retried first.

GitHub releases as the fallback

GitHub is used whenever trunk.io cannot serve the CLI: channel.json is unreachable, a network error or 5xx outlasts the retries, the version is not published there (403/404), or the sha256 does not match. Each time, a core.warning names the trunk.io failure.

  • latest: GitHub's /releases/latest redirect resolves the version, which sets the cache key, and the binary comes from /latest/download/<artifact>. If GitHub can't resolve it either, the version falls back to DEFAULT_CLI_VERSION, now 0.16.0 (was 0.15.4).
  • Pinned version, or a latest that trunk.io resolved: the binary comes from /download/<ver>/<artifact>.
  • GitHub 403/429 keeps the existing "Github rate limits … cache the analytics-cli" hint.

Caching on by default

use-cache now defaults to true in action.yaml, and an absent input means caching is on in src/inputs.ts. false (or any value other than true) turns it off.

The fetching and resolution code moved from cache.ts and lib.ts into src/release.ts. dist/ is rebuilt.

Merge order: do not merge until the backfill has run

Land trunk-io/analytics-cli#1216 first, and run its backfill of existing GitHub releases. With the GitHub fallback, an early merge no longer breaks pinned versions or the 0.16.0 default. They download from GitHub instead, but every run logs a fallback warning and stays on GitHub's rate limits until the host is populated.

Testing

  • jest: 61 tests pass. __tests__/download.test.ts covers:
    • a trunk.io success that never touches GitHub;
    • a 403 that falls back after one request;
    • a 5xx that falls back after the retries;
    • an unreachable channel.json that resolves through GitHub's redirect and downloads /latest/download/;
    • a sha256 mismatch that falls back;
    • a GitHub refusal that surfaces the rate-limit hint.
  • cache.test.ts adds "uses the cache when use-cache is not set".
  • tsc --noEmit, eslint src __tests__ __fixtures__, trunk check and trunk fmt: clean.

🤖 Generated with Claude Code

dfrankland and others added 2 commits October 2, 2026 20:33
…leases

Resolve `latest` from trunk.io/releases/analytics-cli/prod/channel.json once,
and use that concrete version for both the cache key and the download. Check
each download against the version's manifest.json sha256. A 403/404 from the
releases host means the version is not published, so it fails fast without
retries.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
When trunk.io cannot serve the CLI (an unreachable channel.json, a network
error, a 5xx, a 403/404, or a failed sha256 check), download it from GitHub
releases instead and warn with the trunk.io error. For `latest` that goes
through GitHub's /releases/latest redirect and /latest/download/. The
use-cache input now defaults to true.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@dfrankland dfrankland changed the title feat: download trunk-analytics-cli from trunk.io instead of GitHub releases feat: download trunk-analytics-cli from trunk.io (GitHub as fallback), cache by default Oct 2, 2026
@trunk-staging-io

trunk-staging-io Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Static Badge   Static Badge   Static Badge

View Full Report ↗︎ ⋅ Docs

@trunk-io

trunk-io Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Static Badge   Static Badge   Static Badge

View Full Report ↗︎ ⋅ Docs

@dfrankland
dfrankland marked this pull request as ready for review October 2, 2026 20:58
… be resolved

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Comment thread __tests__/cache.test.ts
handler: repoReleasesVersionDownloadHandler,
mock: repoReleasesVersionDownloadMock,
} = MSW_MOCKS.repoReleasesVersionDownload(cliVersion)
it("uses the cache when use-cache is not set", async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

new behavior. Sanity check that this is intentional?

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.

I wanted to make caching the default behavior. This should be checking that we default to using the cache if use-cache is not set.

expect(githubDownloadMock).not.toHaveBeenCalled();
});

it("falls back to GitHub's pinned download when trunk.io does not have the version", async () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

Comment thread src/release.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@dfrankland
dfrankland merged commit a86313c into main Oct 5, 2026
8 checks passed
@dfrankland
dfrankland deleted the dylan/download-cli-from-trunk-io branch October 5, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants