From 9eab938dbebb630353cb661ed051f501effd2f8b Mon Sep 17 00:00:00 2001 From: bougyman's bot Date: Sun, 4 Oct 2026 19:20:11 -0400 Subject: [PATCH] feat: Add --version to every command sv-helper and every alias (svls, sv-enable and the rest), rsvlog and runsvdir.sh all take --version. sv-helper also takes a `version` subcommand. Output is GNU style: `sv-helper 4.1.0` by its own name, `svls (sv-helper) 4.1.0` through an alias. Each is answered before anything else runs. rsvlog answers outside a log directory. runsvdir.sh never resolves, creates or supervises a tree. A regular user's svls creates nothing. An installed script has no version.txt beside it, so each script carries its own version, on a line release-please rewrites through the x-release-please-version marker. The scripts and the README's example are added to extra-files. test/version.bats fails if a marked file is missing from extra-files, or holds a version other than version.txt's. Co-Authored-By: Claude Opus 5.5 --- .release-please-config.json | 16 +++++++ README.md | 11 +++++ docs/releasing.md | 12 +++++ rsvlog.sh | 11 +++++ runsvdir.sh | 11 +++++ sv-helper.sh | 27 ++++++++++- test/version.bats | 92 +++++++++++++++++++++++++++++++++++++ 7 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 test/version.bats diff --git a/.release-please-config.json b/.release-please-config.json index c14eea5..6495540 100644 --- a/.release-please-config.json +++ b/.release-please-config.json @@ -12,6 +12,22 @@ { "type": "generic", "path": "PKGBUILD" + }, + { + "type": "generic", + "path": "sv-helper.sh" + }, + { + "type": "generic", + "path": "rsvlog.sh" + }, + { + "type": "generic", + "path": "runsvdir.sh" + }, + { + "type": "generic", + "path": "README.md" } ], "changelog-sections": [ diff --git a/README.md b/README.md index 26866c3..f444965 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,22 @@ only one definition of what "installed" means. sv-stop Stop a running one sv-restart Restart it sv-helper paths Every path this invocation would use + sv-helper version sv-helper's version All of them are the same script, `sv-helper.sh`, dispatching on the name it was called by. `sv-helper paths` is the one to reach for when a service turns up somewhere unexpected. +Every command, `rsvlog` and `runsvdir.sh` included, also takes +`--version`: + + + + $ svls --version + svls (sv-helper) 4.1.0 + + + ## Where things go The invoking user decides the scope. A regular user never gets diff --git a/docs/releasing.md b/docs/releasing.md index c7c313e..2320e01 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -114,6 +114,18 @@ Job permissions are deliberately uneven. The signing job has signs whatever bytes it is handed and must not be able to change the release it is describing. +## Versions in the source + +Each script reports its version with `--version` from its own +`sv_version` line, because an installed script has no `version.txt` +beside it. release-please rewrites every line marked +`x-release-please-version` in the files listed under `extra-files` in +`.release-please-config.json`. That covers the three scripts, `PKGBUILD`, +and the example in the README, which is marked as a block. +`test/version.bats` fails if a marked file is missing from that list or +holds a version other than `version.txt`'s, so a new file with a version +in it cannot be forgotten. + ## Other packaging `PKGBUILD`'s `pkgver` is bumped by release-please along with everything diff --git a/rsvlog.sh b/rsvlog.sh index 2714cfc..cbf8698 100755 --- a/rsvlog.sh +++ b/rsvlog.sh @@ -29,6 +29,17 @@ set -e +# release-please rewrites this line on every release, through the marker. +sv_version=4.1.0 # x-release-please-version + +# Answered before the checks below, which only make sense for the log +# service itself, so the installed command can say what it is. +if [ "$1" = --version ] +then + echo "rsvlog (sv-helper) $sv_version" + exit 0 +fi + if [ "$(basename "$0")" != "run" ] then echo "This script meant to be linked as ./run in a service/log directory only!" >&2 diff --git a/runsvdir.sh b/runsvdir.sh index dd0db4f..fda415d 100755 --- a/runsvdir.sh +++ b/runsvdir.sh @@ -25,6 +25,17 @@ # with $SV_PREFIX, and falls back to "generic". set -e + +# release-please rewrites this line on every release, through the marker. +sv_version=4.1.0 # x-release-please-version + +# Before anything resolves, creates or supervises a tree. +if [ "$1" = --version ] +then + echo "runsvdir.sh (sv-helper) $sv_version" + exit 0 +fi + exec 2>&1 warn() { diff --git a/sv-helper.sh b/sv-helper.sh index bbe2951..790f611 100755 --- a/sv-helper.sh +++ b/sv-helper.sh @@ -17,6 +17,9 @@ set -e +# release-please rewrites this line on every release, through the marker. +sv_version=4.1.0 # x-release-please-version + commands="sv-list svls sv-find sv-enable sv-disable sv-start sv-stop sv-restart" sv_uname=$(uname -s) @@ -307,6 +310,19 @@ make_links() { done } +# GNU style: the package alone when called by its own name, and the alias +# with the package beside it otherwise, so `svls --version` says which +# package svls belongs to. +print_version() { + name=$1 + if [ "$name" = sv-helper ] || [ "$name" = sv-helper.sh ] + then + echo "sv-helper $sv_version" + else + echo "$name (sv-helper) $sv_version" + fi +} + # Every path this invocation would use, for diagnosing a surprising default. paths() { printf 'uname: %s\n' "$sv_uname" @@ -329,8 +345,9 @@ usage() { sv-list) echo "sv-list - List available services" ;; make-links) echo "make-links - Deprecated; use ./install.sh" ;; paths) echo "paths - Show the service, definition and log paths this invocation resolves" ;; + version) echo "version - Show sv-helper's version (every command also takes --version)" ;; commands) - echo "Valid Commands: ${commands} paths make-links" + echo "Valid Commands: ${commands} paths version make-links" echo "use command -h for help" ;; *) echo "Invalid command (${commands})" ;; @@ -353,6 +370,14 @@ then fi fi +# The version, like help, has to work before any service directory exists, +# and from every alias: `svls --version` as much as `sv-helper version`. +if [ "$cmd" = version ] || [ "$cmd" = --version ] || [ "$1" = --version ] +then + print_version "$(basename "$0")" + exit 0 +fi + # Help must work before any service directory exists, so it is answered # before anything resolves a path. while getopts h options diff --git a/test/version.bats b/test/version.bats new file mode 100644 index 0000000..60c5363 --- /dev/null +++ b/test/version.bats @@ -0,0 +1,92 @@ +#!/usr/bin/env bats +# --version on every command, and the guard that keeps it honest: each +# script carries its own copy of the version, rewritten by release-please, +# so a script left out of its extra-files would quietly report an old one. + +setup() { + load 'test_helper/common' + load 'test_helper/sv' + common_setup + VERSION=$(cat "$REPO_ROOT/version.txt") + export VERSION +} + +@test "sv-helper --version and sv-helper version" { + run "$REPO_ROOT/sv-helper.sh" --version + assert_success + assert_output "sv-helper $VERSION" + + run "$REPO_ROOT/sv-helper.sh" version + assert_success + assert_output "sv-helper $VERSION" +} + +@test "every alias takes --version and names its package" { + local name + for name in svls sv-list sv-find sv-enable sv-disable sv-start sv-stop sv-restart + do + ln -s "$REPO_ROOT/sv-helper.sh" "$TEST_TMP/$name" + run "$TEST_TMP/$name" --version + assert_success + assert_output "$name (sv-helper) $VERSION" + done +} + +@test "rsvlog --version works outside a log directory" { + cd "$TEST_TMP" + run "$REPO_ROOT/rsvlog.sh" --version + assert_success + assert_output "rsvlog (sv-helper) $VERSION" +} + +@test "runsvdir.sh --version answers without creating or supervising a tree" { + local home="$TEST_TMP/home" + mkdir -p "$home" + + run as_user "$home" "$REPO_ROOT/runsvdir.sh" --version + assert_success + assert_output "runsvdir.sh (sv-helper) $VERSION" + refute [ -e "$home/.local" ] +} + +@test "svls --version needs no service directory" { + # A regular user's tree is created on demand, and a version query is + # not a demand. + local home="$TEST_TMP/home" + mkdir -p "$home" + ln -s "$REPO_ROOT/sv-helper.sh" "$TEST_TMP/svls" + + run as_user "$home" "$TEST_TMP/svls" --version + assert_success + refute [ -e "$home/.local" ] +} + +@test "every file with a release-please version marker is in its extra-files" { + local file missing="" + while IFS= read -r file + do + if ! grep -Fq "\"path\": \"$file\"" "$REPO_ROOT/.release-please-config.json" + then + missing="$missing $file" + fi + done < <(git -C "$REPO_ROOT" grep -l 'x-release-please-' -- ':!test/*' ':!docs/*' ':!CHANGELOG.md') + + assert_equal "$missing" "" +} + +@test "every version marker carries the current version" { + # Catches a file added to extra-files after a release, still holding + # whatever version it was written with. + local line found stale="" + while IFS= read -r line + do + found=$(printf '%s\n' "$line" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) + if [ "$found" != "$VERSION" ] + then + stale="$stale +$line" + fi + done < <(git -C "$REPO_ROOT" grep -n 'x-release-please-version' -- ':!test/*' ':!docs/*' ':!CHANGELOG.md') + + assert_equal "$stale" "" +}