|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Bump core-tier package versions across the monorepo. |
| 5 | +# See VERSIONING.md for the versioning policy. |
| 6 | +# |
| 7 | +# Usage: |
| 8 | +# ./scripts/version-bump.sh [--dry-run] <version> |
| 9 | +# |
| 10 | +# Examples: |
| 11 | +# ./scripts/version-bump.sh 1.0.0 |
| 12 | +# ./scripts/version-bump.sh --dry-run 1.0.0 |
| 13 | + |
| 14 | +DRY_RUN=false |
| 15 | +VERSION="" |
| 16 | + |
| 17 | +for arg in "$@"; do |
| 18 | + case "$arg" in |
| 19 | + --dry-run) DRY_RUN=true ;; |
| 20 | + -*) echo "Unknown flag: $arg" >&2; exit 1 ;; |
| 21 | + *) VERSION="$arg" ;; |
| 22 | + esac |
| 23 | +done |
| 24 | + |
| 25 | +if [[ -z "$VERSION" ]]; then |
| 26 | + echo "Usage: version-bump.sh [--dry-run] <version>" >&2 |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 31 | + echo "Error: version must be in semver format (e.g. 1.0.0)" >&2 |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 36 | + |
| 37 | +# Files to update and the sed pattern for each. |
| 38 | +# Format: file:pattern |
| 39 | +TARGETS=( |
| 40 | + # Cargo workspace (covers allium-parser and allium via workspace inheritance) |
| 41 | + "Cargo.toml:s/^version = \"[0-9]*\.[0-9]*\.[0-9]*\"/version = \"$VERSION\"/" |
| 42 | + |
| 43 | + # Root package.json |
| 44 | + "package.json" |
| 45 | + |
| 46 | + # Core-tier npm packages |
| 47 | + "packages/allium-cli/package.json" |
| 48 | + "packages/allium-lsp/package.json" |
| 49 | + "packages/tree-sitter-allium/package.json" |
| 50 | +) |
| 51 | + |
| 52 | +update_json_version() { |
| 53 | + local file="$1" |
| 54 | + local full_path="$ROOT/$file" |
| 55 | + |
| 56 | + if [[ ! -f "$full_path" ]]; then |
| 57 | + echo " SKIP $file (not found)" |
| 58 | + return |
| 59 | + fi |
| 60 | + |
| 61 | + local current |
| 62 | + current=$(grep -m1 '"version"' "$full_path" | sed 's/.*"version": *"\([^"]*\)".*/\1/') |
| 63 | + |
| 64 | + if [[ "$current" == "$VERSION" ]]; then |
| 65 | + echo " OK $file (already $VERSION)" |
| 66 | + return |
| 67 | + fi |
| 68 | + |
| 69 | + if $DRY_RUN; then |
| 70 | + echo " WOULD $file: $current -> $VERSION" |
| 71 | + else |
| 72 | + sed -i '' "s/\"version\": *\"$current\"/\"version\": \"$VERSION\"/" "$full_path" |
| 73 | + echo " SET $file: $current -> $VERSION" |
| 74 | + fi |
| 75 | +} |
| 76 | + |
| 77 | +update_cargo_version() { |
| 78 | + local file="$1" |
| 79 | + local full_path="$ROOT/$file" |
| 80 | + |
| 81 | + if [[ ! -f "$full_path" ]]; then |
| 82 | + echo " SKIP $file (not found)" |
| 83 | + return |
| 84 | + fi |
| 85 | + |
| 86 | + local current |
| 87 | + current=$(grep -m1 '^version' "$full_path" | sed 's/.*"\([^"]*\)".*/\1/') |
| 88 | + |
| 89 | + if [[ "$current" == "$VERSION" ]]; then |
| 90 | + echo " OK $file (already $VERSION)" |
| 91 | + return |
| 92 | + fi |
| 93 | + |
| 94 | + if $DRY_RUN; then |
| 95 | + echo " WOULD $file: $current -> $VERSION" |
| 96 | + else |
| 97 | + sed -i '' "s/^version = \"$current\"/version = \"$VERSION\"/" "$full_path" |
| 98 | + echo " SET $file: $current -> $VERSION" |
| 99 | + fi |
| 100 | +} |
| 101 | + |
| 102 | +echo "Core-tier version bump -> $VERSION" |
| 103 | +if $DRY_RUN; then |
| 104 | + echo "(dry run — no files will be modified)" |
| 105 | +fi |
| 106 | +echo "" |
| 107 | + |
| 108 | +# Cargo workspace |
| 109 | +update_cargo_version "Cargo.toml" |
| 110 | + |
| 111 | +# npm packages |
| 112 | +update_json_version "package.json" |
| 113 | +update_json_version "packages/allium-cli/package.json" |
| 114 | +update_json_version "packages/allium-lsp/package.json" |
| 115 | +update_json_version "packages/tree-sitter-allium/package.json" |
| 116 | + |
| 117 | +echo "" |
| 118 | +echo "Done. Editor-tier packages (allium-vscode, allium-mode, nvim-allium) are not touched." |
| 119 | +echo "Bump those manually if needed." |
0 commit comments