diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6d233a3..eaed31f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,6 +31,8 @@ XHANDLER_E2E=true uv run pytest tests/test_e2e.py # crea, firma y envía una fa conformidad (`testdata/conformance/`). No los edites a mano. La versión del paquete es la del núcleo, y una versión solo se publica con el núcleo de la versión igual de xhandler-rust: `make verify-core` lo comprueba. + Estos comandos descargan el `core.sh` de xhandler-rust (`xhandler-wasm/core.sh`) del tag del + núcleo; `CORE_SH=` usa una copia local, p. ej. al cambiarlo allá. - En Python está lo que necesita IO: el cliente HTTP (httpx), los reintentos y el caché de tokens (`src/xhandler/xsender/`). - Los nombres (`FileSender`, `SunatClient`, `SigningKey`...) se mantienen iguales en Go, Python y diff --git a/Makefile b/Makefile index 8202989..716ef00 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,17 @@ DIST := $(if $(CORE),.dist,$(RUST_REPO)/dist) SYNCED := src/xhandler/_core/xhandler.wasm src/xhandler/_core/VERSION src/xhandler/xbuilder/models.py testdata/conformance +# core.sh syncs and verifies a released core. It lives in xhandler-rust, next to the release +# format it reads, and is downloaded from the tag of the core at hand (from main for a core +# released before it was there, or not released). CORE_SH= runs a local copy instead, e.g. +# while changing it in xhandler-rust. +CORE_SH ?= +CORE_SH_URL := https://raw.githubusercontent.com/project-openubl/xhandler-rust +# $(call core_sh,,) +core_sh = $(if $(CORE_SH),bash $(CORE_SH) $(2),script=$$(mktemp) && trap 'rm -f "$$script"' EXIT && \ + { curl -fsSL -o "$$script" $(CORE_SH_URL)/v$(1)/xhandler-wasm/core.sh 2>/dev/null || \ + curl -fsSL -o "$$script" $(CORE_SH_URL)/main/xhandler-wasm/core.sh; } && bash "$$script" $(2)) + .PHONY: sync dist verify-core verify-release test lint sync: dist @@ -27,14 +38,14 @@ dist: ifeq ($(CORE),) $(MAKE) -C $(RUST_REPO)/xhandler-wasm dist else - ./hack/core.sh download $(CORE) $(DIST) + $(call core_sh,$(CORE:v%=%),download $(CORE) $(DIST)) endif verify-core: - ./hack/core.sh verify src/xhandler/_core/xhandler.wasm src/xhandler/_core/VERSION + $(call core_sh,$$(tr -d '\r\n' &2; \ diff --git a/hack/core.sh b/hack/core.sh deleted file mode 100755 index b78452b..0000000 --- a/hack/core.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bash -# The xhandler core (xhandler.wasm, its models and the conformance corpus) comes from the -# releases of xhandler-rust, which attach xhandler-dist-.tar.gz, xhandler.wasm and -# SHA256SUMS. This script is identical in xhandler-go, xhandler-python and xhandler-java. -# -# core.sh download -# extracts the release's dist into -# core.sh verify -# checks that is the xhandler.wasm released as the version in ; a -# version that was never released (a core built from a checkout) only warns -# 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 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) - [ $# -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 - 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=$(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 - [ -z "$tag" ] || die "$message" - echo "warning: $message" >&2 - elif [ "$(sha256 "$wasm")" != "$expected" ]; then - 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 - ;; -*) usage ;; -esac