diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 36e02b4..0fbe18b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,6 +15,9 @@ on: required: true type: string +# release-tools finds the run of a release by this name +run-name: Release ${{ github.event.release.tag_name || inputs.tag }} + permissions: contents: read diff --git a/Makefile b/Makefile index caba9ff..8202989 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,16 @@ # make sync a checkout of xhandler-rust (RUST_REPO), for development # make verify-core checks that the committed core is the one released as its VERSION # make verify-release TAG=v -# what releasing requires: the core of the xhandler-rust -# release of the same version +# what releasing requires: syncing the xhandler-rust +# release of the same version changes nothing # # The package version is the core's (src/xhandler/_core/VERSION). RUST_REPO ?= ../xhandler-rust CORE ?= DIST := $(if $(CORE),.dist,$(RUST_REPO)/dist) +SYNCED := src/xhandler/_core/xhandler.wasm src/xhandler/_core/VERSION src/xhandler/xbuilder/models.py testdata/conformance + .PHONY: sync dist verify-core verify-release test lint sync: dist @@ -33,6 +35,12 @@ verify-core: verify-release: ./hack/core.sh verify-release $(TAG) src/xhandler/_core/xhandler.wasm src/xhandler/_core/VERSION + $(MAKE) --no-print-directory sync CORE=$(TAG:v%=%) + @if [ -n "$$(git status --porcelain -- $(SYNCED))" ]; then \ + echo "error: the core differs from the xhandler-rust $(TAG) release (now synced here):" >&2; \ + git status --short -- $(SYNCED) >&2; \ + exit 1; \ + fi test: uv run pytest diff --git a/hack/core.sh b/hack/core.sh index 4f7462c..b78452b 100755 --- a/hack/core.sh +++ b/hack/core.sh @@ -11,53 +11,87 @@ # core.sh verify-release # what releasing requires: the version in is the tag's and is # the xhandler.wasm of that xhandler-rust release +# +# A release that can't be read (network, GitHub errors) is an error, never "not released". +# XHANDLER_RUST_RELEASES replaces the releases URL (for tests). set -euo pipefail releases=${XHANDLER_RUST_RELEASES:-https://github.com/project-openubl/xhandler-rust/releases/download} +# The versions release-tools releases +version_re='^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.[0-9]+)?$' +die() { + echo "error: $*" >&2 + exit 1 +} +usage() { + echo "usage: core.sh download | verify | verify-release " >&2 + exit 2 +} sha256() { if command -v sha256sum >/dev/null; then sha256sum "$1"; else shasum -a 256 "$1"; fi | cut -d' ' -f1; } -# The checksum of in the SHA256SUMS of release ; empty if there is none -released_sha256() { curl -fsSL "$releases/v$1/SHA256SUMS" 2>/dev/null | awk -v asset="$2" '$2 == asset {print $1}' || true; } +# The version in a VERSION file, without a Windows line ending +read_version() { tr -d '\r\n' <"$1"; } + +# fetch : 0 when downloaded, 1 when the release has no such file (404); any other +# failure stops the script +fetch() { + local status + status=$(curl -sSL -o "$2" -w '%{http_code}' "$1") || die "cannot download $1" + case "$status" in + 200) return 0 ;; + 404) return 1 ;; + *) die "cannot download $1: HTTP $status" ;; + esac +} + +# The checksum of in the SHA256SUMS of release ; empty if it was never released +# (or not sealed yet: SHA256SUMS goes last) +released_sha256() { + local sums + sums=$(mktemp) + if fetch "$releases/v$1/SHA256SUMS" "$sums"; then + awk -v asset="$2" '$2 == asset {print $1}' "$sums" + fi + rm -f "$sums" +} case "${1:-}" in download) - version=$2 dir=$3 asset="xhandler-dist-$2.tar.gz" + [ $# -eq 3 ] || usage + version=${2#v} dir=$3 asset="xhandler-dist-${2#v}.tar.gz" + [[ "$version" =~ $version_re ]] || die "$2 is not a release version (X.Y.Z or X.Y.Z-alpha.N, -beta.N, -rc.N)" + expected=$(released_sha256 "$version" "$asset") + [ -n "$expected" ] || die "xhandler-rust v$version is not released (no SHA256SUMS with $asset)" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT - curl -fsSL -o "$tmp/$asset" "$releases/v$version/$asset" - if [ "$(sha256 "$tmp/$asset")" != "$(released_sha256 "$version" "$asset")" ]; then - echo "error: $asset does not match the SHA256SUMS of xhandler-rust v$version" >&2 - exit 1 - fi + fetch "$releases/v$version/$asset" "$tmp/$asset" || die "xhandler-rust v$version has no $asset" + [ "$(sha256 "$tmp/$asset")" = "$expected" ] || die "$asset does not match the SHA256SUMS of xhandler-rust v$version" rm -rf "$dir" && mkdir -p "$dir" && tar -xzf "$tmp/$asset" -C "$dir" ;; verify | verify-release) if [ "$1" = verify-release ]; then + [ $# -eq 4 ] || usage tag=$2 shift + else + [ $# -eq 3 ] || usage + tag="" fi - wasm=$2 version=$(cat "$3") - if [ -n "${tag:-}" ] && [ "v$version" != "$tag" ]; then - echo "error: the core is $version, not ${tag#v}: run make sync CORE=${tag#v}" >&2 - exit 1 + wasm=$2 version=$(read_version "$3") + if [ -n "$tag" ]; then + [ "v$version" = "$tag" ] || die "the core is $version, not ${tag#v}: run make sync CORE=${tag#v}" + [[ "$version" =~ $version_re ]] || die "$tag is not a release version (vX.Y.Z or vX.Y.Z-alpha.N, -beta.N, -rc.N)" fi expected=$(released_sha256 "$version" xhandler.wasm) + message="the core $version ($wasm) is not an xhandler-rust release: sync a release with 'make sync CORE='" if [ -z "$expected" ]; then - message="the core $version ($wasm) is not an xhandler-rust release: sync a release with 'make sync CORE='" - if [ -n "${tag:-}" ]; then - echo "error: $message" >&2 - exit 1 - fi + [ -z "$tag" ] || die "$message" echo "warning: $message" >&2 elif [ "$(sha256 "$wasm")" != "$expected" ]; then - echo "error: $wasm is not the xhandler.wasm of xhandler-rust v$version" >&2 - exit 1 + die "$wasm is not the xhandler.wasm of xhandler-rust v$version" else echo "$wasm is the xhandler.wasm of xhandler-rust v$version" fi ;; -*) - echo "usage: core.sh download | verify | verify-release " >&2 - exit 2 - ;; +*) usage ;; esac