Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report different version strings for non-release builds #262

Open
bajtos opened this issue Jun 22, 2023 · 0 comments
Open

Report different version strings for non-release builds #262

bajtos opened this issue Jun 22, 2023 · 0 comments

Comments

@bajtos
Copy link
Member

bajtos commented Jun 22, 2023

It would be nice to add a suffix to the version reported by zinnia and zinniad when these binaries were not built by our release CI workflow.

For example, 0.11.0 is reported by the released binary (no change) and 0.11.0.1-dev is reported by everything else - binaries built by our CI workflow for pull requests, binaries built locally using cargo build, and so on.

Places we need to change:

  • zinnia --version
  • zinniad --version
  • Zinnia.versions.zinnia API - this must match the value reported by --version

How to build the version string:

fn zinnia_version() -> &'static str {
    let pkg_version = env!("CARGO_PKG_VERSION");
    let is_release_build = option_env!("GITHUB_REF_TYPE") == Some("tag")
        && option_env!("GITHUB_REF_NAME") == Some(pkg_version);

    if is_release_build {
        pkg_version
    } else {
        // We cannot use pkg_version here
        //   error: expected a literal
        //   note: only literals (like `"foo"`, `-42` and `3.14`) can be passed to `concat!()`
        concat!(env!("CARGO_PKG_VERSION"), ".1-dev")
    }
}

Now the trick is that we need to make this change in such way that other components reading CARGO_PKG_VERSION pick up the change too. The clap argument parser in particular.

A possible solution is to add a build script to tweak the version. Quoting from rust-lang/cargo#6583 (comment):

//! build.rs
fn main() {
    // If we set CARGO_PKG_VERSION this way, then it will override the default value, which is
    // taken from the `version` in Cargo.toml.
    if let Ok(val) = std::env::var("FLOWCTL_RELEASE_VERSION") {
        println!("cargo:rustc-env=CARGO_PKG_VERSION={}", val);
    }
    println!("cargo:rerun-if-env-changed=FLOWCTL_RELEASE_VERSION");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant