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,