From f0f844b25ef8137593db292d0d6b3a1716b11a77 Mon Sep 17 00:00:00 2001 From: devmobasa <4170275+devmobasa@users.noreply.github.com> Date: Fri, 30 Jan 2026 10:39:32 +0100 Subject: [PATCH] Support four-part release versions --- .github/workflows/build-packages.yml | 9 ++++-- build.rs | 8 +++++ src/about_window/render/draw.rs | 2 +- src/build_info.rs | 3 ++ src/cli.rs | 5 ++- src/daemon/tray/ksni.rs | 2 +- src/lib.rs | 1 + src/main.rs | 1 + src/ui/help_overlay/render/mod.rs | 2 +- tools/README.md | 5 +-- tools/bump-version.sh | 26 ++++++++++++--- tools/create-release-tag.sh | 5 +-- tools/package.sh | 4 +++ tools/publish-release-tag.sh | 7 ++++- tools/update-aur.sh | 47 ++++++++++++++++++++++------ 15 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 src/build_info.rs diff --git a/.github/workflows/build-packages.yml b/.github/workflows/build-packages.yml index d77941bc..a1f1f8e7 100644 --- a/.github/workflows/build-packages.yml +++ b/.github/workflows/build-packages.yml @@ -53,10 +53,15 @@ jobs: . configurator - - name: Read crate version + - name: Read release version id: meta run: | - VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name=="wayscriber") | .version') + if [[ "${GITHUB_REF_NAME:-}" == v* ]]; then + VERSION="${GITHUB_REF_NAME#v}" + fi + if [[ -z "${VERSION:-}" ]]; then + VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name=="wayscriber") | .version') + fi echo "version=${VERSION}" >> "$GITHUB_OUTPUT" - name: Pre-fetch Cargo dependencies (locked) diff --git a/build.rs b/build.rs index 51a5a3c9..67b3f173 100644 --- a/build.rs +++ b/build.rs @@ -10,6 +10,14 @@ fn main() { tablet: { feature = "tablet-input" }, } + println!("cargo:rerun-if-env-changed=WAYSCRIBER_RELEASE_VERSION"); + match env::var("WAYSCRIBER_RELEASE_VERSION") { + Ok(release_version) if !release_version.is_empty() => { + println!("cargo:rustc-env=WAYSCRIBER_RELEASE_VERSION={release_version}"); + } + _ => {} + } + let hash = Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .output() diff --git a/src/about_window/render/draw.rs b/src/about_window/render/draw.rs index 46229a60..cf472902 100644 --- a/src/about_window/render/draw.rs +++ b/src/about_window/render/draw.rs @@ -151,7 +151,7 @@ fn add_link_line( } fn version() -> &'static str { - env!("CARGO_PKG_VERSION") + crate::build_info::version() } fn commit_hash() -> &'static str { diff --git a/src/build_info.rs b/src/build_info.rs new file mode 100644 index 00000000..c58d840e --- /dev/null +++ b/src/build_info.rs @@ -0,0 +1,3 @@ +pub fn version() -> &'static str { + option_env!("WAYSCRIBER_RELEASE_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")) +} diff --git a/src/cli.rs b/src/cli.rs index a3676a16..9d8d9d77 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,7 +2,10 @@ use clap::{ArgAction, Parser}; #[derive(Parser, Debug)] #[command(name = "wayscriber")] -#[command(version, about = "Screen annotation tool for Wayland compositors")] +#[command( + version = crate::build_info::version(), + about = "Screen annotation tool for Wayland compositors" +)] pub struct Cli { /// Run as daemon (background service; bind a toggle like Super+D) #[arg(long, short = 'd', action = ArgAction::SetTrue)] diff --git a/src/daemon/tray/ksni.rs b/src/daemon/tray/ksni.rs index 9b7ac04b..6dad3a51 100644 --- a/src/daemon/tray/ksni.rs +++ b/src/daemon/tray/ksni.rs @@ -63,7 +63,7 @@ impl ksni::Tray for WayscriberTray { ksni::ToolTip { icon_name: "wayscriber".into(), icon_pixmap: vec![], - title: format!("Wayscriber {}", env!("CARGO_PKG_VERSION")), + title: format!("Wayscriber {}", crate::build_info::version()), description, } } diff --git a/src/lib.rs b/src/lib.rs index 1546f552..224c26e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ //! rely on so that external tools (e.g. GUI configurators) can share validation //! logic and serialization code with the main binary. +pub mod build_info; pub mod capture; pub mod config; pub mod draw; diff --git a/src/main.rs b/src/main.rs index 6cf4eaaf..77cea0f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod about_window; mod app; mod backend; +mod build_info; mod capture; mod cli; mod config; diff --git a/src/ui/help_overlay/render/mod.rs b/src/ui/help_overlay/render/mod.rs index 68c7040a..aeeafcd2 100644 --- a/src/ui/help_overlay/render/mod.rs +++ b/src/ui/help_overlay/render/mod.rs @@ -61,7 +61,7 @@ pub fn render_help_overlay( } else { format!( "{} {} {} {} {} {} {} {} {}", - env!("CARGO_PKG_VERSION"), + crate::build_info::version(), BULLET, palette_binding, ARROW, diff --git a/tools/README.md b/tools/README.md index 7824603a..93a745ee 100644 --- a/tools/README.md +++ b/tools/README.md @@ -41,17 +41,18 @@ Helper scripts for development, installation, packaging, and release workflows. - **bump-version.sh** - Bump version numbers - Updates Cargo.toml, configurator/Cargo.toml, Cargo.lock, PKGBUILD, .SRCINFO - Auto-increments patch version if no version specified + - Supports MAJOR.MINOR.PATCH.HOTFIX for packaging-only hotfix releases - Usage: `./tools/bump-version.sh [--dry-run] [new_version]` - **create-release-tag.sh** - Create git tag (local only) - Creates annotated tag `v` without pushing - Requires clean working tree - - Usage: `./tools/create-release-tag.sh ` + - Usage: `./tools/create-release-tag.sh ` (X.Y.Z or X.Y.Z.N) - **publish-release-tag.sh** - Create and push git tag - Creates annotated tag and pushes to origin - Auto-detects version from Cargo.toml if not specified - - Usage: `./tools/publish-release-tag.sh [--version X.Y.Z] [--dry-run]` + - Usage: `./tools/publish-release-tag.sh [--version X.Y.Z[.N]] [--dry-run]` - **release.sh** - Full release workflow - Bumps version, commits changes, creates tag, and pushes diff --git a/tools/bump-version.sh b/tools/bump-version.sh index 501424b9..f2c09d38 100755 --- a/tools/bump-version.sh +++ b/tools/bump-version.sh @@ -6,6 +6,7 @@ usage() { 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. - Updates: * Cargo.toml (wayscriber) * configurator/Cargo.toml @@ -82,13 +83,28 @@ else next_version="${major}.${minor}.${patch}" fi -if ! [[ "$next_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "error: invalid version format: $next_version (expected MAJOR.MINOR.PATCH digits)" >&2 +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" @@ -99,7 +115,7 @@ update_version_field() { if $DRY_RUN; then echo "dry-run: would update version in $file" else - NEXT_VERSION="$next_version" perl -0777 -pi -e 's/(\[package\][^\[]*?\nversion\s*=\s*")\K[^"]+/$ENV{NEXT_VERSION}/s' "$file" + NEXT_VERSION="$cargo_version" perl -0777 -pi -e 's/(\[package\][^\[]*?\nversion\s*=\s*")\K[^"]+/$ENV{NEXT_VERSION}/s' "$file" fi } @@ -118,9 +134,9 @@ fi if [[ -f packaging/PKGBUILD ]]; then if $DRY_RUN; then - echo "dry-run: would set pkgver=${next_version} in packaging/PKGBUILD and regenerate .SRCINFO" + echo "dry-run: would set pkgver=${package_version} in packaging/PKGBUILD and regenerate .SRCINFO" else - sed -i "s/^pkgver=.*/pkgver=${next_version}/" packaging/PKGBUILD + sed -i "s/^pkgver=.*/pkgver=${package_version}/" packaging/PKGBUILD (cd packaging && makepkg --printsrcinfo > .SRCINFO) fi else diff --git a/tools/create-release-tag.sh b/tools/create-release-tag.sh index bb0fdcd8..e9ca11ff 100755 --- a/tools/create-release-tag.sh +++ b/tools/create-release-tag.sh @@ -13,6 +13,7 @@ Requirements: Examples: tools/create-release-tag.sh 0.9.2 + tools/create-release-tag.sh 0.9.9.1 EOF } @@ -33,8 +34,8 @@ require_bin git version="$1" tag="v${version}" -if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "error: invalid version format: $version (expected MAJOR.MINOR.PATCH)" >&2 +if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then + echo "error: invalid version format: $version (expected MAJOR.MINOR.PATCH[.HOTFIX])" >&2 exit 1 fi diff --git a/tools/package.sh b/tools/package.sh index 8b6a592a..6ca0ba1e 100755 --- a/tools/package.sh +++ b/tools/package.sh @@ -69,6 +69,10 @@ if [[ -z "$VERSION" ]]; then | head -n1)" fi +if [[ -n "$VERSION" ]]; then + export WAYSCRIBER_RELEASE_VERSION="$VERSION" +fi + mkdir -p "${ARTIFACT_ROOT}" info() { printf '\033[0;32m[INFO]\033[0m %s\n' "$*" >&2; } diff --git a/tools/publish-release-tag.sh b/tools/publish-release-tag.sh index f481e1e2..f30c537d 100755 --- a/tools/publish-release-tag.sh +++ b/tools/publish-release-tag.sh @@ -11,7 +11,7 @@ DRY_RUN=0 usage() { cat <<'EOF' -publish-release-tag.sh [--version X.Y.Z] [--dry-run] +publish-release-tag.sh [--version X.Y.Z[.N]] [--dry-run] Creates an annotated git tag "v" and pushes it to origin. If --version is omitted, uses the wayscriber crate version from Cargo metadata. @@ -33,6 +33,11 @@ if [[ -z "$VERSION" ]]; then VERSION="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name=="wayscriber") | .version')" fi +if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then + echo "error: invalid version format: $VERSION (expected MAJOR.MINOR.PATCH[.HOTFIX])" >&2 + exit 1 +fi + TAG="v${VERSION}" # Safety checks diff --git a/tools/update-aur.sh b/tools/update-aur.sh index 022217e7..4bd5cfbe 100755 --- a/tools/update-aur.sh +++ b/tools/update-aur.sh @@ -18,6 +18,23 @@ AUR_REPO="wayscriber" PACKAGE_URL="https://aur.archlinux.org/packages/wayscriber" AUR_DIR="$HOME/aur-packages/wayscriber" +usage() { + cat <<'EOF' +update-aur.sh [--version X.Y.Z[.N]] + +Updates the AUR package metadata. By default, uses the Cargo.toml version. +EOF +} + +VERSION_OVERRIDE="" +while [[ $# -gt 0 ]]; do + case "$1" in + --version) VERSION_OVERRIDE="$2"; shift 2 ;; + -h|--help) usage; exit 0 ;; + *) echo "Unknown arg: $1" >&2; usage; exit 1 ;; + esac +done + echo "═══════════════════════════════════════════════════════════════" echo " WAYSCRIBER - AUR UPDATE AUTOMATION" echo "═══════════════════════════════════════════════════════════════" @@ -34,16 +51,26 @@ CARGO_VERSION=$(grep '^version = ' "$PROJECT_ROOT/Cargo.toml" | head -1 | sed 's echo -e "${GREEN}📦 Current version in Cargo.toml: $CARGO_VERSION${NC}" echo "" +RELEASE_VERSION="${VERSION_OVERRIDE:-$CARGO_VERSION}" +if ! [[ "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then + echo -e "${RED}❌ Invalid version format: $RELEASE_VERSION (expected MAJOR.MINOR.PATCH[.HOTFIX])${NC}" + exit 1 +fi +if [[ "$RELEASE_VERSION" != "$CARGO_VERSION" ]]; then + echo -e "${YELLOW}📦 Using release version override: $RELEASE_VERSION${NC}" + echo "" +fi + # Check if version tag exists on GitHub cd "$PROJECT_ROOT" -if ! git tag | grep -q "^v$CARGO_VERSION\$"; then - echo -e "${YELLOW}⚠️ Git tag v$CARGO_VERSION does not exist${NC}" +if ! git tag | grep -q "^v$RELEASE_VERSION\$"; then + echo -e "${YELLOW}⚠️ Git tag v$RELEASE_VERSION does not exist${NC}" echo "" - read -p "Create and push tag v$CARGO_VERSION? (y/n) " -n 1 -r + read -p "Create and push tag v$RELEASE_VERSION? (y/n) " -n 1 -r echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then - git tag -a "v$CARGO_VERSION" -m "Release v$CARGO_VERSION" - git push origin "v$CARGO_VERSION" + git tag -a "v$RELEASE_VERSION" -m "Release v$RELEASE_VERSION" + git push origin "v$RELEASE_VERSION" echo -e "${GREEN}✅ Tag created and pushed${NC}" else echo -e "${RED}❌ Aborted - tag required for AUR${NC}" @@ -85,13 +112,13 @@ echo -e "${GREEN}Copied $SOURCE_FILE to $AUR_DIR/PKGBUILD${NC}" # Update version in PKGBUILD cd "$AUR_DIR" if grep -q '^pkgver=' PKGBUILD; then - sed -i "s/^pkgver=.*/pkgver=$CARGO_VERSION/" PKGBUILD + sed -i "s/^pkgver=.*/pkgver=$RELEASE_VERSION/" PKGBUILD fi if grep -q '^pkgrel=' PKGBUILD; then sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD fi -echo -e "${GREEN}✅ Updated PKGBUILD: pkgver=$CARGO_VERSION, pkgrel=1${NC}" +echo -e "${GREEN}✅ Updated PKGBUILD: pkgver=$RELEASE_VERSION, pkgrel=1${NC}" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" @@ -144,7 +171,7 @@ echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then # Add and commit git add PKGBUILD .SRCINFO .gitignore 2>/dev/null || git add PKGBUILD .SRCINFO - git commit -m "Update to v$CARGO_VERSION" + git commit -m "Update to v$RELEASE_VERSION" # Push if git push origin master 2>/dev/null; then @@ -163,7 +190,7 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then echo "═══════════════════════════════════════════════════════════════" echo "" echo "Package URL: $PACKAGE_URL" - echo "Version: $CARGO_VERSION" + echo "Version: $RELEASE_VERSION" echo "" echo "Users can update with:" echo " yay -Syu wayscriber" @@ -175,6 +202,6 @@ else echo "To push manually later:" echo " cd $AUR_DIR" echo " git add PKGBUILD .SRCINFO" - echo " git commit -m 'Update to v$CARGO_VERSION'" + echo " git commit -m 'Update to v$RELEASE_VERSION'" echo " git push origin master" fi