Skip to content

Latest commit

 

History

History
154 lines (117 loc) · 7.57 KB

release_prefix.md

File metadata and controls

154 lines (117 loc) · 7.57 KB

release_prefix.sh

Revision: 1 Last modified: 2026-12-04T17:48:16Z

Overview

Resolves the project's release/tag prefix — the <PREFIX> in <PREFIX>-<version> (§11.4.151).

It is the single source of truth for that naming. Every release-tag-creating or version-naming script, in the main repo and in every owned submodule, is required to obtain its prefix from here so that one release shares one prefix and is greppable across every repo:

git tag -l "$(scripts/release_prefix.sh)-*"

Run it (or source it) when: you are about to name a tag or a version and need the prefix without hardcoding it.

Prerequisites

  • bash, git (optional — used to find the project root; a no-git fallback exists).
  • Nothing else. No permissions, no network, no writes.

Resolution order (closed set, deterministic — §11.4.6)

# Source Notes
1 HELIX_RELEASE_PREFIX in the environment Authoritative when set
2 HELIX_RELEASE_PREFIX in the git-ignored project-root .env Parsed, never sourced — a hostile .env cannot execute code (§11.4.10). Quotes are stripped; whitespace trimmed
3 Fallback: lowercased snake_case of the project-root directory name (§11.4.29) Always resolvable from the checkout, no operator input

Env vars (NAMES only): HELIX_RELEASE_PREFIX, HELIX_PROJECT_ROOT.

HELIX_PROJECT_ROOT is an explicit override for a layout the automatic resolution cannot handle. It wins over every tier only when it names an existing, readable and searchable (-x) directory. An invalid value prints a warning and falls through — it is not silently ignored (§11.4.6).

Usage examples

# As a command
prefix="$(bash scripts/release_prefix.sh)"

# Sourced (no subprocess; useful in loops)
. scripts/release_prefix.sh
prefix="$(helix_release_prefix)"

# In a tag name
git tag -a "$(bash scripts/release_prefix.sh)-1.0.0" -m "Release 1.0.0"

# List this project's tags
git tag -l "$(bash scripts/release_prefix.sh)-*"

# Explicit override for an unusual layout
HELIX_PROJECT_ROOT=/srv/checkouts/thing bash scripts/release_prefix.sh

Real output from this checkout on 2026-12-04 (a worktree whose directory name is a session id, so tier 3 fired):

$ bash scripts/release_prefix.sh
pi_agent_2f2d6f42_3ec9_435_5164e256
$ echo $?
0

That is tier 3 in action — the directory name slugged to snake_case. In a normal project (~/Projects/thing) the same command prints thing, and with HELIX_RELEASE_PREFIX=atmosphere in the environment it prints atmosphere.

Exit codes

Code Meaning
0 Prefix printed on stdout (never empty)
1 Genuinely unresolvable root — release_prefix: cannot resolve a prefix (no HELIX_RELEASE_PREFIX, no .env value, empty root name) on stderr

Non-zero happens only for a genuinely unresolvable root: a directed error, never a guess (§11.4.6).

Edge cases

  • Sourcing vs running. The last line checks [ "${BASH_SOURCE[0]:-$0}" = "${0}" ]; when sourced it defines helix_release_prefix and prints nothing. Sourcing a command substitution to get a subprocess is a common mistake — pick one.

  • Project-root resolution is anchored to this file's own location, never the caller's cwd. This is a fixed defect, and the reason matters:

    • the old primary mechanism ran git rev-parse --show-toplevel in the caller's cwd. Inside a nested constitution/ submodule (which has its own .git) that returns the submodule's toplevel, so the project's .env is never found and the prefix silently degrades to the directory name;
    • from a directory with no git repo at all, the old fallback was one level short.

    Both produced the wrong prefix depending purely on where the caller happened to run — which a downstream consumer read through to a correctly-tagged dispatch being wrongly refused.

  • Two layouts are both supported and had to be reconciled:

    • EMBEDDED — constitution/ is a nested git submodule of a consuming project: git -C "$self_dir" rev-parse --show-superproject-working-tree returns the consuming project's root.
    • STANDALONE — constitution/ is cloned as its own top-level repo: --show-toplevel correctly returns that repo's own root, so .env.example's documented helix_constitution fallback holds. A fixed "two levels up" would have landed above a standalone clone and picked up the containing directory's name.
  • Unregistered nested constitution/. A constitution/ with its own .git but no formal gitlink registration would otherwise be treated as standalone. The script widens to the parent only when basename "$root" is literally constitution and the parent carries real evidence: a .env that genuinely contains a HELIX_RELEASE_PREFIX= assignment (verified through the same parser tier 2 uses — file existence alone is not enough), or a .gitmodules line exactly path = constitution.

  • An unreadable or content-irrelevant parent .env does not widen. A parent with only API_KEY=x does not widen. A chmod 000 .env does not widen. A clone named HelixConstitution under an unrelated workspace/ does not widen.

  • HELIX_PROJECT_ROOT set to a readable-but-not-searchable directory (chmod 444) warns and falls through, rather than passing validation and then failing on cd with empty stdout.

  • Snake_case fallback examples: HelixConstitution → helix_constitution; My App → my_app; pi_agent_2f2d6f42_… → unchanged (already snake_case).

Internal behaviour

  1. helix_release_prefix checks tier 1 (HELIX_RELEASE_PREFIX in the environment) and returns it.
  2. Otherwise _hrp_project_root resolves the root, in this order: HELIX_PROJECT_ROOT (validated -d/-r/-x, warned and skipped when invalid) → git -C "$self_dir" rev-parse --show-superproject-working-tree (embedded layout) → git -C "$self_dir" rev-parse --show-toplevel (standalone, with the gated widen-to-parent heuristic) → $self_dir/.. (not inside any git repository at all: an unpacked tarball, a bare file copy).
  3. Tier 2: _hrp_from_env_file "$root/.env" — greps the last HELIX_RELEASE_PREFIX assignment (ignoring comments), trims whitespace, strips a matching pair of quotes. Never sources it.
  4. Tier 3: _hrp_snake_case "$(basename "$root")" — camelCase→snake, non-alnum→_, lowercase, squeeze/trim.
  5. An empty result is an error (exit 1) with a message naming all three missing sources.

Related scripts

  • scripts/release_tag.sh — the primary consumer; builds <PREFIX>-<version> from this. docs/scripts/release_tag.md.
  • scripts/release.sh / scripts/release/release_all.sh — the release pipeline, which also names versions.
  • scripts/update_constitution.sh — reads remote helixconstitution-v* release tags.
  • constitution/.env.example — documents the HELIX_RELEASE_PREFIX variable and the standalone fallback.
  • scripts/lib/constitution_layout.sh — layout resolution used by the update/install scripts.
  • §11.4.151 (project-prefixed naming), §11.4.29 (snake_case), §11.4.6 (no guessing), §11.4.10 (never source .env).

Last verified

2026-12-04 — bash -n clean, and the read-only command executed for real (it writes nothing):

$ bash -n scripts/release_prefix.sh && echo PARSE-OK
PARSE-OK

$ bash scripts/release_prefix.sh; echo "RC=$?"
pi_agent_2f2d6f42_3ec9_435_5164e256
RC=0

The printed value is tier 3 applied to this worktree's directory name. To see tier 1 instead:

$ HELIX_RELEASE_PREFIX=demo bash scripts/release_prefix.sh
demo