release: address Greptile review + add opaque notify hook

Greptile (PR #448):
- C1 (P1): release-watch.sh compared the GitHub tag (minus 'v') against the
  manifest's .version (from version.txt content). If a tag and its version.txt
  ever diverged, the guard never matched and it rebuilt every hour forever.
  Compare the manifest's .tag against the release tag directly -- exact and
  immune to version-string formatting. Drops the now-unused normalize().
- C2 (P2): document that .tag is the built git ref (release tag for automated
  builds, branch for manual) and that consumers use .version for display.
- C3 (P2): document that newest-by-publish-date is the intended trigger and
  that prereleases are deliberately included (every release is -beta), so we
  do not filter on .prerelease as suggested.

Also add an optional completion notify hook: release.sh invokes
$WROLPI_RELEASE_NOTIFY with a success/failure message (no-op if unset, skipped
on dry-run). The public script names no path or tool; the real notifier stays
on the host (commented Environment= placeholder in the service unit).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roland 2026-05-30 14:11:09 -06:00
parent 0e3564b704
commit 30550f4c5b
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 43 additions and 13 deletions

View file

@ -34,28 +34,31 @@ mkdir -p "${STATE_DIR}"
log() { echo "[release-watch] $*"; }
# Normalize a release tag to a version string (drop a leading 'v').
normalize() { echo "${1#v}"; }
# Newest non-draft release tag (includes prereleases / -beta). Read-only and
# unauthenticated; the public 60 req/hr limit is irrelevant at hourly cadence.
# Newest non-draft release tag. GitHub's /releases list is ordered by creation
# date, so [0] is the most recently *published* release -- exactly the trigger
# we want. Prereleases (-beta) are intentionally included (every WROLPi release
# is a prerelease), so we deliberately do NOT filter on `.prerelease`. Read-only
# and unauthenticated; the 60 req/hr public limit is irrelevant at hourly cadence.
LATEST_TAG=$(curl -fsSL -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${REPO}/releases" \
| jq -r '[.[] | select(.draft == false)][0].tag_name // empty')
[ -n "${LATEST_TAG}" ] || { log "No releases found; nothing to do."; exit 0; }
# What is already published? A missing manifest (404) means "nothing yet".
PUBLISHED_VERSION=$(curl -fsSL "${CDN_BASE}/latest.json" 2>/dev/null \
| jq -r '.version // empty' || true)
# What is already built? release.sh records the git ref it built in the
# manifest's `.tag`. Compare that directly against the release tag: it is an
# exact match and immune to any divergence between a tag name and the
# version.txt content it carries. (Comparing versions could loop forever -- a
# build that succeeds but whose .version never equals the tag would rebuild
# every hour.) A missing manifest (404) means "nothing built yet".
PUBLISHED_TAG=$(curl -fsSL "${CDN_BASE}/latest.json" 2>/dev/null \
| jq -r '.tag // empty' || true)
LATEST_VERSION=$(normalize "${LATEST_TAG}")
if [ "${LATEST_VERSION}" = "${PUBLISHED_VERSION}" ]; then
log "Up to date (published v${PUBLISHED_VERSION}); nothing to do."
if [ "${PUBLISHED_TAG}" = "${LATEST_TAG}" ]; then
log "Up to date (published ${LATEST_TAG}); nothing to do."
exit 0
fi
log "New release ${LATEST_TAG} (published: ${PUBLISHED_VERSION:-none})."
log "New release ${LATEST_TAG} (published: ${PUBLISHED_TAG:-none})."
# Skip a tag that has already failed MAX_RETRIES times -- needs a human.
if [ -f "${FAIL_STATE}" ]; then

View file

@ -64,11 +64,32 @@ S3CMD=(s3cmd)
log() { echo "[release] $*"; }
die() { echo "[release] ERROR: $*" >&2; exit 1; }
# Optional completion hook. Set WROLPI_RELEASE_NOTIFY to a command that accepts
# a single message argument; it is invoked on success and on failure. Unset by
# default, so this public script names no notifier and no path.
notify() {
[ -n "${WROLPI_RELEASE_NOTIFY:-}" ] || return 0
"${WROLPI_RELEASE_NOTIFY}" "$1" || true
}
# Report the outcome via the notify hook (skipped for dry runs). Installed
# only after the version resolves, so help/early-exit paths stay silent.
on_exit() {
local rc=$?
[ "${DRY_RUN}" -eq 1 ] && return
if [ "${rc}" -eq 0 ]; then
notify "WROLPi v${VERSION} released -- ${CDN_BASE}/latest.json"
else
notify "WROLPi release FAILED (exit ${rc}) for v${VERSION:-?}"
fi
}
# Resolve the version straight from the target ref so the artifact names match
# the code that gets built.
VERSION=$(curl -fsSL "https://raw.githubusercontent.com/${REPO}/${REF}/wrolpi/version.txt" | tr -d '[:space:]')
[ -n "${VERSION}" ] || die "Could not fetch version from ref '${REF}'"
log "Releasing WROLPi v${VERSION} (ref: ${REF})"
trap on_exit EXIT
ISO="${REPO_DIR}/debian-live-config/WROLPi-v${VERSION}-amd64.iso"
IMG="${REPO_DIR}/pi-gen/WROLPi-v${VERSION}-aarch64-desktop.img.xz"
@ -105,6 +126,9 @@ IMG_NAME=$(basename "${IMG}")
RELEASED=$(date -u +%Y-%m-%dT%H:%M:%SZ)
# Build latest.json. jq -n keeps the values properly escaped/typed.
# `.tag` is the git ref that was built: a release tag for automated builds
# (release-watch.sh compares it to decide what is already published) or a
# branch name for manual runs. Use `.version` for a display version.
MANIFEST=$(jq -n \
--arg version "${VERSION}" \
--arg tag "${REF}" \

View file

@ -28,5 +28,8 @@ StateDirectory=wrolpi-release
Environment=STATE_DIR=/var/lib/wrolpi-release
# Uncomment if the s3cmd config is not at /root/.s3cfg:
#Environment=S3CFG=/home/wrolpi/.s3cfg
# Optional: command to notify on release success/failure (gets one message arg).
# Keep the real path here on the host -- it is intentionally not in the repo.
#Environment=WROLPI_RELEASE_NOTIFY=/home/wrolpi/bin/notify
# A full release builds two images and can run for hours.
TimeoutStartSec=0