From 630c2153715578a6a28937bebca80ae2007a7683 Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Mon, 6 May 2024 16:12:32 -0500 Subject: [PATCH] cli: don't add git commit on release builds --- .github/workflows/release.yml | 2 ++ cli/build.rs | 5 +++++ cli/src/commands/version.rs | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f3cb9196bb..9d5e2a512b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,6 +47,8 @@ jobs: target: ${{ matrix.target }} - name: Build release binary run: cargo build --target ${{ matrix.target }} --verbose --release --features packaging,vendored-openssl + env: + JJ_RELEASE_BUILD: "1" - name: Build archive shell: bash run: | diff --git a/cli/build.rs b/cli/build.rs index 72116a1018..dc10fe321e 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -54,6 +54,11 @@ fn main() -> std::io::Result<()> { println!("cargo:rustc-env=JJ_GIT_COMMIT=g{}", git_hash); } + // if JJ_RELEASE_BUILD, propagate + if std::env::var("JJ_RELEASE_BUILD").is_ok() { + println!("cargo:rustc-env=JJ_RELEASE_BUILD=1"); + } + Ok(()) } diff --git a/cli/src/commands/version.rs b/cli/src/commands/version.rs index 4d7c94ea26..ffe49b3d1d 100644 --- a/cli/src/commands/version.rs +++ b/cli/src/commands/version.rs @@ -40,8 +40,14 @@ pub(crate) fn cmd_version( ) -> Result<(), CommandError> { let base_version = command.app().get_version().unwrap(); let (version, git_commit) = if let Some(git_commit) = option_env!("JJ_GIT_COMMIT") { - let short_commit = &git_commit[..12]; - (format!("{}-{}", base_version, short_commit), git_commit) + // in a release build, don't include the commit hash in the + // `--numeric-version` or normal output. GH-3629 + if option_env!("JJ_RELEASE_BUILD").is_some() { + (String::from(base_version), git_commit) + } else { + let short_commit = &git_commit[..12]; + (format!("{}-{}", base_version, short_commit), git_commit) + } } else { (String::from(base_version), "unknown") }; @@ -71,6 +77,11 @@ Report bugs: writeln!(ui.stdout())?; writeln!(ui.stdout(), "Target: {}", env!("JJ_CARGO_TARGET"))?; writeln!(ui.stdout(), "Commit: {}", git_commit)?; + writeln!( + ui.stdout(), + "Release: {}", + option_env!("JJ_RELEASE_BUILD").is_some() + )?; } Ok(()) }