# Distribution

How the [standalone june](https://june.dev/docs/standalone.md) is built, released, installed and upgraded, and why. This is the record of what is implemented; [Releasing](https://june.dev/docs/reference/releasing.md) is the runbook for doing it.

```text
johno/june (private)                     johno/june-releases (public)          a user's machine
────────────────────                     ────────────────────────────          ────────────────
release PR → main → june-vX.Y.Z tag
release.yml: build every platform ──┐
  (one Actions artifact, 14 days)   │
smoke on each OS and CPU            │
rehearse on a fake GitHub           │
sign manifest.json (release key) ───┴──▶ draft → prerelease → verified ──▶ install.sh / install.ps1
                                         anonymously → latest                june upgrade
```

## Decisions

- **GitHub Releases are the only artifact store.** No npm publication, R2, S3, CDN or service. GitHub Actions artifacts only hand builds between jobs: they expire and need authentication, so nothing installs from them.
- **A separate public repository hosts the releases.** The source repository, `johno/june`, is private, and a private repository's release assets can't be downloaded anonymously. Releases go to a public repository, `johno/june-releases`, which holds only release assets and a README, never source. A release names the source commit it was built from in its manifest and notes.
- **The project's june runs project commands.** The installed `june` is a launcher that hands a command to the june its project installs (CLI protocol 1, see [Which june runs a command](https://june.dev/docs/cli.md#which-june-runs-a-command)), so a global upgrade never changes what a project runs.
- **A signature, not only checksums.** Whoever can replace an archive in a release can replace its checksum too, so each release's `manifest.json` is signed with an Ed25519 key that lives only in the release workflow's protected environment, and every june and install script trusts exactly the public keys in `src/distribution/keys.ts`.
- **No silent upgrades.** `june upgrade` runs only when you run it. A check for newer releases (`june upgrade --check`) changes nothing.
- **npm publication is deferred, not designed away.** The `june` package's exports, `bin` and build are unchanged, and a project installs june from the repository or a tarball as before. Publishing it to npm, and serving binaries from a CDN, are separate decisions for later.

## A release

A release is the tag `june-vX.Y.Z`, or `june-vX.Y.Z-rc.N` for a release candidate, on a commit on `main` whose `packages/june/package.json` says exactly that version. Its GitHub release, in the public repository, has these assets:

| Asset                    | What it is                                                                                                                        |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `manifest.json`          | The release: version, tag, channel, source commit, CLI protocol, Bun version, and each archive's platform, name, size and SHA-256 |
| `manifest.sig`           | An SSHSIG signature of `manifest.json`'s exact bytes, namespace `june-release`                                                    |
| `june-<platform>.tar.gz` | One regular file, `june`, mode 755 (macOS and Linux)                                                                              |
| `june-windows-x64.zip`   | One file, `june.exe` (Windows)                                                                                                    |
| `checksums.txt`          | `sha256sum`-style digests, for people checking by hand                                                                            |

`manifest.json` is canonical JSON (sorted keys, no whitespace, one final newline); a reader re-serializes it and refuses anything else, which also rules out duplicate keys. It has exactly these fields, and readers refuse unknown ones, unknown or duplicate platforms, a tag or channel that doesn't match the version, archive names other than `june-<platform>.<ext>`, and impossible sizes.

Release candidates are GitHub prereleases and are never latest. Assets download from:

```text
https://github.com/johno/june-releases/releases/latest/download/manifest.json    latest stable
https://github.com/johno/june-releases/releases/download/june-v0.2.0/<asset>      a version
```

`latest` is GitHub's own latest release: the newest published, non-draft, non-prerelease one, never a sort of tag names.

## Trust

An install or upgrade trusts nothing until it has checked it:

1. **The manifest's signature**, by a key in `src/distribution/keys.ts` (and the install scripts' `RELEASE_KEYS`, which a test keeps identical). The signature is fetched from the manifest's own release, so a release becoming latest between two downloads can't pair one release's manifest with another's signature.
2. **The archive's exact size and SHA-256** against the signed manifest.
3. **The archive's contents**: exactly one regular file with the expected name, read by june's own extractor, so path traversal, links and extra entries are impossible.
4. **The executable**: run in staging, its `--version` must print the release's version.

Downloads are anonymous (no token is ever sent), HTTPS only, and may only be redirected to the release repository's host or GitHub's release asset hosts (`objects.githubusercontent.com`, `release-assets.githubusercontent.com`, `github-releases.githubusercontent.com`). Responses are capped in size and time out when they stall.

The first trust comes from the install script itself, fetched over HTTPS from june.dev (or read before running it), which carries the public keys. After that, each installed june carries them.

**Signatures are SSHSIG** (OpenSSH's `ssh-keygen -Y sign` format), not raw Ed25519, so the install scripts verify them with `ssh-keygen -Y verify`, which macOS, most Linux distributions and Windows 10+ include. macOS's own `openssl` is LibreSSL without usable Ed25519, and an installer can't verify a binary's signature with the binary it is checking.

**What it doesn't protect against**: a compromise of the release signing key, or of the install script's host, before you install. Keep the key in the `release` environment only, and see [rotating it](https://june.dev/docs/reference/releasing.md#rotate-the-signing-key).

## The installation

```text
~/.june/ (JUNE_HOME)
  bin/june -> ../current/june
  current  -> versions/0.2.1/darwin-arm64
  previous -> versions/0.2.0/darwin-arm64
  versions/<version>/<platform>/{june, manifest.json, manifest.sig}
  staging/   .lock/
```

The install scripts verify a release, then hand the verified files to that june's `june upgrade --from <dir> --install`, so installing and upgrading share one implementation (`src/distribution/install.ts`). It holds a lock (a directory with a unique owner token, taken over only when its owner died or after ten minutes), unpacks into `staging/`, runs the new version, renames it into `versions/`, and switches `current` (then `bin/june`) by atomic rename. A running june is never overwritten, any failure leaves the active version as it was, and the active and previous versions are kept.

On Windows, links need extra privileges, so `current` and `previous` are files naming the version and `bin\june.exe` is a copy of the active one, replaced by renaming the running copy away first.

## Platforms

A platform is released only after its executable passes the smoke tests (`src/cli/standalone.e2e.test.ts`) natively; a cross-compiled file isn't evidence. The release workflow builds all of them once on Linux and runs each one's smoke tests on its own runner before anything is published.

| Platform                  | Bun target                 | Released | Native evidence                                                                                |
| ------------------------- | -------------------------- | -------- | ---------------------------------------------------------------------------------------------- |
| darwin-arm64              | `bun-darwin-arm64`         | Yes      | `macos-latest` in CI; Apple silicon locally                                                    |
| darwin-x64                | `bun-darwin-x64-baseline`  | Yes      | `macos-15-intel` in CI; Rosetta 2 locally                                                      |
| linux-x64                 | `bun-linux-x64-baseline`   | Yes      | `ubuntu-latest` in CI; Docker amd64 locally                                                    |
| linux-arm64               | `bun-linux-arm64`          | Yes      | `ubuntu-24.04-arm` in CI; Docker arm64 locally                                                 |
| windows-x64               | `bun-windows-x64-baseline` | Yes      | `windows-latest` in CI: the smoke tests and `windows.dist.ts` (install.ps1, upgrade, rollback) |
| Linux musl, Windows arm64 | none                       | No       | Not built: the installer says so instead of installing a near match                            |

The x64 targets are Bun's baseline builds, which run on CPUs without AVX2 and under Rosetta. Builds are reproducible: two builds of a commit with the same Bun produce byte-identical archives (Bun embeds the output file's name, so every platform compiles to `june`).

## Rate limits and outages

The installers and `june upgrade` use github.com's download URLs, not the REST API, so the REST API's limit of 60 unauthenticated requests an hour doesn't apply. GitHub may still answer `429` or `5xx`, which both report clearly with any `Retry-After`. Installing an exact version (`--version`) never depends on `latest`. `june upgrade --from <dir>` installs from files fetched any other way.

## Moving the releases elsewhere

The release origin is one URL, `DEFAULT_RELEASE.url` in `src/distribution/config.ts` and `DEFAULT_RELEASE_URL` in the install scripts (a test keeps them equal). Any host that serves the same paths (`<url>/latest/download/<asset>` and `<url>/download/<tag>/<asset>`) works:

- **For a mirror**, set `JUNE_RELEASE_URL` for the install script and `june upgrade`. Signatures still have to verify, and `june upgrade` never moves to an older version than you have unless asked, so a mirror can't downgrade you.
- **To move for good** (say, if `johno/june` becomes public and hosts its own releases), publish to both for a release, then release a june whose default URL is the new one; older junes keep upgrading from the old origin until they reach it.

## Code

| Path                                | What it does                                                                                                 |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `src/cli/index.ts`, `launcher.ts`   | The launcher: project handoff, `upgrade` and `rollback`                                                      |
| `src/cli/upgrade.ts`                | `june upgrade` and `june rollback`                                                                           |
| `src/distribution/`                 | What the executable ships: platforms, versions, manifests, signatures, downloads, archives, the installation |
| `src/release/`                      | Release tooling, never shipped: build, sign, publish, tags, rehearsal                                        |
| `install/install.sh`, `install.ps1` | The install scripts                                                                                          |
| `.github/workflows/release*.yml`    | The tag-driven release                                                                                       |
