From c632608f663ba037a0a2dbf3b167465da9341693 Mon Sep 17 00:00:00 2001 From: Josui Date: Tue, 17 Nov 2026 14:23:25 +0000 Subject: [PATCH 1/2] fix(ci): release only on "release not found" and an exact CHANGELOG heading release.yml treated every `gh release view` failure as unreleased, so an auth or network error looked like a version to ship, and matched the CHANGELOG heading as a regex, so a version's dots matched any character. The decision moves to scripts/release-version.sh, shellchecked and covered by tests/test_release_version.py against a fake gh. Same fix as crunchtools/rhel10-bootc-workstation 289eee6. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R7Y1jckWHhAgXg2WBwkWbb --- .github/workflows/container.yml | 3 +- .github/workflows/release.yml | 13 +------ CHANGELOG.md | 9 +++++ scripts/release-version.sh | 33 ++++++++++++++++ tests/test_release_version.py | 68 +++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 12 deletions(-) create mode 100755 scripts/release-version.sh create mode 100755 tests/test_release_version.py diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index b583fe3..43f57c7 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -82,8 +82,9 @@ jobs: set -eu podman run --rm -v "$PWD:/mnt:ro,z" -w /mnt \ docker.io/koalaman/shellcheck:v0.11.0 bin/sdlc tests/contract.sh \ - tests/test_host_contract.sh + tests/test_host_contract.sh scripts/release-version.sh tests/test_host_contract.sh + tests/test_release_version.py - name: Build if: env.IS_TAG != 'true' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4cb4530..6aade4f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,17 +33,8 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -eu - v=$(sed -n 's/^version = "\(.*\)"$/\1/p' pyproject.toml | head -1) - [ -n "$v" ] || { echo "pyproject.toml names no version" >&2; exit 1; } - if gh release view "v$v" >/dev/null 2>&1; then - echo "v$v is already released" - echo "tag=" >> "$GITHUB_OUTPUT" - elif grep -q "^## \[$v\]" CHANGELOG.md; then - echo "tag=v$v" >> "$GITHUB_OUTPUT" - else - echo "v$v has no CHANGELOG heading; not releasing" >&2 - exit 1 - fi + tag=$(scripts/release-version.sh) + echo "tag=$tag" >> "$GITHUB_OUTPUT" # The App's token, because a tag created with GITHUB_TOKEN does not start # container.yml, and the release would never be promoted. diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c24c82..aad780e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ All notable changes to this project are documented here, following ## [Unreleased] +### Fixed + +- `release.yml` no longer mistakes a failed `gh release view` (auth, network, + rate limit) for an unreleased version: only `release not found` counts, and + any other failure stops the job. The CHANGELOG heading check is a literal + match, so a version's dots no longer match any character. The decision now + lives in `scripts/release-version.sh`, tested by + `tests/test_release_version.py`. + ## [0.7.3] - 2026-11-17 ### Changed diff --git a/scripts/release-version.sh b/scripts/release-version.sh new file mode 100755 index 0000000..a5b3b13 --- /dev/null +++ b/scripts/release-version.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Print the tag release.yml should cut, or nothing when there is none. +# +# Reads the version from pyproject.toml in the current directory. Prints +# vX.Y.Z when that version has no release yet and CHANGELOG.md has a +# "## [X.Y.Z]" heading, prints nothing when it is already released, and exits +# non-zero for everything else: no version, no heading, or a gh failure other +# than "release not found". An auth or network error must stop the release, +# not read as "unreleased". +set -euo pipefail + +v=$(sed -n 's/^version = "\(.*\)"$/\1/p' pyproject.toml | head -1) +[ -n "$v" ] || { echo "pyproject.toml names no version" >&2; exit 1; } + +if out=$(gh release view "v$v" 2>&1); then + echo "v$v is already released" >&2 + exit 0 +fi +if ! printf '%s\n' "$out" | grep -q 'release not found'; then + printf 'gh release view v%s failed:\n%s\n' "$v" "$out" >&2 + exit 1 +fi + +# A literal match, not a regex: the heading is exactly "## [X.Y.Z]", alone or +# followed by a space, so 0.7.3 matches neither "## [0x7x3]" nor "## [0.7.30]". +if awk -v h="## [$v]" 'index($0, h) == 1 && + (length($0) == length(h) || substr($0, length(h) + 1, 1) == " ") {f = 1} + END {exit !f}' CHANGELOG.md; then + echo "v$v" +else + echo "v$v has no CHANGELOG heading; not releasing" >&2 + exit 1 +fi diff --git a/tests/test_release_version.py b/tests/test_release_version.py new file mode 100755 index 0000000..a1c07f9 --- /dev/null +++ b/tests/test_release_version.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +"""`scripts/release-version.sh` must release only what it is sure of. + +release.yml cuts whatever tag this prints. Two ways it used to get that wrong: +the CHANGELOG heading was matched as a regex, so the dots in a version matched +any character, and every `gh release view` failure counted as "not released", +so an auth or network error looked like a version waiting to ship. This runs +the script against a fake `gh` and asserts each case. + +Run: tests/test_release_version.py (needs python3 and bash) +""" + +from __future__ import annotations + +import os +import subprocess +import tempfile +from pathlib import Path + +SCRIPT = Path(__file__).resolve().parent.parent / "scripts" / "release-version.sh" + +GH_RELEASED = "#!/bin/sh\necho 'title: v0.7.3'\n" +GH_MISSING = "#!/bin/sh\necho 'release not found' >&2\nexit 1\n" +GH_AUTH = "#!/bin/sh\necho 'HTTP 401: Bad credentials' >&2\nexit 1\n" + + +def run(version: str, changelog: str, gh: str) -> tuple[int, str]: + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + (root / "pyproject.toml").write_text(f'[project]\nversion = "{version}"\n') + (root / "CHANGELOG.md").write_text(changelog) + bindir = root / "bin" + bindir.mkdir() + (bindir / "gh").write_text(gh) + (bindir / "gh").chmod(0o755) + env = {**os.environ, "PATH": f"{bindir}{os.pathsep}{os.environ['PATH']}"} + proc = subprocess.run( + [str(SCRIPT)], cwd=root, env=env, capture_output=True, text=True, check=False + ) + return proc.returncode, proc.stdout.strip() + + +CASES = [ + # (name, version, changelog, gh, expected exit, expected stdout) + ("unreleased with heading", "0.7.3", "## [0.7.3] - 2026-11-17\n", GH_MISSING, 0, "v0.7.3"), + ("heading with no date", "0.7.3", "## [0.7.3]\n", GH_MISSING, 0, "v0.7.3"), + ("already released", "0.7.3", "## [0.7.3] - 2026-11-17\n", GH_RELEASED, 0, ""), + ("no heading", "0.7.3", "## [0.7.2] - 2026-11-17\n", GH_MISSING, 1, ""), + ("dots are not wildcards", "0.7.3", "## [0x7x3] - 2026-11-17\n", GH_MISSING, 1, ""), + ("longer version is not a match", "0.7.3", "## [0.7.30] - 2026-11-17\n", GH_MISSING, 1, ""), + ("gh auth failure is not unreleased", "0.7.3", "## [0.7.3] - 2026-11-17\n", GH_AUTH, 1, ""), + ("no version", "", "## [0.7.3]\n", GH_MISSING, 1, ""), +] + + +def main() -> int: + failed = 0 + for name, version, changelog, gh, want_code, want_out in CASES: + code, out = run(version, changelog, gh) + ok = code == want_code and out == want_out + failed += not ok + detail = "" if ok else f" (exit {code}, stdout {out!r})" + print(f"{'ok' if ok else 'FAIL'}: {name}{detail}") + return 1 if failed else 0 + + +if __name__ == "__main__": + raise SystemExit(main()) From d9ef45a1ebdd0afb7a067cab227f282f7c9145c5 Mon Sep 17 00:00:00 2001 From: Josui Date: Tue, 17 Nov 2026 14:25:28 +0000 Subject: [PATCH 2/2] chore: shellcheck scripts/release-version.sh at commit too, as CI does Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R7Y1jckWHhAgXg2WBwkWbb --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61d7d9f..503604c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,8 +34,8 @@ repos: - repo: local hooks: - id: shellcheck - name: shellcheck (bin/sdlc and the tests) - entry: podman --events-backend=none run --rm --log-driver=none -v .:/mnt:ro,z -w /mnt docker.io/koalaman/shellcheck:v0.11.0 bin/sdlc tests/contract.sh tests/test_host_contract.sh + name: shellcheck (bin/sdlc, the tests and scripts) + entry: podman --events-backend=none run --rm --log-driver=none -v .:/mnt:ro,z -w /mnt docker.io/koalaman/shellcheck:v0.11.0 bin/sdlc tests/contract.sh tests/test_host_contract.sh scripts/release-version.sh language: system pass_filenames: false always_run: true