# Packaging and releases

kurama ships one Go binary per platform. Windows has two builds from the same
source:

| Artifact | Purpose | Console window |
| --- | --- | --- |
| `kurama.exe` | Double-click GUI | No (`-H=windowsgui`) |
| `kurama-cli.exe` | Terminal wizard and scripts | Yes |

Linux and macOS use a single `kurama` binary that can do both. The GUI always
runs through the user's default browser, so no platform-specific webview is
needed.

## Local builds

### Windows (PowerShell)

```powershell
pwsh ./packaging/build.ps1 -Version 2.1.1
```

Outputs to `dist/`:

```
kurama_2.1.1_windows_amd64.zip
kurama-cli_2.1.1_windows_amd64.zip
kurama_2.1.1_windows_arm64.zip
kurama-cli_2.1.1_windows_arm64.zip
checksums.txt
```

Each zip contains the executable plus `LICENSE.md`,
`THIRD_PARTY_NOTICES.md`, and `LICENSE-geckodriver.txt`. The script injects
version, commit, and UTC build date with `-ldflags`, uses `-trimpath`, and
writes SHA-256 hashes.

### Linux / macOS

```bash
./packaging/build.sh 2.1.1
```

The script cross-compiles Windows, Linux, and macOS artifacts into `dist/` and
writes `checksums.txt`. Linux and macOS get a single `kurama` binary that can
open the GUI or run the CLI. Build on any platform; Go's cross-compilation needs
no C toolchain because kurama is pure Go.

### Make targets

```bash
make build          # console binary for the host
make build-gui      # Windows GUI executable
make build-cli      # Windows CLI executable
make test
make release-check  # tests, vet, and cross-build sanity
```

## GoReleaser

`.goreleaser.yaml` defines the release artifacts. It builds the Windows GUI and
the cross-platform CLI, then produces zips/tarballs and a checksum file.

```bash
goreleaser build --snapshot --clean     # build only, no publish
goreleaser release --clean              # publish after configuring a remote
```

The repository currently has no Git remote. Add one before publishing. For
Codeberg, configure GoReleaser's Gitea support and provide a `GITEA_TOKEN` with
release permission; for GitHub, the equivalent is `GITHUB_TOKEN`. The config
itself is host-neutral and only names the project, builds, and archives.

Asset names are stable:

```
kurama_<version>_windows_<arch>.zip          (GUI, no console)
kurama-cli_<version>_windows_<arch>.zip      (Windows CLI)
kurama_<version>_<os>_<arch>.tar.gz          (Linux/macOS; GUI and CLI)
checksums.txt
```

The download page uses these names. Update `index.html` when the version
changes, or point its buttons at the releases page.

## Continuous integration

`.forgejo/workflows/ci.yml` runs on Codeberg for pushes and pull requests:

1. check out the repository,
2. `go build ./...`,
3. `go vet ./...`,
4. `go test ./...`.

The Go unit suite is hermetic, so CI needs no Firefox. Integration and Selenium
tests are intentionally not part of the default job: they launch a browser and
need network access to addons.mozilla.org; the Selenium GUI suite also needs
Python. Run them on a release machine or in a dedicated job. `docs/testing.md`
lists the commands.

A future release workflow can call `goreleaser release` on a `v*` tag once a
remote and token exist. Keeping publishing manual until then avoids broken
release links.

## Version injection

Build metadata lives in `internal/version`:

```go
var (
    Version = "2.1.1-dev"
    Commit  = "unknown"
    Date    = "unknown"
)
```

Override with:

```
-X codeberg.org/farba/kurama/internal/version.Version=2.1.1
-X codeberg.org/farba/kurama/internal/version.Commit=<sha>
-X codeberg.org/farba/kurama/internal/version.Date=<RFC3339>
```

`kurama version` and `kurama doctor` print the result.

## Release checklist

1. Update the version in `packaging/build.ps1`/`build.sh`, `index.html`, and
   `website/docs/install.html` if you use an explicit version.
2. Run `go test ./...` and `go vet ./...`.
3. Run the Go integration tests and the Selenium GUI suite on a machine with
   Firefox; Python and Selenium are needed only for the GUI suite.
4. Build both Windows binaries and smoke-test them:
   - `kurama-cli.exe version`
   - `kurama-cli.exe doctor`
   - double-click `kurama.exe`, complete quick setup in a throwaway profile.
5. Generate checksums and attach every artifact plus `checksums.txt` to the
   release.
6. Update `index.html` and `website/docs/install.html` links if the release URL
   or version changed.
7. Tag the release and push. Never rewrite a published tag.

## Smoke-testing the Windows GUI build

`-H=windowsgui` detaches stdout, so a console command checking the binary cannot
read normal output. Instead:

```powershell
# The packaging script writes zips, not loose executables.
Expand-Archive .\dist\kurama-cli_2.1.1_windows_amd64.zip .\tmp -Force
.\tmp\kurama-cli.exe doctor
.\tmp\kurama-cli.exe apply --dry-run --preset balanced

# Start the GUI build; the browser opens the local wizard.
Expand-Archive .\dist\kurama_2.1.1_windows_amd64.zip .\tmp -Force
Start-Process .\tmp\kurama.exe
```

If SmartScreen warns about an unsigned download, that is expected for a new
unsigned project. Code signing requires a certificate and is not part of the
current build.

## What is embedded

Because assets use `go:embed`, packaging never needs to copy sidecar files:

- preference `.txt` bundles,
- uBlock Origin XPI,
- wallpaper JPEG,
- GUI HTML/CSS/JS and favicon,
- the geckodriver archive for the target platform.

A user can move the executable anywhere and it still works. There is no Python,
Selenium, Java, or runtime driver download. The first add-on install extracts
geckodriver into the user cache; release archives also carry the MPL-2.0
license text in `LICENSE-geckodriver.txt`.

## Reproducibility

`-trimpath` removes local paths. Go builds are otherwise reproducible when the
same toolchain, version, commit, and date are supplied. The build scripts derive
the date from the current UTC clock, so byte-for-byte reproducibility requires
passing a fixed date; that is intentional for human-readable release metadata.
