Files
nuwiki/scripts/set-version.sh
T
gffranco 59494e9a86
CI / cargo fmt --check (push) Successful in 54s
CI / cargo clippy (push) Successful in 58s
CI / cargo test (push) Successful in 1m8s
CI / editor keymaps (push) Successful in 1m44s
ci(release): stamp the version in-pipeline from a dispatch input
Releasing no longer means hand-editing the version across four files. The
Release workflow is now workflow_dispatch with a `version` input:

  Actions → Run workflow → version: 0.4.0

A new `prepare` job validates the semver, runs scripts/set-version.sh to
stamp it into the workspace Cargo.toml, the two internal path-dep pins,
g:nuwiki_version, and the Cargo.lock entries for our crates; gates on
`cargo test --workspace`; then commits "chore(release): X.Y.Z" and pushes
the vX.Y.Z tag. The build matrix and release job run off that freshly
pushed tag (checkout ref = the new tag), so the tagged commit carries the
real version.

scripts/set-version.sh is the single source of truth for where the version
lives — run it locally with the same arg to bump by hand. It patches
Cargo.lock via awk so it needs no cargo/toolchain.

The push:tags trigger is removed (the pipeline now creates the tag itself,
so a tag-push trigger would double-fire).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 15:06:33 +00:00

58 lines
2.2 KiB
Bash
Executable File

#!/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"