From 9e13fa7a3b18cdbd8cf9a70d9431935b9438deac Mon Sep 17 00:00:00 2001 From: Santiago Date: Sat, 21 Nov 2026 13:44:37 -0300 Subject: [PATCH 1/4] feat: publish the Helm charts as OCI packages on release A version tag now packages both charts and pushes each to oci://ghcr.io/txpipe/charts/ at its own chart version, skipping any version the registry already holds. Pull requests package the charts and fail when a chart changed since the newest release tag without a version bump. Shell tests cover the version check in a throwaway repository and the push against a local registry. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publisher-release.yml | 38 ++++++++++++++++++++ docs/publisher-packaging.md | 10 ++++++ k8s/check-chart-versions.sh | 30 ++++++++++++++++ k8s/check-chart-versions.test.sh | 45 +++++++++++++++++++++++ k8s/dolos-publisher/README.md | 9 +++++ k8s/package-charts.sh | 21 +++++++++++ k8s/push-charts.sh | 47 +++++++++++++++++++++++++ k8s/push-charts.test.sh | 46 ++++++++++++++++++++++++ k8s/registry/README.md | 9 +++++ 9 files changed, 255 insertions(+) create mode 100755 k8s/check-chart-versions.sh create mode 100755 k8s/check-chart-versions.test.sh create mode 100755 k8s/package-charts.sh create mode 100755 k8s/push-charts.sh create mode 100755 k8s/push-charts.test.sh diff --git a/.github/workflows/publisher-release.yml b/.github/workflows/publisher-release.yml index 4a3db98..cc98b27 100644 --- a/.github/workflows/publisher-release.yml +++ b/.github/workflows/publisher-release.yml @@ -64,10 +64,48 @@ jobs: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: persist-credentials: false + # The version check compares against the newest release tag. + fetch-depth: 0 - uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0 with: version: v3.17.3 - run: k8s/dolos-publisher/test.sh + - name: Package the charts + run: k8s/package-charts.sh "$RUNNER_TEMP/charts" + - name: Test the chart version check + run: k8s/check-chart-versions.test.sh + - name: Test the chart push against a local registry + run: k8s/push-charts.test.sh + - name: Check changed charts bumped their version + if: github.event_name == 'pull_request' + env: + BASE_REF: ${{ github.base_ref }} + run: k8s/check-chart-versions.sh "$(git describe --tags --abbrev=0 --match 'v*' "origin/$BASE_REF")" + + charts: + name: Publish charts + if: startsWith(github.ref, 'refs/tags/v') + needs: [chart] + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + persist-credentials: false + - uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0 + with: + version: v3.17.3 + - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Package the charts + run: k8s/package-charts.sh "$RUNNER_TEMP/charts" + - name: Push chart versions not yet published + run: k8s/push-charts.sh "$RUNNER_TEMP/charts" publish: name: Publish multi-architecture image diff --git a/docs/publisher-packaging.md b/docs/publisher-packaging.md index e5c3294..f5a0120 100644 --- a/docs/publisher-packaging.md +++ b/docs/publisher-packaging.md @@ -82,6 +82,16 @@ distinct, explicit decisions. `gh attestation verify oci://ghcr.io/txpipe/stelae-publisher@sha256: --repo txpipe/stelae`. Operations selects the tested image for a separate deployment. +5. The same tag publishes the charts under `oci://ghcr.io/txpipe/charts/`: + `dolos-publisher` and `stelae-registry`. Each is published at its own + `Chart.yaml` `version:`, independent of the workspace version, and only + once: a version the registry already holds is skipped, never replaced. A + pull request that changes a chart since the newest release tag must bump + that chart's version, or the chart check fails. +6. The first push of a chart creates a private package. The organization + owner makes it public by hand in the package settings; later versions + inherit that visibility. + Pull requests and branch-based manual runs only build and test. A manual run on a version tag follows the same publication path as a tag push. The workflow does not create GitHub Releases, tags, or deployments. diff --git a/k8s/check-chart-versions.sh b/k8s/check-chart-versions.sh new file mode 100755 index 0000000..5329d9d --- /dev/null +++ b/k8s/check-chart-versions.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Fail for each chart whose files differ from while its Chart.yaml +# version does not. Run inside the repository; a chart absent at +# passes. +set -eu + +if [ $# -ne 1 ]; then + echo "usage: $0 " >&2 + exit 2 +fi +BASE=$1 +cd "$(git rev-parse --show-toplevel)" + +failed=0 +for chart in k8s/dolos-publisher/chart k8s/registry/chart; do + if git diff --quiet "$BASE" -- "$chart"; then + continue + fi + if ! base_yaml=$(git show "$BASE:$chart/Chart.yaml" 2>/dev/null); then + continue + fi + base_version=$(printf '%s\n' "$base_yaml" | sed -n 's/^version: *//p') + version=$(sed -n 's/^version: *//p' "$chart/Chart.yaml") + name=$(sed -n 's/^name: *//p' "$chart/Chart.yaml") + if [ "$version" = "$base_version" ]; then + echo "$name: $chart changed since $BASE but its version is still $version" >&2 + failed=1 + fi +done +exit "$failed" diff --git a/k8s/check-chart-versions.test.sh b/k8s/check-chart-versions.test.sh new file mode 100755 index 0000000..c63bae6 --- /dev/null +++ b/k8s/check-chart-versions.test.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# check-chart-versions.sh in a throwaway repository: a changed chart with an +# unchanged version fails, a bumped version passes, an untouched chart passes. +set -eu + +CHECK=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)/check-chart-versions.sh +REPO=$(mktemp -d) +trap 'rm -rf "$REPO"' EXIT +cd "$REPO" + +git init -q +git config user.email test@example.invalid +git config user.name test +for chart in dolos-publisher registry; do + mkdir -p "k8s/$chart/chart/templates" + printf 'apiVersion: v2\nname: %s\nversion: 0.1.0\n' "$chart" >"k8s/$chart/chart/Chart.yaml" + echo 'kind: ConfigMap' >"k8s/$chart/chart/templates/configmap.yaml" +done +git add k8s +git commit -q -m base +git tag v0.1.0 + +# Untouched charts pass. +"$CHECK" v0.1.0 + +# A changed template with the same version fails and names its chart. +echo 'data: {}' >>k8s/dolos-publisher/chart/templates/configmap.yaml +git commit -q -am "change a template" +if "$CHECK" v0.1.0 2>"$REPO/err"; then + echo "a changed chart with an unchanged version passed" >&2 + exit 1 +fi +grep -F 'dolos-publisher:' "$REPO/err" +if grep -F 'stelae-registry' "$REPO/err" || grep -F 'registry:' "$REPO/err"; then + echo "the untouched chart was reported" >&2 + exit 1 +fi + +# A bumped version passes; the other chart stays untouched. +sed -i.bak 's/^version: 0.1.0$/version: 0.1.1/' k8s/dolos-publisher/chart/Chart.yaml +rm k8s/dolos-publisher/chart/Chart.yaml.bak +git commit -q -am "bump the chart" +"$CHECK" v0.1.0 + +echo "check-chart-versions: ok" diff --git a/k8s/dolos-publisher/README.md b/k8s/dolos-publisher/README.md index 1abc667..69b0975 100644 --- a/k8s/dolos-publisher/README.md +++ b/k8s/dolos-publisher/README.md @@ -9,6 +9,15 @@ The chart runs a publisher built on the Dolos v2 configuration: `dolosToml` is a v2 file keeping full history. There is no host selector. The directory and chart name stay `dolos-publisher` to preserve release and object naming. +## Getting the chart + +A release publishes the chart as an OCI package at its own `version:`. Pull +or install a pinned version without a checkout: + +```sh +helm pull oci://ghcr.io/txpipe/charts/dolos-publisher --version +``` + ## Rendered resources - ConfigMap `-config`, mounted at `/etc/publisher`, carries diff --git a/k8s/package-charts.sh b/k8s/package-charts.sh new file mode 100755 index 0000000..359f755 --- /dev/null +++ b/k8s/package-charts.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# Package every Stelae chart into at its own Chart.yaml version and +# print " " for each. +set -eu + +ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) + +if [ $# -ne 1 ]; then + echo "usage: $0 " >&2 + exit 2 +fi +OUT=$1 +mkdir -p "$OUT" + +for chart in "$ROOT"/k8s/dolos-publisher/chart "$ROOT"/k8s/registry/chart; do + helm package "$chart" --destination "$OUT" >/dev/null + name=$(sed -n 's/^name: *//p' "$chart/Chart.yaml") + version=$(sed -n 's/^version: *//p' "$chart/Chart.yaml") + test -f "$OUT/$name-$version.tgz" + echo "$name $version" +done diff --git a/k8s/push-charts.sh b/k8s/push-charts.sh new file mode 100755 index 0000000..306619f --- /dev/null +++ b/k8s/push-charts.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# Push every chart package in to the chart registry, skipping any +# version the registry already holds: a published version is never replaced. +# STELAE_CHART_REGISTRY overrides the registry root and STELAE_CHART_PLAIN_HTTP=1 +# talks to it over plain HTTP; both exist for tests. +set -eu + +REGISTRY=${STELAE_CHART_REGISTRY:-oci://ghcr.io/txpipe/charts} + +if [ $# -ne 1 ]; then + echo "usage: $0 " >&2 + exit 2 +fi +OUT=$1 + +set -- +if [ "${STELAE_CHART_PLAIN_HTTP:-}" = 1 ]; then + set -- --plain-http +fi + +found=0 +for package in "$OUT"/*.tgz; do + test -f "$package" || continue + found=1 + name=$(helm show chart "$package" | sed -n 's/^name: *//p') + version=$(helm show chart "$package" | sed -n 's/^version: *//p') + if error=$(helm show chart "$@" "$REGISTRY/$name" --version "$version" 2>&1 >/dev/null); then + echo "$name $version: already published, skipped" + continue + fi + # Only a missing version is pushed; any other lookup failure stops here, + # since pushing then could replace a version the lookup failed to see. + case $error in + *"not found"* | *"NOT_FOUND"* | *"MANIFEST_UNKNOWN"* | *"NAME_UNKNOWN"*) ;; + *) + echo "$name $version: cannot tell whether it is published: $error" >&2 + exit 1 + ;; + esac + helm push "$@" "$package" "$REGISTRY" + echo "$name $version: published" +done + +if [ "$found" = 0 ]; then + echo "no chart packages in $OUT" >&2 + exit 1 +fi diff --git a/k8s/push-charts.test.sh b/k8s/push-charts.test.sh new file mode 100755 index 0000000..8090d44 --- /dev/null +++ b/k8s/push-charts.test.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# push-charts.sh against a local OCI registry: the first run publishes every +# chart, the second skips each one and exits 0. +set -eu + +K8S=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +IMAGE=${STELAE_TEST_REGISTRY_IMAGE:-public.ecr.aws/docker/library/registry:2} +OUT=$(mktemp -d) +container= +cleanup() { + if [ -n "$container" ]; then docker rm -f "$container" >/dev/null; fi + rm -rf "$OUT" +} +trap cleanup EXIT + +container=$(docker run -d -p 127.0.0.1::5000 "$IMAGE") +port=$(docker port "$container" 5000/tcp | sed -n '1s/.*://p') +for attempt in $(seq 30); do + curl -fsS "http://127.0.0.1:$port/v2/" >/dev/null 2>&1 && break + if [ "$attempt" = 30 ]; then + echo "the local registry did not start" >&2 + exit 1 + fi + sleep 1 +done + +export STELAE_CHART_REGISTRY="oci://127.0.0.1:$port/charts" +export STELAE_CHART_PLAIN_HTTP=1 + +"$K8S/package-charts.sh" "$OUT/charts" >"$OUT/packaged" +count=$(grep -c '' "$OUT/packaged") + +"$K8S/push-charts.sh" "$OUT/charts" >"$OUT/first" +cat "$OUT/first" +test "$(grep -c ': published$' "$OUT/first")" = "$count" + +"$K8S/push-charts.sh" "$OUT/charts" >"$OUT/second" +cat "$OUT/second" +test "$(grep -c ': already published, skipped$' "$OUT/second")" = "$count" + +while read -r name version; do + helm show chart --plain-http "$STELAE_CHART_REGISTRY/$name" --version "$version" | + grep -Fx "version: $version" +done <"$OUT/packaged" + +echo "push-charts: ok" diff --git a/k8s/registry/README.md b/k8s/registry/README.md index 65fdd6a..e90bb49 100644 --- a/k8s/registry/README.md +++ b/k8s/registry/README.md @@ -75,6 +75,15 @@ Render and install are the operator's responsibility. `templates/NOTES.txt` prints the smoke test: a `401` on `/v2/`, a sub-second blob `HEAD`, and a `307` on a blob `GET`. +## Getting the chart + +A release publishes the chart as an OCI package at its own `version:`. Pull +or install a pinned version without a checkout: + +```sh +helm pull oci://ghcr.io/txpipe/charts/stelae-registry --version +``` + ## The interim image zot v2.1.17–v2.1.20 resolve a blob `HEAD`'s Content-Type by walking the From c2329abe8c122e346956a81d9e3e38c1ecbd8b36 Mon Sep 17 00:00:00 2001 From: Santiago Date: Sat, 21 Nov 2026 13:46:14 -0300 Subject: [PATCH 2/4] test: pull the push test's registry from GHCR with backoff Co-Authored-By: Claude Opus 5.5 --- k8s/push-charts.test.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/k8s/push-charts.test.sh b/k8s/push-charts.test.sh index 8090d44..2cd0fdc 100755 --- a/k8s/push-charts.test.sh +++ b/k8s/push-charts.test.sh @@ -4,7 +4,8 @@ set -eu K8S=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) -IMAGE=${STELAE_TEST_REGISTRY_IMAGE:-public.ecr.aws/docker/library/registry:2} +# zot from GHCR: ECR Public throttles anonymous pulls from shared runner IPs. +IMAGE=${STELAE_TEST_REGISTRY_IMAGE:-ghcr.io/project-zot/zot:v2.1.20} OUT=$(mktemp -d) container= cleanup() { @@ -13,6 +14,15 @@ cleanup() { } trap cleanup EXIT +# A failed pull is infrastructure, not a finding: back off and try again. +for attempt in 1 2 3 4 5; do + docker pull --quiet "$IMAGE" >/dev/null && break + if [ "$attempt" = 5 ]; then + echo "cannot pull $IMAGE" >&2 + exit 1 + fi + sleep $((attempt * 15)) +done container=$(docker run -d -p 127.0.0.1::5000 "$IMAGE") port=$(docker port "$container" 5000/tcp | sed -n '1s/.*://p') for attempt in $(seq 30); do From b29ca2d2f6bc8c3f048b02b49400875b6e264db7 Mon Sep 17 00:00:00 2001 From: Santiago Date: Sat, 21 Nov 2026 13:58:59 -0300 Subject: [PATCH 3/4] ci: recheck chart versions against the previous release before pushing --- .github/workflows/publisher-release.yml | 4 ++++ docs/publisher-packaging.md | 5 ++++- k8s/check-chart-versions.test.sh | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publisher-release.yml b/.github/workflows/publisher-release.yml index cc98b27..48d38a0 100644 --- a/.github/workflows/publisher-release.yml +++ b/.github/workflows/publisher-release.yml @@ -94,9 +94,13 @@ jobs: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: persist-credentials: false + # The version check compares against the previous release tag. + fetch-depth: 0 - uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0 with: version: v3.17.3 + - name: Check charts changed since the previous release bumped their version + run: k8s/check-chart-versions.sh "$(git describe --tags --abbrev=0 --match 'v*' HEAD^)" - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 with: registry: ghcr.io diff --git a/docs/publisher-packaging.md b/docs/publisher-packaging.md index f5a0120..e1963d3 100644 --- a/docs/publisher-packaging.md +++ b/docs/publisher-packaging.md @@ -87,7 +87,10 @@ distinct, explicit decisions. `Chart.yaml` `version:`, independent of the workspace version, and only once: a version the registry already holds is skipped, never replaced. A pull request that changes a chart since the newest release tag must bump - that chart's version, or the chart check fails. + that chart's version, or the chart check fails. The release repeats that + check against the previous release tag before it pushes, so a change that + reached the branch without a bump fails the release instead of going + unpublished. 6. The first push of a chart creates a private package. The organization owner makes it public by hand in the package settings; later versions inherit that visibility. diff --git a/k8s/check-chart-versions.test.sh b/k8s/check-chart-versions.test.sh index c63bae6..b44b13e 100755 --- a/k8s/check-chart-versions.test.sh +++ b/k8s/check-chart-versions.test.sh @@ -42,4 +42,19 @@ rm k8s/dolos-publisher/chart/Chart.yaml.bak git commit -q -am "bump the chart" "$CHECK" v0.1.0 +# At release time, a change that landed without a bump after the previous +# release fails against the tag the release job resolves. +git tag v0.1.1 +echo 'kind: Secret' >k8s/registry/chart/templates/secret.yaml +git add k8s/registry/chart/templates/secret.yaml +git commit -q -m "add a template without a bump" +git tag v0.1.2 +previous=$(git describe --tags --abbrev=0 --match 'v*' HEAD^) +test "$previous" = v0.1.1 +if "$CHECK" "$previous" 2>"$REPO/err"; then + echo "an unbumped change since the previous release passed" >&2 + exit 1 +fi +grep -F 'registry:' "$REPO/err" + echo "check-chart-versions: ok" From 5e19e688175ff2e3d838d9892ef5256d1adcb787 Mon Sep 17 00:00:00 2001 From: Santiago Date: Sat, 21 Nov 2026 14:09:20 -0300 Subject: [PATCH 4/4] ci: resolve the previous release by version, not ancestry The release recheck used `git describe HEAD^`, which skips a release tagged on a commit the branch does not reach, such as one squash-merged through a release PR. k8s/previous-release-tag.sh picks the highest v* tag below the one being released, and the chart version test covers a release tagged off the branch. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publisher-release.yml | 2 +- docs/publisher-packaging.md | 4 ++- k8s/check-chart-versions.test.sh | 44 +++++++++++++++++++++++-- k8s/previous-release-tag.sh | 22 +++++++++++++ 4 files changed, 67 insertions(+), 5 deletions(-) create mode 100755 k8s/previous-release-tag.sh diff --git a/.github/workflows/publisher-release.yml b/.github/workflows/publisher-release.yml index 48d38a0..2393536 100644 --- a/.github/workflows/publisher-release.yml +++ b/.github/workflows/publisher-release.yml @@ -100,7 +100,7 @@ jobs: with: version: v3.17.3 - name: Check charts changed since the previous release bumped their version - run: k8s/check-chart-versions.sh "$(git describe --tags --abbrev=0 --match 'v*' HEAD^)" + run: k8s/check-chart-versions.sh "$(k8s/previous-release-tag.sh "$GITHUB_REF_NAME")" - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4 with: registry: ghcr.io diff --git a/docs/publisher-packaging.md b/docs/publisher-packaging.md index e1963d3..500fa2f 100644 --- a/docs/publisher-packaging.md +++ b/docs/publisher-packaging.md @@ -90,7 +90,9 @@ distinct, explicit decisions. that chart's version, or the chart check fails. The release repeats that check against the previous release tag before it pushes, so a change that reached the branch without a bump fails the release instead of going - unpublished. + unpublished. The previous release is the highest `v*` tag below the one + being released, even when it was tagged on a commit the branch does not + reach, as a squash-merged release PR leaves it. 6. The first push of a chart creates a private package. The organization owner makes it public by hand in the package settings; later versions inherit that visibility. diff --git a/k8s/check-chart-versions.test.sh b/k8s/check-chart-versions.test.sh index b44b13e..1bdd41a 100755 --- a/k8s/check-chart-versions.test.sh +++ b/k8s/check-chart-versions.test.sh @@ -1,9 +1,13 @@ #!/bin/sh # check-chart-versions.sh in a throwaway repository: a changed chart with an -# unchanged version fails, a bumped version passes, an untouched chart passes. +# unchanged version fails, a bumped version passes, an untouched chart passes, +# and at release time previous-release-tag.sh finds the tag to check against, +# even when that release was tagged off the branch. set -eu -CHECK=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)/check-chart-versions.sh +HERE=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +CHECK=$HERE/check-chart-versions.sh +PREVIOUS=$HERE/previous-release-tag.sh REPO=$(mktemp -d) trap 'rm -rf "$REPO"' EXIT cd "$REPO" @@ -49,12 +53,46 @@ echo 'kind: Secret' >k8s/registry/chart/templates/secret.yaml git add k8s/registry/chart/templates/secret.yaml git commit -q -m "add a template without a bump" git tag v0.1.2 -previous=$(git describe --tags --abbrev=0 --match 'v*' HEAD^) +previous=$("$PREVIOUS" v0.1.2) test "$previous" = v0.1.1 +if "$PREVIOUS" v0.1.0 2>/dev/null; then + echo "the first release resolved a previous release" >&2 + exit 1 +fi if "$CHECK" "$previous" 2>"$REPO/err"; then echo "an unbumped change since the previous release passed" >&2 exit 1 fi grep -F 'registry:' "$REPO/err" +# A release tagged on a side commit, then squashed onto the branch as an +# identical commit, is still the previous release of the next tag. +main=$(git symbolic-ref --short HEAD) +git checkout -q -b release +sed -i.bak 's/^version: 0.1.1$/version: 0.1.2/' k8s/dolos-publisher/chart/Chart.yaml +rm k8s/dolos-publisher/chart/Chart.yaml.bak +echo 'data: {}' >>k8s/dolos-publisher/chart/templates/configmap.yaml +git commit -q -am "release: v0.1.3" +git tag v0.1.3 +git checkout -q "$main" +git checkout v0.1.3 -- k8s +git commit -q -m "release: v0.1.3 (squash)" +test -z "$(git diff v0.1.3 HEAD)" +if git merge-base --is-ancestor v0.1.3 HEAD; then + echo "the side release is reachable from the branch" >&2 + exit 1 +fi +echo 'data: {}' >>k8s/dolos-publisher/chart/templates/configmap.yaml +git commit -q -am "change the chart without a bump" +git tag v0.1.4 +# Ancestry alone would resolve v0.1.2, where the version differs, and pass. +test "$(git describe --tags --abbrev=0 --match 'v*' HEAD^)" = v0.1.2 +previous=$("$PREVIOUS" v0.1.4) +test "$previous" = v0.1.3 +if "$CHECK" "$previous" 2>"$REPO/err"; then + echo "an unbumped change since a release tagged off the branch passed" >&2 + exit 1 +fi +grep -F 'dolos-publisher:' "$REPO/err" + echo "check-chart-versions: ok" diff --git a/k8s/previous-release-tag.sh b/k8s/previous-release-tag.sh new file mode 100755 index 0000000..a108a8e --- /dev/null +++ b/k8s/previous-release-tag.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Print the highest v* tag ordered below by version, whether or not the +# branch reaches its commit: a release tagged off the branch still counts. +# Fail when is not a tag or no earlier release exists. +set -eu + +if [ $# -ne 1 ]; then + echo "usage: $0 " >&2 + exit 2 +fi +TAG=$1 + +if ! git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then + echo "$TAG is not a tag" >&2 + exit 1 +fi +previous=$(git tag --list 'v*' --sort=-v:refname | awk -v tag="$TAG" 'seen { print; exit } $0 == tag { seen = 1 }') +if [ -z "$previous" ]; then + echo "no release tag precedes $TAG" >&2 + exit 1 +fi +echo "$previous"