# Contributing

> Where Barn's code lives, the checks a change must pass, how to edit these docs, and how releases and the image catalog are maintained.

---

LLMS index: [llms.txt](/v1.5/llms.txt)

---

Start here to change Barn: find the code, run the checks a pull request must pass, and edit these docs. The last two sections are for maintainers cutting a release or refreshing the image catalog. Barn is Apache-2.0; for a large change, open an issue first to agree on the design.

## Choose a repository {#choose-a-repository}

| What you want to change | Where to work |
|---|---|
| CLI behavior, VM lifecycle, native macOS component (`Barn.app`), installer, and packages | [`pgsty/barn`](https://github.com/pgsty/barn) |
| Documentation site, guides, command reference, and translations | [`pgsty/barn.pgsty.com`](https://github.com/pgsty/barn.pgsty.com) |
| Official Linux image definitions or offline normalization rules | `packaging/image-repository/` and `packaging/image-pipeline/` in [`pgsty/barn`](https://github.com/pgsty/barn) |
{.wide .expand}

A useful bug report has `barn version`, the host OS and architecture, the exact command, and the error output with private keys and passwords removed. Report security problems [privately](../security/#report-a-vulnerability). Coding style, error-message rules, and commit conventions are in [`CONTRIBUTING.md`](https://github.com/pgsty/barn/blob/main/CONTRIBUTING.md).

## Keep the product model {#product-model}

Barn keeps a deliberately small product model, and changes should preserve it:

- **One Linux deployment per `BARN_HOME`**: no projects, leases, or workspaces ([scope](../../reference/configuration/#discovery), [rationale](../design/)).
- **One inventory format**: a Pigsty-compatible Ansible inventory; an unknown `vm_*` key is an error.
- **Absence never destroys**: removing a host from the inventory does not delete its VM; destruction is always an explicit command.
- **One privileged path**: root work goes through `barn-hosts-helper` or the reviewed network plan, nowhere else.
- **`barn mac` stays separate**: it never reads the Linux inventory and runs entirely as the invoking user.

## Find the implementation {#find-the-implementation}

| Subsystem | Source paths |
|---|---|
| CLI commands, flags, JSON/YAML output, and error rendering | `cmd/barn/`, `internal/failure/` |
| Inventory parsing, defaults, and resolved node specs | `internal/config/`, `internal/spec/` |
| Linux lifecycle: convergence, journals, disks, and SSH readiness | `internal/linuxvm/` (`internal/private/` in v1.3.0 and earlier), `internal/vm/`, `internal/cloudinit/`, `internal/state/` |
| Host platform and QEMU arguments | `internal/platform/`, `internal/qemu/` |
| Host preparation, networking, process identity, and `/etc/hosts` | `internal/setup/`, `internal/network/`, `internal/process/`, `internal/hostconfig/`, `cmd/barn-hosts-helper/` |
| Deployment SSH keys and the `~/.ssh/config` integration | `internal/sshkeys/`, `internal/sshconfig/` |
| Guest clock checks and scheduled sync | `internal/timesync/`, `internal/timejob/` |
| Image catalog trust, `qcow2` verification, and catalog tools | `internal/image/`, `tools/catalogcheck/`, `tools/catalogexport/`, `tools/catalogsign/` |
| Native macOS VMs and the desktop app | `internal/macvm/`, `native/mac-runner/` |
| Packaging, image pipeline, CI workflows, and integration tests | `packaging/`, `.github/workflows/`, `tests/` |
{.wide .expand}

Read each package's tests alongside the code: they pin down which failures Barn recovers from automatically and which ones must stop safely.

## Build and test {#build-and-test}

Install Go 1.27.4 and the linters pinned in `packaging/toolchain.env`; CI asserts these exact versions:

```bash
go install honnef.co/go/tools/cmd/staticcheck@v0.8.2
go install golang.org/x/tools/cmd/deadcode@v0.53.0
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.15.0
go install golang.org/x/vuln/cmd/govulncheck@v1.10.0
```

Put `GOBIN` (or `$(go env GOPATH)/bin`) on your `PATH`. `make check` also needs Python 3, `jq`, and a C compiler for the race detector.

| Target | What it does | Run it |
|---|---|---|
| `make build` | Builds `bin/barn` and its matching `bin/barn-hosts-helper` for this host | While iterating ([details](../../start/source-build/#build-the-cli)) |
| `make test` | `go test ./...` | While iterating |
| `make race` | `go test -race ./...` | For concurrency changes |
| `make check` | Everything CI runs (below) | Before every pull request; it must pass |
| `make mac-native-test` | C and Swift tests for the native runner; needs Apple Silicon, macOS 27+, and Xcode 27+ | For native Mac changes |
| `make release-snapshot` | Builds and verifies a complete snapshot release without uploading anything | For changes under `tools/`, `packaging/`, `.goreleaser.yaml`, or the `Makefile` |
{.wide .expand}

`make check` runs module verification (`go mod verify`, `go mod tidy -diff`), shell syntax checks, the maintenance-ownership check, unit and race tests, `go vet`, Staticcheck, the four-target `deadcode` intersection, errcheck through `golangci-lint`, `govulncheck`, cross-compilation for `darwin/arm64`, `darwin/amd64`, `linux/amd64`, and `linux/arm64`, the image-pipeline and installer tests (including `tests/mac-release-test.py`), and the dependency-license check. The maintenance check fails when a new file under `tools/` or `packaging/` is not referenced by a Make target, a workflow, or `CONTRIBUTING.md`.

Changes to virtualization, networking, or disk behavior also need a live run on the target host (Linux KVM, macOS HVF, or Virtualization.framework for `barn mac`); name the host in the pull request.

Packaging changes also run the `packaging` workflow. To reproduce it locally, install GoReleaser, nFPM, and Syft at the versions in `packaging/toolchain.env`, then run:

```bash
make release-snapshot SNAPSHOT_DIST=.goreleaser-review
```

`release-snapshot` first runs `make release-check` (toolchain versions and `goreleaser check`), then builds and verifies archives, `.deb`/`.rpm` packages, SBOMs, and checksums. `SNAPSHOT_DIST` (default `.goreleaser-snapshot`) must name one new directory directly under the repository root. To include the native Mac payload, see [Mac Release](../mac-release/#snapshot-payload).

## Edit the documentation {#edit-the-documentation}

The site is Hugo with the OINK theme, in [`pgsty/barn.pgsty.com`](https://github.com/pgsty/barn.pgsty.com); the source repository keeps no `docs/` directory.

| Content | Location |
|---|---|
| Task guides | `versions/manuals/1.5/docs/start/` for 1.5-specific changes |
| Command and configuration reference | `versions/manuals/1.5/docs/reference/` for 1.5-specific changes |
| Project pages (this section) | `versions/manuals/1.5/docs/about/` for 1.5-specific changes |
| Design decisions and research, with date and implementation status | `content/blog/design/` |
| Release notes | `content/release/` |
{.wide .expand}

Every page is an English/Chinese pair, `page.md` and `page.zh.md`, with the same front matter routing fields and the same explicit `{#id}` on every heading, which OINK's Duo View uses to align the two languages. Follow [`STYLE_GUIDE.md`](https://github.com/pgsty/barn.pgsty.com/blob/main/STYLE_GUIDE.md). Check CLI examples against `barn <command> --help`, and inventory examples with `barn validate` and `barn plan` under a temporary `BARN_HOME`.

Validate the site before committing:

```bash
make check
```

The check verifies Go modules and builds both editions with the pinned OINK theme. It checks internal links, anchors, assets and search indexes before replacing `public/`. Use `make dev` to live-edit the 1.5 manual with a sibling `../oink` checkout, or `make preview` to browse both editions with the pinned theme.

## Release outputs and gates {#release-outputs-and-gates}

Each release publishes:

- `.tar.gz` archives for `darwin` and `linux` on `amd64` and `arm64`, each with `bin/barn`, `bin/barn-hosts-helper`, and `licenses/`. Since 0.9.2 the Darwin arm64 archive also carries `bin/Barn.app`, with the CLI, helper, and app signed with Developer ID and notarized.
- Linux `.deb` and `.rpm` packages that install `/usr/bin/barn` and `/opt/barn/libexec/barn-hosts-helper`.
- `checksums.txt`, its detached `checksums.txt.sig`, `release.json`, SPDX SBOMs, the Homebrew formula, and the installer.

Stable versions from 1.0.0 on become GitHub's latest release. Versions below 1.0.0 and versions with a prerelease suffix are GitHub pre-releases, and the installer needs an explicit `BARN_VERSION` for them.

Cut a release in this order:

1. Move the `Unreleased` entries in `CHANGELOG.md` into a dated section, update the README installation links, and add an English release note without a top-level heading at `.github/releases/<version>.md`.
2. Pass the catalog gate with `make catalog-check`, synchronizing the embedded catalog first if it changed ([below](#maintain-the-image-catalog)).
3. Require source CI to pass on the release commit, and a packaging snapshot to pass on the latest packaging changes.
4. Build the assets from the tag: push `v<version>` to run the tag workflow, which needs all six [Apple signing secrets](../mac-release/#ci-signing), or use the [local release path](../mac-release/#local-release). Both verify archives, packages, SBOMs, checksums, and CLI/helper pairing before creating a draft release.
5. Run live Linux VM acceptance, plus [Mac acceptance](../mac-release/#acceptance) when shipping `Barn.app`.
6. Sign the draft checksum manifest, upload the final metadata and signature, and run `make release-publish RELEASE_TAG=v<version>`. Update Homebrew and the bilingual site after publication. [Signing procedure](../../reference/repository-signing/#maintainer-sign)
7. Verify anonymous downloads, the installer, and the Homebrew upgrade against the published bytes.
{.steps}

## Maintain the image catalog {#maintain-the-image-catalog}

The catalog embedded in `barn` and the one published on the mirrors must be byte-identical at every revision; Barn rejects two different catalogs with the same revision as signed equivocation. Never republish a revision with different bytes.

Build and normalize candidate `qcow2` images with the [Image Pipeline](../../reference/image-pipeline/) (`packaging/image-pipeline/build-official.py --list` shows the ten-image matrix). The pipeline produces an unsigned candidate repository for `barn repo build` and `barn repo verify`; it never edits `repo.yaml`, signs, or publishes, so promotion stays a separate step. Promote an image only after native startup and SSH checks on each changed architecture.

Sign the same `catalog.json` bytes twice. Barn 1.5.0 verifies the ML-DSA-87 `.sig` sidecar. Barn 1.4.0 verifies `.minisig` with the existing Minisign key. [Maintainer commands and key fingerprints](../../reference/repository-signing/#maintainer-sign)

When the published catalog changes, bring the source in line before the next release:

1. Verify the new signed catalog, then copy it to `internal/image/default-catalog.json`.
2. Update `EmbeddedManifestVersion` in `internal/image/catalog.go` and the embedded catalog date in `internal/image/manifest.go`; update `packaging/image-repository/repo.yaml` if the repository sources changed.
3. Run the catalog tests (`go test ./internal/image/...`), and `barn update` with a fresh temporary `BARN_HOME` to confirm the remote catalog verifies and activates.
4. Run the online gate:

   ```bash
   make catalog-check
   go run ./tools/catalogcheck -verify-bytes
   ```

   `make catalog-check` activates each official mirror's signed catalog in a fresh temporary data root, requires exact byte agreement with the embedded catalog, and checks every stable artifact's availability and size. `-verify-bytes` also downloads and hashes every stable image (several GB, nothing kept). Formal native builds and both release paths run `catalog-check` automatically; never bypass it to ship references to removed images.
{.steps}

Client-side verification and the repository format are in [Linux Images](../../reference/images/).
