Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,22 @@ only one definition of what "installed" means.
sv-stop <service> Stop a running one
sv-restart <service> 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`:

<!-- x-release-please-start-version -->

$ svls --version
svls (sv-helper) 4.1.0

<!-- x-release-please-end -->

## Where things go

The invoking user decides the scope. A regular user never gets
Expand Down
12 changes: 12 additions & 0 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions rsvlog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions runsvdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
27 changes: 26 additions & 1 deletion sv-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -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})" ;;
Expand All @@ -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
Expand Down
92 changes: 92 additions & 0 deletions test/version.bats
Original file line number Diff line number Diff line change
@@ -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" ""
}
Loading