From 286d3f2468bdb5aa66e734743b97563f2f4ed677 Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Sun, 1 Feb 2026 12:44:27 -0800 Subject: [PATCH] Fix version mismatch by setting version from CI env var - Add build.rs that reads CLI_VERSION env var (defaults to "dev") - Update clap to use CLI_VERSION set by build script - Set Cargo.toml version to 0.0.0-dev as placeholder - CI passes git tag as CLI_VERSION when building releases Local builds show "dev", release builds show the tag version. Fixes #25 --- .github/workflows/build.yml | 4 +++- Cargo.lock | 2 +- Cargo.toml | 2 +- build.rs | 7 +++++++ src/cmd/mod.rs | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 build.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ab9a58..b86b9db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,7 +63,7 @@ jobs: steps: - uses: actions/checkout@v4 - + - name: Setup Rust toolchain uses: dtolnay/rust-toolchain@master with: @@ -83,6 +83,8 @@ jobs: - name: Build release binary run: cargo build --release --target ${{ matrix.target }} + env: + CLI_VERSION: ${{ needs.version.outputs.new_tag }} - name: Prepare artifact shell: bash diff --git a/Cargo.lock b/Cargo.lock index ffff48a..cd2d70a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1161,7 +1161,7 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "popcorn-cli" -version = "0.1.0" +version = "0.0.0-dev" dependencies = [ "anyhow", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 779842d..bbbd750 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "popcorn-cli" -version = "0.1.0" +version = "0.0.0-dev" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..3497d5f --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +fn main() { + // CI sets CLI_VERSION env var from git tag, otherwise show "dev" + let version = std::env::var("CLI_VERSION") + .map(|v| v.trim_start_matches('v').to_string()) + .unwrap_or_else(|_| "dev".to_string()); + println!("cargo:rustc-env=CLI_VERSION={}", version); +} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 66a8909..b2322b8 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -37,7 +37,7 @@ fn load_config() -> Result { } #[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] +#[command(author, version = env!("CLI_VERSION"), about, long_about = None)] pub struct Cli { #[command(subcommand)] command: Option,