From e23a1406fc8d3c9c71297301f3d97d9c5fa04e02 Mon Sep 17 00:00:00 2001 From: Aaron Schlesinger <70865+arschles@users.noreply.github.com> Date: Sun, 19 Jul 2026 18:44:00 -0700 Subject: [PATCH 1/2] Making `qt --version` represent the actual built version Fixes #47 --- cli/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 631f074..2d3e7f5 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,5 +1,8 @@ [package] name = "qt" +# As of this writing (2026-07-19), we are not distributing a Rust library, and this +# will not change unless we do. The version that we care about is output by +# `qt --version`, and that is set up in the cli-release.yml GitHub workflow definition. version = "0.1.0" edition = "2024" From 684a840563229b53b9ccf89ba3387102fd783237 Mon Sep 17 00:00:00 2001 From: Aaron Schlesinger <70865+arschles@users.noreply.github.com> Date: Sun, 19 Jul 2026 18:46:07 -0700 Subject: [PATCH 2/2] progress --- .github/workflows/cli-release.yml | 32 +++++++++++++++++++++++++++++++ cli/src/cli.rs | 5 ++++- cli/tests/version.rs | 5 +++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cli-release.yml b/.github/workflows/cli-release.yml index 17084fa..9ac4563 100644 --- a/.github/workflows/cli-release.yml +++ b/.github/workflows/cli-release.yml @@ -57,8 +57,40 @@ jobs: - uses: Swatinem/rust-cache@v2 with: workspaces: cli + - name: Set CLI version + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + env: + EVENT_NAME: ${{ github.event_name }} + REF: ${{ github.ref }} + REF_NAME: ${{ github.ref_name }} + REF_TYPE: ${{ github.ref_type }} + COMMIT: ${{ github.sha }} + run: | + if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then + version="unversioned-${COMMIT}" + elif [[ "$REF_TYPE" == "tag" ]]; then + version="$REF_NAME" + elif [[ "$REF" == "refs/heads/main" ]]; then + version="beta-${COMMIT}" + else + echo "unable to determine CLI version" >&2 + exit 1 + fi + + echo "QT_CLI_VERSION=$version" >> "$GITHUB_ENV" + echo "EXPECTED_CLI_VERSION=$version" >> "$GITHUB_ENV" - name: Build release binary run: cargo build --locked --release --target ${{ matrix.target }} + - name: Verify CLI version + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + env: + TARGET: ${{ matrix.target }} + run: | + actual="$("target/${TARGET}/release/qt" --version)" + if [[ "$actual" != "$EXPECTED_CLI_VERSION" ]]; then + echo "CLI version mismatch: expected '$EXPECTED_CLI_VERSION', got '$actual'" >&2 + exit 1 + fi - name: Package release artifact env: TARGET: ${{ matrix.target }} diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 4777bfa..1ac0b63 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -1,6 +1,9 @@ use clap::{Parser, Subcommand}; -pub const VERSION: &str = env!("CARGO_PKG_VERSION"); +pub const VERSION: &str = match option_env!("QT_CLI_VERSION") { + Some(version) => version, + None => env!("CARGO_PKG_VERSION"), +}; #[derive(Debug, Parser)] #[command( diff --git a/cli/tests/version.rs b/cli/tests/version.rs index c4a7b6b..4fdb8dd 100644 --- a/cli/tests/version.rs +++ b/cli/tests/version.rs @@ -2,8 +2,9 @@ use assert_cmd::Command; use predicates::prelude::*; #[test] -fn version_flag_prints_cargo_package_version_without_a_prefix() { - let expected = predicate::eq(format!("{}\n", env!("CARGO_PKG_VERSION"))); +fn version_flag_prints_compiled_version_without_a_prefix() { + let version = option_env!("QT_CLI_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")); + let expected = predicate::eq(format!("{version}\n")); Command::new(assert_cmd::cargo::cargo_bin!("qt")) .arg("--version")