Skip to content

Commit

Permalink
cli: don't add git commit on release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
thoughtpolice committed May 7, 2024
1 parent ea76957 commit 6df5da8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
5 changes: 5 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
15 changes: 13 additions & 2 deletions cli/src/commands/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
};
Expand Down Expand Up @@ -71,6 +77,11 @@ Report bugs: <https://github.com/martinvonz/jj/issues>
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(())
}

0 comments on commit 6df5da8

Please sign in to comment.