|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Tag the current commit and push the tag. Pushing a `v*` tag is the only |
| 3 | +# supported upload path: `.github/workflows/publish.yml` re-verifies the tag |
| 4 | +# SHA, packs, installs and checks both release artifacts, then publishes to |
| 5 | +# crates.io over OIDC and to npm with provenance. |
| 6 | +# |
| 7 | +# Every check here mirrors one the workflow makes after the tag exists. A tag |
| 8 | +# is effectively single-use for a release, so failing locally is free and |
| 9 | +# failing in CI is not. |
| 10 | +set -euo pipefail |
| 11 | + |
| 12 | +die() { |
| 13 | + printf 'release: %s\n' "$1" >&2 |
| 14 | + exit 1 |
| 15 | +} |
| 16 | + |
| 17 | +branch=$(git branch --show-current) |
| 18 | +[ "$branch" = "main" ] || die "releases run from main, not '$branch'" |
| 19 | +[ -z "$(git status --porcelain)" ] || die "working tree is not clean" |
| 20 | + |
| 21 | +git fetch --quiet origin main |
| 22 | +head=$(git rev-parse HEAD) |
| 23 | +remote=$(git rev-parse origin/main) |
| 24 | +[ "$head" = "$remote" ] || |
| 25 | + die "HEAD ($head) and origin/main ($remote) differ; push or pull first" |
| 26 | + |
| 27 | +# publish.yml pins the tag against all seven of these. |
| 28 | +version=$(node -p "require('./packages/zodrs/package.json').version") |
| 29 | +for pair in \ |
| 30 | + "packages/zodrs/native/package.json:native addon" \ |
| 31 | + "packages/zodrs/wasm/package.json:wasm addon" \ |
| 32 | + "crates/zodrs-node/package.json:node binding" \ |
| 33 | + "crates/zodrs-node/smoke/package.json:node smoke"; do |
| 34 | + manifest=${pair%%:*} |
| 35 | + found=$(node -p "require('./$manifest').version") |
| 36 | + [ "$found" = "$version" ] || die "${pair#*:} is $found, expected $version" |
| 37 | +done |
| 38 | +workspace=$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml","rb"))["workspace"]["package"]["version"])') |
| 39 | +[ "$workspace" = "$version" ] || die "Cargo workspace is $workspace, expected $version" |
| 40 | +crate=$(cargo metadata --format-version 1 --no-deps | |
| 41 | + jq -r '.packages[] | select(.name == "zodrs") | .version') |
| 42 | +[ "$crate" = "$version" ] || die "zodrs crate is $crate, expected $version" |
| 43 | + |
| 44 | +tag="v$version" |
| 45 | +if git rev-parse --verify --quiet "refs/tags/$tag" >/dev/null; then |
| 46 | + die "$tag already exists locally" |
| 47 | +fi |
| 48 | +if [ -n "$(git ls-remote --tags origin "refs/tags/$tag")" ]; then |
| 49 | + die "$tag already exists on origin" |
| 50 | +fi |
| 51 | + |
| 52 | +git tag -a "$tag" -m "$tag" |
| 53 | +git push origin "$tag" |
| 54 | +printf 'release: pushed %s at %s; publish.yml now verifies and uploads\n' "$tag" "$head" |
0 commit comments