|
| 1 | +#!/usr/bin/env bash |
| 2 | +# bump.sh — bump rpr version in pyproject.toml and npm/package.json in lockstep. |
| 3 | +# |
| 4 | +# Usage: |
| 5 | +# scripts/bump.sh 0.2.0 |
| 6 | +# |
| 7 | +# Does NOT commit, tag, or push — just edits the two files so you can review |
| 8 | +# the diff and open a PR. The release workflow runs on merge to main and |
| 9 | +# detects the new version automatically. |
| 10 | + |
| 11 | +set -euo pipefail |
| 12 | + |
| 13 | +if [ "$#" -ne 1 ]; then |
| 14 | + echo "usage: $0 <version>" >&2 |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +new="$1" |
| 19 | + |
| 20 | +# PEP 440 / semver-ish: MAJOR.MINOR.PATCH with optional pre/post/dev suffix. |
| 21 | +if ! [[ "$new" =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-zA-Z0-9.+-]*)?$ ]]; then |
| 22 | + echo "error: '$new' is not a valid version (expected MAJOR.MINOR.PATCH[suffix])" >&2 |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +repo_root=$(git rev-parse --show-toplevel) |
| 27 | +cd "$repo_root" |
| 28 | + |
| 29 | +current=$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml","rb"))["project"]["version"])') |
| 30 | +echo "Current version: $current" |
| 31 | +echo "New version: $new" |
| 32 | + |
| 33 | +if [ "$current" = "$new" ]; then |
| 34 | + echo "Already at $new — nothing to do." |
| 35 | + exit 0 |
| 36 | +fi |
| 37 | + |
| 38 | +# pyproject.toml — surgical replace of the project.version line. |
| 39 | +NEW="$new" python3 - <<'PY' |
| 40 | +import os, pathlib, re |
| 41 | +p = pathlib.Path("pyproject.toml") |
| 42 | +s = p.read_text() |
| 43 | +s, n = re.subn(r'^version\s*=\s*"[^"]+"', |
| 44 | + f'version = "{os.environ["NEW"]}"', |
| 45 | + s, count=1, flags=re.M) |
| 46 | +if n != 1: |
| 47 | + raise SystemExit("error: could not find 'version = ...' line in pyproject.toml") |
| 48 | +p.write_text(s) |
| 49 | +PY |
| 50 | + |
| 51 | +# npm/package.json — preserve 2-space indent and trailing newline. |
| 52 | +NEW="$new" node -e ' |
| 53 | +const fs = require("fs"); |
| 54 | +const p = "npm/package.json"; |
| 55 | +const j = JSON.parse(fs.readFileSync(p, "utf8")); |
| 56 | +j.version = process.env.NEW; |
| 57 | +fs.writeFileSync(p, JSON.stringify(j, null, 2) + "\n"); |
| 58 | +' |
| 59 | + |
| 60 | +echo |
| 61 | +echo "Updated:" |
| 62 | +echo " pyproject.toml" |
| 63 | +echo " npm/package.json" |
| 64 | +echo |
| 65 | +echo "Next steps:" |
| 66 | +echo " git checkout -b release/v$new" |
| 67 | +echo " git commit -am \"Release v$new\"" |
| 68 | +echo " gh pr create --fill" |
0 commit comments