# Releasing

How to release the standalone june: a release PR, a tag, and a workflow that builds, tests, signs and publishes it to GitHub Releases. Every step is a `make` target, so you can run any of them locally. [Distribution](https://june.dev/docs/reference/distribution.md) explains how it all works.

> **Not set up yet.** Nothing has been released. The public release repository, its GitHub App, the signing key and the `release` environment below must be created once, by a person, before the first release. Until then the release workflow builds and tests everything and then stops, saying what's missing.

## Release a version

1. **Prepare.** On a branch, bump the version and move the changelog's notes under it, then open a PR like any other:

   ```sh
   make release:prepare bump=minor      # or major, patch, rc, release, or 0.3.0
   ```

   `rc` makes the next release candidate (`0.2.1-rc.1`, then `-rc.2`) and leaves the notes under Unreleased; `release` turns a candidate into its stable release. The PR needs nothing but `packages/june/package.json` and `CHANGELOG.md`.

2. **Merge it.** The `Tag June releases` workflow tags the merge commit `june-v<version>` and starts `Release June`. Any other change to the package's `package.json`, or a rerun, finds the version already tagged and does nothing.

3. **Approve.** `Release June` checks the tag, builds every platform once, smoke tests each one natively, rehearses the release on a fake GitHub and runs the lifecycle tests. The publish job then waits for approval in the `release` environment. Approve it to sign and publish.

4. **Check it:**

   ```sh
   curl -fsSL https://june.dev/install.sh | bash -s -- --version <version>
   june --version
   ```

A release candidate is published as a prerelease, which `june upgrade` and the install scripts never take unless asked for by version. A stable release becomes GitHub's latest only after every asset has been downloaded anonymously and verified.

You can also tag by hand (`make release:tag push=1` on an up-to-date `main`), which starts `Release June` the same way.

## Rehearse

Nothing here needs a credential or publishes anything:

```sh
make verify:cli          # build this machine's june and smoke test its archive with no Bun on PATH
make release:dry-run     # build, sign with a throwaway key, publish twice to a fake GitHub, install it with install.sh
make test:distribution   # install, upgrade, pin, roll back and break three real versions on a fake GitHub
make release:tag dry=1   # say what tag main would get
```

`Release June` can also be run from the Actions tab with `dry_run` (the default): it builds, smoke tests and rehearses a tag or branch, and skips publishing.

## Every step

| Command                                      | Does                                                                                      |
| -------------------------------------------- | ----------------------------------------------------------------------------------------- |
| `make release:prepare bump=<b>`              | Bumps `packages/june` for a release PR (`dry=1` changes nothing)                          |
| `make release:tag [push=1]`                  | Tags `HEAD` `june-v<version>` if that version has no tag and is newer than every release  |
| `make release:check-tag tag=<t>`             | Refuses a tag whose package version differs or whose commit isn't on `main`               |
| `make build:cli [platforms=…] [host=1]`      | Builds the archives and `inventory.json` into `packages/june/out/release`                 |
| `make verify:cli [dir=<build>]`              | Smoke tests this machine's archive from a build                                           |
| `make release:sign [dir=] [key=<pem>]`       | Writes `manifest.json`, `manifest.sig` and `checksums.txt`; the key must be a trusted one |
| `make release:verify [dir=]`                 | Checks a signed build the way installers do                                               |
| `make release:publish repo=<r> commit=<sha>` | Publishes a signed build (token in `JUNE_RELEASE_TOKEN`; `dry=1`)                         |

## When something fails

- **The tag doesn't match the package version, or isn't on `main`.** `release:check-tag` stops the release before anything is built. Delete the tag if nothing was published, fix the version in a PR, and let the merge tag it.
- **A build, smoke test or rehearsal fails.** Nothing is published, and the latest release is unchanged. Fix it on `main` with a new patch version; a published version is never rebuilt.
- **Publishing fails part way.** A release that didn't finish is a draft or a prerelease, never latest. Rerun the failed `Release June` run: `release:publish` uploads only what's missing, checks every asset's digest and picks up where it stopped. It refuses to replace any asset of a published release with different bytes.
- **The workflow says the `release` environment is missing something.** Finish the [one-time setup](#set-up-once); the build is kept as the run's `june-release` artifact for 14 days, and rerunning the publish job uses it.

## A bad release

Published assets are never changed or deleted by the release tooling. To pull a bad stable release back:

1. Make the previous release latest again: `gh release edit june-v<previous> --repo johno/june-releases --latest`. New installs and `june upgrade` get it at once.
2. Tell people who upgraded to run `june rollback`, or `june upgrade --version <previous>`.
3. Release the fix as a new patch version.

## Set up once

These are manual steps for a person with admin access; nothing in the repository does them.

1. **Create the public release repository** `johno/june-releases` with a README, so it has a default branch for release tags. Turn on immutable releases in its settings, so a published release's assets and tag can't change.
2. **Create a GitHub App** with Contents: read and write, installed on `johno/june-releases` only. Its token is the only credential that can publish.
3. **Make the release signing key** on a trusted machine:

   ```sh
   bun packages/june/src/release/cli.ts keygen --out ~/june-release-key
   ```

   Put the public key line in `src/distribution/keys.ts` and in `RELEASE_KEYS` in `install/install.sh` and `install/install.ps1` (a test checks they match), in a PR. Keep the private key's PEM somewhere safe offline too.

4. **Create the `release` environment** in `johno/june` with required reviewers and deployment limited to `main` and `june-v*` tags (the tag workflow releases from `main`; a tag you push releases from the tag), and give it:
   - secrets `JUNE_RELEASE_SIGNING_KEY` (the PEM), `JUNE_RELEASE_APP_ID` and `JUNE_RELEASE_APP_PRIVATE_KEY`;
   - the variable `JUNE_RELEASE_REPO` = `johno/june-releases`.
5. **Protect the tags** with a ruleset on `johno/june` for `june-v*`: only maintainers and GitHub Actions may create them, and no one may update or delete them.
6. **Serve the install scripts** from `https://june.dev/install.sh` and `https://june.dev/install.ps1`, as static files that are exactly `packages/june/install/install.sh` and `install.ps1` from `main` (for example, copied into `apps/www/public` in the PR that adds the release key). Until then, people can run them from a checkout or from the public repository's raw URL.

No npm token, R2 bucket or CDN is involved.

## Rotate the signing key

1. Make a new key (`keygen`) and add its public key to `keys.ts` and both install scripts **alongside** the old one. Release a version signed with the old key: every june upgraded to it trusts both.
2. Switch `JUNE_RELEASE_SIGNING_KEY` to the new key and release again.
3. Once people have had time to upgrade, remove the old key from the trusted lists in a later release.

If the key leaks, do the same, but remove the leaked key in the same release as the new one, make that the latest release, and tell users to reinstall with the install script, since a june that only trusts the leaked key can't tell a forged release from a real one.
