Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/cli-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
5 changes: 4 additions & 1 deletion cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading