# 9.3 Packing, Publishing, and Releasing

_Pekit / Pekit TRM / Commands_

> How pekit package and pekit publish call the workspace's packagers, and the stages of pekit release, from checking the working tree to tagging the commit.

## 9.3.1 Packing

The workspace's packagers are the `packaging` module's `^packagers`, set
from `pekitconf.packagers`. Each is a `packaging.Packager`: a `name`, a
`pack` function of a package to the directory it packed it into, and a
`publish` function of a package, that directory, and a store.

`pekit package` evaluates `packaging.pack(package NAME())` for each package
selected. The module's `pack` calls each packager's `pack`, which is
normally a hermetic step. A workspace with no packager fails with an error
saying to list one in `pekitconf.packagers`.

## 9.3.2 Publishing

`pekit publish` evaluates `packaging.publish(package NAME(), "STORE")` for
each package. The module packs the package with each packager, then calls
each packager's `publish` with the packed directory and the store, as the
target's own effects, in program order, outside any step. The store is an
argument rather than a context, so packing doesn't depend on it, and
publishing into a second store packs nothing again.

A package that fails to publish fails alone, as any target does, and the
packages published before it stay published.

## 9.3.3 Publishing strictly

A packager's `publish` is a target's own effect, which a strict build
refuses. So `pekit publish --strict` builds in two passes, as a release
does (`published_strictly`):

1. **Pack strictly.** Every package selected is packed, as `pekit package
   --strict` packs it.
2. **Gate.** A recipe any of whose packages failed to pack is held back:
   none of its packages is published, each fails, and so does the command.
   A packager such as ppk never publishes a version twice with other
   contents, so a recipe's family of packages is published whole or not at
   all. The other recipes go on to be published.
3. **Publish.** The packages are published with the strict pass's
   settings: no host tools, and the same platform key. The target's own
   effects are allowed, and every step is taken from the store, even with
   `--rebuild`. This pass writes no trace or GCSL profile.

The steps counted are those of the strict pass, and any the publishing ran.

## 9.3.4 Releasing

`pekit release PACKAGE --to STORE` works in these stages (`release`):

1. **Check the tree.** The workspace has to be in a git repository and match
   its `HEAD`: every file committed, nothing changed or untracked, except
   `pekit-out/` and `.gcsl/`. Otherwise the command fails, naming each file
   that differs.
2. **Export.** The workspace's tree at `HEAD` is exported with `git archive`
   into a directory of its own under the cache, so no file the repository
   ignores, or doesn't hold, reaches the build.
3. **Build strictly.** The package is packed there with `--strict`,
   `--check-reproducible`, and the `release` profile. Its value gives the
   package's name and version.
4. **Check the tag.** The tag is `NAME@VERSION`. If a tag of that name is on
   another commit, the release fails, before anything is published.
5. **Publish.** The package is published with each packager into the store.
   Publishing is a target's own effect, which a strict build refuses, so
   this pass keeps the strict build's step settings, no host tools and the
   same platform key, so that its steps are found in the store, and allows
   the target's effects, which the strict pass checked.
6. **Tag.** `HEAD` is tagged `NAME@VERSION` with a lightweight tag, which
   needs no git identity. If the tag is already on `HEAD`, the package is
   published again and no tag is added.

A tag is only ever added, never moved or deleted.
