diff --git a/release/release-watch.sh b/release/release-watch.sh index 7a0b193b..1e7701d8 100755 --- a/release/release-watch.sh +++ b/release/release-watch.sh @@ -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 diff --git a/release/release.sh b/release/release.sh index 92038c0d..caca1cef 100755 --- a/release/release.sh +++ b/release/release.sh @@ -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}" \ diff --git a/release/wrolpi-release.service b/release/wrolpi-release.service index c71d9c7e..f640f2bf 100644 --- a/release/wrolpi-release.service +++ b/release/wrolpi-release.service @@ -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