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
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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<version>
# what releasing <version> requires: the core of the xhandler-rust
# release of the same version
# what releasing <version> 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
Expand All @@ -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
Expand Down
80 changes: 57 additions & 23 deletions hack/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,87 @@
# core.sh verify-release <tag> <wasm> <version-file>
# what releasing <tag> requires: the version in <version-file> is the tag's and <wasm> 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 <version> <dir> | verify <wasm> <version-file> | verify-release <tag> <wasm> <version-file>" >&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 <asset> in the SHA256SUMS of release <version>; 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 <url> <file>: 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 <asset> in the SHA256SUMS of release <version>; 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=<version>'"
if [ -z "$expected" ]; then
message="the core $version ($wasm) is not an xhandler-rust release: sync a release with 'make sync CORE=<version>'"
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 <version> <dir> | verify <wasm> <version-file> | verify-release <tag> <wasm> <version-file>" >&2
exit 2
;;
*) usage ;;
esac
Loading