Files
nuwiki/scripts/set-version.sh
T

58 lines
2.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# scripts/set-version.sh — stamp a release version into every hardcoded spot.
#
# This is the single source of truth for *where* the version lives. The
# release pipeline (.gitea/workflows/release.yaml) calls it with the
# workflow-dispatch input; run it the same way to prepare a release by hand:
#
# scripts/set-version.sh 0.4.0
#
# It rewrites:
# 1. Cargo.toml — [workspace.package] version
# 2. crates/nuwiki-lsp/Cargo.toml — nuwiki-core path-dep version pin
# 3. crates/nuwiki-ls/Cargo.toml — nuwiki-lsp path-dep version pin
# 4. plugin/nuwiki.vim — g:nuwiki_version (the Lua client reads it too)
# 5. Cargo.lock — the version of our three own crates
#
# Cargo.lock is patched directly (awk) so this needs no cargo/toolchain —
# the only thing that changes for our crates is their version string.
set -euo pipefail
ver="${1:-}"
ver="${ver#v}" # tolerate a leading "v"
if ! printf '%s' "$ver" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$'; then
echo "usage: $0 <semver> e.g. $0 0.4.0" >&2
exit 2
fi
root="$(cd "$(dirname "$0")/.." && pwd)"
cd "$root"
# 1. Workspace package version (root Cargo.toml, [workspace.package]).
sed -i -E "s/^version = \"[0-9][^\"]*\"/version = \"$ver\"/" Cargo.toml
# 2-3. Internal path-dep pins must track the workspace version.
sed -i -E "s|(nuwiki-core = \{ path = \"\.\./nuwiki-core\", version = )\"[^\"]*\"|\1\"$ver\"|" \
crates/nuwiki-lsp/Cargo.toml
sed -i -E "s|(nuwiki-lsp = \{ path = \"\.\./nuwiki-lsp\", version = )\"[^\"]*\"|\1\"$ver\"|" \
crates/nuwiki-ls/Cargo.toml
# 4. VimL client version global (the Lua client reads this same g: var).
sed -i -E "s/(let g:nuwiki_version = ')[^']*(')/\1$ver\2/" plugin/nuwiki.vim
# 5. Cargo.lock entries for our own crates. Each [[package]] block lists the
# name line immediately followed by the version line; rewrite only those.
for crate in nuwiki-core nuwiki-lsp nuwiki-ls; do
awk -v c="$crate" -v v="$ver" '
$0 == "name = \"" c "\"" {
print
if (getline > 0) { sub(/version = "[^"]*"/, "version = \"" v "\"") }
print
next
}
{ print }
' Cargo.lock > Cargo.lock.tmp && mv Cargo.lock.tmp Cargo.lock
done
echo "Set version to $ver"