Metadata-Version: 2.4
Name: gorget
Version: 0.1.30
Summary: Source-pipeline tool for RPM package supply-chain trust
License: MIT License
        
        Copyright (c) 2026 gorget-project
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyYAML>=6.0
Requires-Dist: requests>=2.31
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: pytest-mock>=3.12; extra == "dev"
Requires-Dist: responses>=0.24; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: mypy>=1.8; extra == "dev"
Requires-Dist: types-PyYAML; extra == "dev"
Requires-Dist: types-requests; extra == "dev"
Dynamic: license-file

# Gorget

**Gorget** is a source-pipeline tool for RPM package supply-chain trust. It
fetches upstream source tarballs directly from their origin (rather than an
intermediate lookaside cache), applies transforms, verifies integrity,
enforces dependency policy, and emits lookaside-ready artifacts.

It's a plain CLI tool, installed like any other build dependency (e.g. via
RPM) and invoked directly -- its acquisition and derivation steps already run
untrusted third-party code the same way `go-vendor-tools`, `npm`, `cargo`, and Maven do,
so it doesn't need or get container isolation those tools don't have either.

Each package gets a declarative `<package>.source-pipeline.yaml` describing
exactly how its sources are produced. When no pipeline YAML exists, gorget
falls back to fetching every `Source` URL declared in the package's spec file.

This is an early-stage implementation covering the **Fetch**, **Transform**,
**Verify**, **Policy**, and **Post** stages and the core framework (config
parsing, variable substitution, the stage pipeline, and a minimal Emit).

## How-to guides

- [Getting started: write your first source-pipeline.yaml](docs/how-to/getting-started.md)
- [Add source verification for a new upstream](docs/how-to/verify-a-new-upstream.md)
- [Hand-patch a vendored dependency, and stop it from regressing](docs/how-to/hand-patch-and-enforce-a-dependency-version.md)
- [Maven bump and offline vendor example](examples/maven-pipeline-demo/)
- [Add a policy check to an existing pipeline](docs/how-to/add-a-policy-check.md)
- [Add a post: step to refresh generated metadata](docs/how-to/add-a-post-step.md)
- [Fetch a source whose URL you don't know until runtime](docs/how-to/discover-additional-sources.md)
- [Fetch from a private git repo](docs/how-to/fetch-from-a-private-repo.md)
- [Debug a failing pipeline locally](docs/how-to/debug-a-failing-pipeline.md)

## CLI interface

```
gorget \
  --package-dir ./<package-dir> \
  --pipeline-file ./pipeline.yaml \
  --gpg-keys-dir ./gpg-keys \
  --output-dir ./output \
  --version <new-version> \
  [--old-version <old-version>] \
  [--dry-run]
```

| Flag | Purpose |
|---|---|
| `--package-dir` | Package directory: spec file, patches, sources manifest |
| `--pipeline-file` | The package's pipeline definition (optional) |
| `--gpg-keys-dir` | Centralized GPG keyrings, one armored/binary key file per trusted upstream, referenced by filename from `verify: gpg-signature` steps |
| `--output-dir` | Fetched tarballs, `sources` manifest, `report.json` |

Each of these has a historical default (`/package`, `/pipeline.yaml`,
`/gpg-keys`, `/output` respectively, see [CLI flags](#cli-flags)) from
gorget's original container-mount design, but every real caller passes all
four explicitly -- there's no container providing them implicitly anymore.

## Pipeline steps

### `fetch:`

| Step | Purpose |
|---|---|
| `spec-update` | Bump `Version:`/reset `Release:`/apply declared substitutions, before Source URLs resolve |
| `spec-source` | Download the spec's `Source0`/`SourceN` URLs (macro-resolved), by index or all |
| `url` | Download an explicit URL not declared in the spec |
| `git` | Clone a repo at a tag/branch/commit/tree (optionally with recursive submodules via `submodules: shallow`/`full`; use `full` if the project pins submodules to non-tip commits), archive the checkout (or a subdir) |

`vendor` runs package managers in a disposable copy of the source tree. Dependency
trees, caches, and other package-manager changes cannot enter a later Source0 repack.
The `sync-go-modules` option copies Go module metadata back to Source0.
Yarn vendoring also copies `yarn.lock` and `.yarnrc.yml` back to Source0, so its
checksums and offline-cache settings match the generated vendor archive.

Pinned Git trees without commit history use zero timestamps in their archives.

`git` (or another real fetch step) is mandatory for a **native package** (no
Fedora dist-git history, so no `Source0` tarball URL to fall back to) --
there's no bare-`spec-source` fallback the way an already-Fedora-derived
package has. `vendor` is only needed on top of that if the package actually
has dependencies to vendor -- exactly the same condition as for any package,
native or not, nothing about it is native-specific. `transform:`/`verify:`/
`policy:`/`post:` are all still available too, same as any other pipeline --
see [`native-cargo-demo`](examples/native-cargo-demo/) for a native package
that happens to need both `git` and `vendor`.

```yaml
fetch:
  - type: git
    repo: "${UPSTREAM_REPO}"   # or a literal URL/local path
    ref: "v${VERSION}"          # tag, branch, or commit SHA
    shallow: true                # default; a SHA-like ref falls back to a
                                  # partial clone instead of true --depth 1
    subdir: null                  # archive just this subdir of the checkout
    archive_name: "${PACKAGE}-${VERSION}.tar.gz"  # default shown; optional

transform:
  - type: vendor
    ecosystem: cargo              # go | npm | cargo | composer | maven | gradle
    archive_name: "${PACKAGE}-${VERSION}-vendor.tar.xz"  # see note below
    modules:                       # default: [{path: "."}] -- a single
      - path: "."                  # module rooted at the checkout itself
        name: null                  # explicit label (multi-module archives
                                     # only; see combine.py for etcd's case)
```

For a single Cargo module without an explicit `name`, the vendor archive contains
`vendor/` and `vendor-config.toml`. Append `vendor-config.toml` to the build's
`.cargo/config.toml` after extraction. It redirects registry and Git dependencies
to the relative `vendor` directory, so an offline build needs no Cargo cache.

For pnpm packages, `offline-cache` defaults to true. Gorget reads the exact
`pnpm@...` version from `package.json` when present. It also reads an exact
`devEngines.packageManager` pnpm version. If neither field sets an exact
version, Gorget uses the configured pnpm executable. Gorget bundles that CLI
with a working `.bin/pnpm` shim, `.pnpm-store`, and `.pnpm-cache`. It adds full
registry metadata for names in `metadata-packages:` when absent from pnpm's
install-generated cache. A frozen lockfile gives pnpm exact versions and
integrity hashes, so the install can fetch package contents without asking the
registry for every package's full version catalog. The archive contains
`.pnpm`, `.pnpm-store`, and `.pnpm-cache` at its root. Gorget runs the install
once per declared platform with pnpm 10.14 or later. Older pnpm versions use
`--force` to fetch optional packages for all platforms. This mode requires one module. Set
`offline-cache: false` to use the legacy store-only vendor archive.
Use that opt-out only when the consumer does not need an offline pnpm install.
Set `metadata-packages:` only for packages whose full registry metadata the
offline build needs but the frozen install does not fetch. This option supports
pnpm 11 and 12.

```yaml
fetch:
  - type: git
    repo: "${UPSTREAM_REPO}"
    ref: "v${VERSION}"
    submodules: full

transform:
  - type: vendor
    ecosystem: pnpm
    modules:
      - path: jaeger-ui
    archive_name: "jaeger-ui-pnpm-cache-${VERSION}.tar.bz2"
    metadata-packages:
      - "@adobe/css-tools"
```

`git`'s `archive_name` defaults to `${PACKAGE}-${VERSION}.tar.gz` if
omitted. `vendor`'s default is **not** analogous -- `${PACKAGE}-vendor.tar.gz`,
with no version and always gzip -- so a pipeline that wants a versioned
and/or differently-compressed vendor archive (`.tar.bz2`/`.tar.xz`, both
valid, see `gorget/util/archive.py`) must set `archive_name` explicitly.
Nothing cross-checks either default or override against what the spec
file's `Source0`/`SourceN` actually declare, or against `%prep`'s
`%autosetup -n` (which must match the *archive's* internal top-level
directory -- itself just `archive_name` minus its compression suffix, not
the upstream repo's own directory name) -- a mismatch surfaces as a `%prep`
failure several steps removed from the pipeline YAML that caused it.

`vendor`'s `modules` lets one archive combine several submodules (e.g. an
etcd-style repo with independent `server`/`etcdctl`/`etcdutl` Go modules) --
each gets its own labeled top-level directory in the combined archive unless
there's exactly one module with no explicit `name`, which instead produces a
bare `vendor/` at the archive root.

For Maven, gorget runs `mvn dependency:go-offline` with `vendor/` as the local
repository and archives that repository. Maven bumps use
`groupId:artifactId` coordinates. Direct declarations use the Maven Versions
plugin; transitive dependencies get a `dependencyManagement` entry. As with
other `vendor-bump` ecosystems, gorget repacks the source archive after the
edit so its `pom.xml` matches the vendor repository.

**`git` doesn't manage credentials.** It shells out to a plain `git
clone`/`git checkout`, inheriting whatever ambient git configuration the
process invoking gorget already has (a credential helper, an SSH agent, a
`url.insteadOf` rewrite, `.netrc`) -- there's no gorget-level flag or config
field for a token or key. A private `repo:` with no such ambient auth fails
closed with git's own `fatal: could not read Username for '...': terminal
prompts disabled`. See
[Fetch from a private git repo](docs/how-to/fetch-from-a-private-repo.md).

### `transform:`

Runs after `fetch:`, in declared order, against what was already fetched.

| Step | Purpose |
|---|---|
| `strip-tarball` | Derive a tarball with matching paths removed, preserving the acquired input |
| `vendor-bump` | Bump a vendored dependency (direct **or** nested transitive) to a minimum or series-capped version (Go/npm/pnpm/yarn/Cargo/Maven), before a later `vendor` step re-vendors. Transitive deps are forced via the ecosystem's override mechanism (npm `overrides`, pnpm `pnpm-workspace.yaml` overrides, yarn `resolutions`, cargo `--precise`). Plain `version: "0.39.0"` means `>=0.39.0` (no upper bound); tilde `version: "~4.18.2"` means `>=4.18.2` capped to the `4.18.x` series |
| `vendor` | Generate a Go/npm/pnpm/yarn/Cargo/Composer/Maven/Gradle vendor archive from the source workspace |
| `run` | Escape hatch: an arbitrary command, with declared output paths archived as new artifacts afterward |
| `pack` | Archive an explicit list of files already in `--package-dir` into a single deterministic tarball, each at its own relative path |

For compatibility, gorget still accepts `vendor` entries under `fetch:` and
moves them before the declared transform steps. This syntax is deprecated;
new and updated pipelines should declare vendoring under `transform:`.

Transforms use a Git checkout when one is active. Otherwise, they extract the
sole fetched source archive. A `vendor` step can select an archive by its output
name through `source`, including when fetch also downloads signatures or keys:

```yaml
fetch:
  - type: url
    url: "https://example.org/project-${VERSION}.tar.gz"
  - type: url
    url: "https://example.org/project-${VERSION}.tar.gz.asc"
transform:
  - type: vendor
    ecosystem: cargo
    source: "project-${VERSION}.tar.gz"
    modules:
      - path: "project-${VERSION}"
```

Downloaded archives retain their internal layout. Their module paths include the
archive's top-level directory. Git checkouts use paths relative to the checkout.
A source switch rejects uncommitted workspace changes. A `run` step's `target`
selects a detached archive extraction without changing the active source.

Go bumps apply all pending pins before one `go mod tidy` per module. Bump checks
use `GOWORK=off`, so workspace version selection cannot hide stale requirements
in an individual module. Native bumps update Source0's module metadata; use
`sync-go-modules` for metadata changes made by the later Go vendor step.

Yarn uses Node to invoke a checked-in release when `.yarnrc.yml` declares
`yarnPath`. Dependency bumps remove conflicting resolutions before setting a
package-wide constraint. Berry lockfile updates keep transient install state
outside Source0. Vendor cache generation disables dependency build scripts.

Cargo uses its existing dependency requirements to resolve updates. An
incompatible transitive requirement can prevent a requested version from
replacing an older copy. Gorget rejects the remaining version violation.

`run:`'s `outputs:` archives files/directories whose name is known upfront.
For a name only known once the command runs (e.g. a version string it
discovered from the source tree), declare `discovered-outputs:` instead: a
manifest file (relative to the step's cwd) the command writes, one
`<output_name>\t<path>` pair per line:

```yaml
transform:
  - type: run
    target: "node-v22.9.0.tar.gz"
    command: ["./discover-icu-version.sh"]
    discovered-outputs: "discovered.tsv"   # each line: "<output_name>\t<path>"
```

`run:`'s `artifacts:` materializes publication artifacts' raw, unextracted
bytes into the step's cwd (the same idiom as `post:`'s `artifacts:` below).
Use it when a script needs the archive itself rather than `target:`'s
extracted view.

For Gradle, gorget runs the configured `task` (default: `build`) with
`GRADLE_USER_HOME` set to `vendor/`, then archives the populated Gradle user
home. It uses `./gradlew` when the project includes the Gradle wrapper and
otherwise uses `gradle`. For example, Gradle's own source tree should use its
distribution task:

```yaml
transform:
  - type: vendor
    ecosystem: gradle
    task: ":distributions-full:binDistributionZip"
```

A later build can use the extracted directory as `GRADLE_USER_HOME` and pass
`--offline`. Gradle then fails if the build needs a dependency that the first
build did not resolve.

Set optional `max-workers` to a positive integer to limit Gradle workers.
Use one worker when concurrent Scala tasks contend for a cold Zinc compiler
cache. Without this field, Gradle keeps its default worker limit.

Retain a Gradle build file with `outputs` to use it in a later post step.
Paths are relative to the vendor workspace root, including any module path.
Each path or glob must select exactly one file inside that workspace. Missing
files, multiple matches, escaping symlinks, and duplicate artifact names fail
the pipeline. Source0 stays unchanged.

```yaml
transform:
  - type: vendor
    ecosystem: gradle
    task: releaseTarGz
    max-workers: 1
    archive-name: "kafka-${VERSION}-gradle-vendor.tar.gz"
    outputs:
      - path: "core/build/distributions/kafka_*-${VERSION}.tgz"
        name: "kafka-${VERSION}-runtime.tgz"
post:
  - type: run
    artifacts: ["kafka-${VERSION}-runtime.tgz"]
    command: ["./generate-bundled-provides.sh", "kafka-${VERSION}-runtime.tgz"]
publish:
  files:
    - "kafka-${VERSION}.tar.gz"
    - "kafka-${VERSION}-gradle-vendor.tar.gz"
```

The post script consumes the first build's runtime archive. The explicit
`publish` list excludes that intermediate archive from the sources manifest.
Without `publish`, Gorget publishes all artifacts as before. Dry runs plan the
retained artifact names without running Gradle or reading build files.

### `verify:`

Runs after `transform:`. Validates integrity/authenticity of what was
fetched, before Policy and Emit.

| Step | Purpose |
|---|---|
| `gpg-signature` | Verify a detached GPG signature against a keyring in the GPG keys directory (`--gpg-keys-dir`) |
| `checksum-file` | Verify an artifact's digest against an entry in a fetched checksums-listing file (e.g. `SHASUMS256.txt`) |

```yaml
verify:
  - type: gpg-signature
    target: "foo-1.2.3.tar.gz"        # output_name of an already-fetched artifact
    signature: "foo-1.2.3.tar.gz.asc"  # output_name of the fetched detached signature
    keyring: "example-project.asc"      # filename within --gpg-keys-dir

  - type: checksum-file
    target: "foo-1.2.3.tar.gz"
    checksums-file: "SHASUMS256.txt"    # output_name of the fetched checksums listing
    algorithm: sha256                    # sha256 (default) | sha512 | sha1 | md5
```

Unlike `transform:`'s `strip-tarball`, there is no auto-select fallback when
`target`/`signature`/`checksums-file` are omitted -- guessing wrong on a
security check is worse than on a convenience transform, so all three are
required.

`gpg-signature` imports the keyring into a fresh, throwaway GPG homedir per
check (`gpg --homedir <tmp> --import ... && gpg --homedir <tmp> --verify
...`) rather than using `--keyring` directly, for robustness across keyring
formats and modern GPG's keybox-format quirks.

**Re-publication detection runs automatically whenever a `sources` file
exists in the package directory** -- no `verify:` step needed to opt in, since it's the core
supply-chain safety net: every freshly-fetched artifact whose filename is
already recorded in `sources` has its checksum recomputed (at whichever
digest algorithm the existing entry uses) and compared, failing closed if
upstream silently republished a same-named file with different content. A
package with neither an existing `sources` file nor any declared `verify:`
steps gets a non-blocking "no verification configured" warning instead.

All verification failures across all checks -- re-publication and declared
`verify:` steps alike -- are aggregated into one error rather than stopping
at the first failure, so a single run surfaces everything wrong at once.
`report.json`'s `verify` stage includes a `details` list with the per-check
type/target/status/reason.

### `publish:`

Selects the exact artifact filenames that Emit writes to `--output-dir` and
the `sources` manifest. The order in `files` is preserved.

```yaml
publish:
  files:
    - "${PACKAGE}-${VERSION}.tar.gz"
    - "${PACKAGE}-${VERSION}-vendor.tar.xz"
```

Gorget fails if a listed file was not produced or appears more than once.
Produced files that are not listed remain available to earlier stages, but
Emit does not write them. An explicit empty list emits an empty `sources`
manifest.

Pipelines without `publish:` keep the previous behavior and emit every
produced artifact. Gorget logs a deprecation warning for this compatibility
mode. A later release will require the section.

### `accepted-checksums:`

A top-level section, sibling to `fetch`/`transform`/`verify`/`toolchain`,
for explicitly accepting a re-publication that re-publication detection
would otherwise fail closed on:

```yaml
accepted-checksums:
  - file: "foo-1.2.3.tar.gz"
    checksum: "f871e5f8...747749e2"   # the artifact's sha512, from the failure message
    reason: "Upstream re-cut the tarball to fix line endings; verified by hand"
```

Matching against `sources` uses whatever digest algorithm that file already
records, but `accepted-checksums:` entries are always matched against the
artifact's own **sha512** checksum (gorget's standard, and what the failure
message itself prints) -- copy it straight from the error, don't recompute
it separately. Each entry requires a human-authored `reason:`, so accepting
a re-publication always leaves an audit trail rather than silently
suppressing the check.

### Stable artifact names across version updates

Some specs require a stable source filename even though the source is fetched
from a Git tag that advances with every upstream release.  Declare that narrow
case on the Git fetch step:

```yaml
fetch:
  - type: git
    repo: "${UPSTREAM_REPO}"
    ref: "v${VERSION}"
    archive_name: "project-source.tar.gz"
    allow-version-change: true
```

When Gorget is invoked for an actual update (`--old-version` differs from
`--version`), a changed checksum for this artifact is reported as an
`expected-version-change` rather than a re-publication failure. A rerun for
the same version still fails closed if the ref produces different content.
This is not a replacement for `accepted-checksums:`: use that only when the
same intended source was genuinely re-published with different bytes.

### `policy:`

Runs after `verify:`, before Emit. Validates the *final vendored output* --
acts as a safety net for `vendor-bump` (confirms a pin actually took effect)
and catches violations in packages that don't use `vendor-bump` at all. Unlike
`vendor-bump` (a one-time edit), this re-runs on every pipeline execution, so a
later upstream update silently reverting a security fix fails the build
instead of shipping quietly.

```yaml
policy:
  vendor-constraints:
    - package: sanitize-html
      ecosystem: npm        # go | npm | pnpm | yarn | cargo | maven
      version: "2.17.5"      # minimum version -- "at least this version"
      reason: "CVE-2024-XXXXX"

  audit: true                # run Go/npm/Cargo/Maven ecosystem audits
                              # against every vendored module found

  license-compliance:
    disallowed:
      - GPL-3.0-only
      - AGPL-3.0-only
```

| Check | Behavior |
|---|---|
| `vendor-constraints` | Reads resolved versions from Go module queries, JavaScript lockfiles, Cargo.lock, or Maven dependency queries. For npm, pnpm, Yarn, and Cargo, the lowest locked version must meet the declared minimum; a newer copy cannot hide an older copy. Checks every vendored module for that ecosystem automatically -- no per-entry module path needed. Fails closed. |
| `audit` | `go mod verify` checks module cache checksums against `go.sum` -- deterministic, no network, **fails closed**. `npm audit`, `cargo audit`, and Maven's OWASP dependency-check query live vulnerability databases over the network -- non-deterministic (results can change with no code change), so findings are recorded in `report.json` but are **warn-only, never fail closed**. `cargo-audit` must be separately installed on `PATH`. |
| `license-compliance` | Flags a vendored dependency whose declared license is in `disallowed`. Supported for npm (`package.json`'s `license` field) and Cargo (`Cargo.toml`'s `license` field) only -- Go has no standard machine-readable per-module license field, so Go modules get a single "unsupported" warning instead of a fabricated check. |

A package with none of the three configured gets a non-blocking "no policy
configured" skip. All deterministic failures (`vendor-constraints`,
`go mod verify`, `license-compliance`) are aggregated into one error, same as
`verify:`.

### `post:`

Runs after `policy:`, before Emit. The one stage that intentionally writes
into `--package-dir` rather than the scratch work dir -- for metadata that
needs to land in the tracked spec file, e.g. refreshing a generated
`Provides:` block from a vendored dependency manifest.

```yaml
post:
  - type: run
    artifacts: ["${PACKAGE}-${VERSION}.tar.gz"]
    command: ["./generate-bundled-provides.py", "${VERSION}"]
```

Each step's `command` runs with `--package-dir` as its working directory --
which is *not* where fetched/vendored artifacts live (they're in a scratch
work dir until Emit, which runs after Post). A step that needs to read one
declares its `output_name` in `artifacts:`; each is copied into
`--package-dir` under that name immediately before the command runs.

Skipped entirely under `--dry-run` (nothing should write to the real package
directory during a dry run) and when no `post:` steps are declared.

#### `bundled-provides` (built-in primitive)

The canonical `post:` case -- generating an RPM `Provides: bundled(npm(...))`
block for vendored JS dependencies -- is available as a built-in step, so no
custom script is needed. It parses the lockfile(s) in the fetched source tree
and writes one sorted `Provides:` line per dependency.

```yaml
post:
  - type: bundled-provides
    ecosystem: npm          # npm | pnpm | yarn
    modules:
      - path: "ui"          # defaults to [{ path: "." }]
    scope: production       # "production" (default, drops devDependencies) | "all"
    output: bundled-npm-provides.inc
```

It reads `package-lock.json` / `pnpm-lock.yaml` / `yarn.lock` from
`<source>/<module.path>` -- the same checkout `vendor`/`vendor-bump` operate
on, so the provides reflect any `vendor-bump` edits made earlier in the
pipeline. Versions are normalised to RPM form (a semver pre-release
`1.2.3-rc.1` becomes `1.2.3~rc.1`).

The namespace is deliberately fixed to `bundled(npm(<name>))` for **every** JS
ecosystem (npm/pnpm/yarn) and is not configurable. npm/pnpm/yarn all resolve
against the npm registry, so the package name is the stable identifier
regardless of which lockfile produced it. Unlike Go -- where
`go-rpm-macros` auto-generates `bundled(golang(...))` at build time from
`vendor/modules.txt` -- Fedora has no build-time generator for bundled npm
provides and no single blessed string, so gorget standardises on one form
(matching the Bundled Software Policy's `bundled(<system>(<name>))` shape).
Every gorget-packaged JS app emits the same namespace, keeping the block
greppable and consistent across packages.

The file is written into `--package-dir`; pull it into the spec with:

```spec
%include %{SOURCEN}    # e.g. %include %{S:9}, matching its SourceN: entry
```

Requires a materialized source workspace from a Git fetch or an archive-based
transform. For Berry, production scope follows workspace and transitive production
dependencies. Classic Yarn includes all locked dependencies in both scopes.

### `toolchain:`

```yaml
toolchain:
  - name: node      # one of: go, node, npm, cargo, rustc, python, maven, gradle
    version: "24"   # selected version stream; component-wise prefix match
    minimum-version: "24.16"  # optional inclusive version floor
```

Declares per-package tool version requirements for `vendor`/`vendor-bump`/
`run` steps. Before any stage runs (even under `--dry-run`),
gorget activates an installed RPM-native version when the distribution exposes
one through a distinctly named executable, then validates it. Node.js uses
`node-<major>` (and matching `npm-<major>`/`npx-<major>` when installed); Python
uses `python<major>.<minor>`. The temporary aliases apply to the entire pipeline,
including child scripts that use `/usr/bin/env`, and are removed afterward.

Other tools currently validate the ambient executable (e.g. `go version`).
Version matching is component-wise (`1.22` matches `1.22.3`), and a mismatch or
missing tool fails closed. `minimum-version` additionally requires the active
version to be at least the declared numeric version, so a package can select a
stable major stream while enforcing its actual runtime floor. Gorget only
activates absolute `/usr/bin` executables owned by installed RPMs; it never
installs or downloads a toolchain. The required RPM must already be present in
the execution image.

An earlier design shelled out to [`mise`](https://mise.jdx.dev/) to activate
an already-installed version on demand, but that was rejected: mise's job is
downloading toolchain binaries directly from their own upstream release
channels at runtime, which reintroduces exactly the kind of untrusted-source
problem gorget exists to eliminate for source tarballs, just one layer up.
Activation is instead RPM-native with zero mid-pipeline network dependency,
using the same distinctly named binary pattern Fedora already uses for
`python3.9`/`python3.11`/`python3.12` and Hummingbird uses for Node.js.

## CLI flags

| Flag | Description |
|---|---|
| `--version` | New upstream version to fetch (required) |
| `--old-version` | Previous upstream version |
| `--dry-run` | Run through the Policy stage but skip Emit; prints the report to stdout instead |
| `--package-dir` | Package directory (default: `/package`) |
| `--pipeline-file` | Pipeline YAML file (default: `/pipeline.yaml`) |
| `--gpg-keys-dir` | GPG keys directory (default: `/gpg-keys`) |
| `--output-dir` | Output directory (default: `/output`) |
| `--upstream-repo` | Canonical upstream repo URL, exposed as `${UPSTREAM_REPO}` |
| `--debug` | Trace every stage/step transition and subprocess command run (argv, cwd, exit code, stdout/stderr) to stderr |

## Exit codes

| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Transient error (download failure, missing tool, invalid config) |
| 2 | Policy violation |

## Variable substitution

`${VERSION}`, `${VERSION_MAJOR}`, `${VERSION_MINOR}`, `${VERSION_PATCH}`,
`${VERSION_FOURTH}`, `${VERSION_FOURTH_SUFFIX}`, `${VERSION_BUILD}`,
`${OLD_VERSION}`, `${PACKAGE}`, `${SPEC_FILE}`, `${PACKAGE_DIR}`,
`${UPSTREAM_REPO}` are available in any string value in the pipeline YAML.

- `${VERSION_FOURTH}` is the fourth dot-separated component of `${VERSION}`
  (empty if absent). `${VERSION_FOURTH_SUFFIX}` includes its leading dot, or
  is empty when the fourth component is absent or `0`. For an OpenJDK ref,
  `jdk-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${VERSION_FOURTH_SUFFIX}+${VERSION_BUILD}`
  maps `17.0.20.0.8` to `jdk-17.0.20+8` and `17.0.21.1.0` to
  `jdk-17.0.21.1+0`.

- `${PACKAGE_DIR}` is the absolute path to the package's directory (i.e.
  `--package-dir`) -- useful in `run:` step scripts that need to reach files
  living alongside the spec file, such as a patch applied before running a
  build tool.
- `${UPSTREAM_REPO}` is the value passed via `--upstream-repo`, if any --
  useful for pointing `type: git`'s `repo:` at the same canonical URL a
  caller already tracks elsewhere (e.g. its own package metadata), instead
  of duplicating it in the pipeline YAML. Empty string if not passed.

## Local development

For source-workspace ownership, dependency inventories, and adapter contracts,
read [Source workspaces and dependencies](docs/development/source-and-dependencies.md).


```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

gorget --version 1.2.3 \
  --package-dir ./rpms/curl \
  --pipeline-file ./metadata/curl.source-pipeline.yaml \
  --output-dir /tmp/output \
  --dry-run

pytest
ruff check src/ tests/
mypy src/gorget
```

Tests that shell out to a real `rpmspec` are marked `integration` and are
skipped automatically when `rpmspec` isn't on `PATH`.

Run every example under `examples/` in one shot (sets up `.venv` if needed,
runs each demo's setup script, then runs gorget against each pipeline YAML):

```bash
./run-examples.sh
```
