mirror of
https://github.com/devmobasa/wayscriber.git
synced 2026-11-01 07:36:42 +01:00
173 lines
5.1 KiB
Bash
Executable File
173 lines
5.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage: tools/bump-version.sh [--dry-run] [new_version]
|
|
|
|
- If new_version is omitted, bumps the patch version (e.g., 0.9.2 -> 0.9.3).
|
|
- new_version can be MAJOR.MINOR.PATCH or MAJOR.MINOR.PATCH.HOTFIX.
|
|
- HOTFIX versions are packaging-only: Cargo and flake.nix stay on MAJOR.MINOR.PATCH;
|
|
packaging/PKGBUILD, packaging/.SRCINFO, and release artifacts use the HOTFIX version.
|
|
- Updates:
|
|
* Cargo.toml (wayscriber)
|
|
* configurator/Cargo.toml
|
|
* Cargo.lock (workspace versions only; preserves locked dependencies)
|
|
* flake.nix package version follows Cargo.toml automatically
|
|
* packaging/PKGBUILD pkgver and template sha256sums=('SKIP')
|
|
* packaging/.SRCINFO (via makepkg --printsrcinfo)
|
|
|
|
The repo PKGBUILD is a template: release/AUR automation computes the real
|
|
source archive checksum after the tag exists.
|
|
|
|
Requires: cargo, jq, makepkg, sed, perl, python3 or python pointing to Python 3.
|
|
EOF
|
|
}
|
|
|
|
require_bin() {
|
|
if ! command -v "$1" >/dev/null 2>&1; then
|
|
echo "error: $1 is required" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
if [[ "${1-}" == "-h" || "${1-}" == "--help" ]]; then
|
|
usage
|
|
exit 0
|
|
fi
|
|
|
|
require_bin cargo
|
|
require_bin jq
|
|
require_bin makepkg
|
|
require_bin sed
|
|
require_bin perl
|
|
if ! { command -v python3 >/dev/null 2>&1 && python3 -c 'import sys; raise SystemExit(0 if sys.version_info[0] == 3 else 1)' >/dev/null 2>&1; } \
|
|
&& ! { command -v python >/dev/null 2>&1 && python -c 'import sys; raise SystemExit(0 if sys.version_info[0] == 3 else 1)' >/dev/null 2>&1; }; then
|
|
echo "error: python3 or python pointing to Python 3 is required" >&2
|
|
exit 1
|
|
fi
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$REPO_ROOT"
|
|
|
|
current_version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name=="wayscriber") | .version')"
|
|
if [[ -z "$current_version" ]]; then
|
|
echo "error: unable to detect current wayscriber version" >&2
|
|
exit 1
|
|
fi
|
|
|
|
DRY_RUN=false
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--dry-run)
|
|
DRY_RUN=true
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
-*)
|
|
usage
|
|
exit 1
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ $# -gt 1 ]]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
if [[ $# -eq 1 ]]; then
|
|
next_version="$1"
|
|
else
|
|
IFS='.' read -r major minor patch <<<"$current_version"
|
|
patch=$((patch + 1))
|
|
next_version="${major}.${minor}.${patch}"
|
|
fi
|
|
|
|
if ! [[ "$next_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
|
|
echo "error: invalid version format: $next_version (expected MAJOR.MINOR.PATCH[.HOTFIX])" >&2
|
|
exit 1
|
|
fi
|
|
|
|
IFS='.' read -r major minor patch hotfix extra <<<"$next_version"
|
|
if [[ -n "${extra:-}" ]]; then
|
|
echo "error: invalid version format: $next_version (too many segments)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
cargo_version="${major}.${minor}.${patch}"
|
|
package_version="${next_version}"
|
|
if [[ -z "${hotfix:-}" ]]; then
|
|
cargo_version="${next_version}"
|
|
fi
|
|
|
|
echo "Current version: $current_version"
|
|
echo "Bumping to: $next_version"
|
|
if [[ "$cargo_version" != "$next_version" ]]; then
|
|
echo "Cargo version: $cargo_version (release version has hotfix)"
|
|
fi
|
|
|
|
update_version_field() {
|
|
local file="$1"
|
|
if ! [[ -f "$file" ]]; then
|
|
echo "warn: $file not found, skipping" >&2
|
|
return
|
|
fi
|
|
if $DRY_RUN; then
|
|
echo "dry-run: would update version in $file"
|
|
else
|
|
NEXT_VERSION="$cargo_version" perl -0777 -pi -e 's/(\[package\][^\[]*?\nversion\s*=\s*")\K[^"]+/$ENV{NEXT_VERSION}/s' "$file"
|
|
fi
|
|
}
|
|
|
|
# Resolve against the existing manifests without writing the lockfile. An empty
|
|
# registry cache must fail before either manifest or any package metadata changes.
|
|
if [[ -f Cargo.lock ]]; then
|
|
if ! cargo update --workspace --offline --dry-run >/dev/null; then
|
|
echo "error: cannot resolve locked dependencies offline; run ./tools/fetch-all-deps.sh before bumping the version. No version files changed." >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
update_version_field "Cargo.toml"
|
|
update_version_field "configurator/Cargo.toml"
|
|
|
|
if [[ -f Cargo.lock ]]; then
|
|
if $DRY_RUN; then
|
|
echo "dry-run: would update workspace versions in Cargo.lock, preserving dependencies"
|
|
else
|
|
cargo update --workspace --offline >/dev/null
|
|
fi
|
|
else
|
|
echo "warn: Cargo.lock not found, skipping lockfile update" >&2
|
|
fi
|
|
|
|
if [[ -f packaging/PKGBUILD ]]; then
|
|
if $DRY_RUN; then
|
|
echo "dry-run: would set pkgver=${package_version}, reset sha256sums=SKIP, and regenerate .SRCINFO"
|
|
else
|
|
sed -i "s/^pkgver=.*/pkgver=${package_version}/" packaging/PKGBUILD
|
|
sed -i "s/^sha256sums=.*/sha256sums=('SKIP')/" packaging/PKGBUILD
|
|
(cd packaging && makepkg --printsrcinfo > .SRCINFO)
|
|
fi
|
|
else
|
|
echo "warn: packaging/PKGBUILD not found, skipping PKGBUILD/.SRCINFO" >&2
|
|
fi
|
|
|
|
if $DRY_RUN; then
|
|
echo "Dry run complete (no changes made)"
|
|
else
|
|
bash tools/check-version-consistency.sh --release-version "$package_version"
|
|
echo "Updated versions to $next_version"
|
|
fi
|