Skip to content

Commit

Permalink
Include git tag in --version output.
Browse files Browse the repository at this point in the history
Short version (`-V`) is unchanged and displays declared version only.

We also need to fetch git tag in the CI else git will not find it.
(Only on release, for CI we will only have the commit sha)
  • Loading branch information
mgautierfr committed Nov 17, 2024
1 parent 231529c commit 45a9a1d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pre_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-tags: true

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-tags: true

- name: Publish
env:
Expand Down
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ license.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.0.32", features = ["derive"] }
clap = { version = "4.0.32", features = ["derive", "cargo"] }
clap_mangen = "0.2.20"
clap_complete = "4.5.0"
human-panic = "2.0.2"
Expand All @@ -36,3 +36,5 @@ env_logger = "0.11.5"
anyhow = "1.0.75"
log = "0.4.20"
jbk.workspace = true
const_format = "0.2.33"
git-version = "0.3.9"
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ use log::error;
use std::path::PathBuf;
use std::process::ExitCode;

const VERSION: &str = const_format::formatcp!(
"{} (git:{})",
clap::crate_version!(),
git_version::git_version!(args = ["--dirty=*", "--tags", "--always"])
);

#[derive(Parser)]
#[command(name = "waj", author, version, about, long_about=None)]
#[command(name = "waj", author, version, long_version=VERSION, about, long_about=None)]
struct Cli {
/// Set verbose level. Can be specify several times to augment verbose level.
#[arg(short, long, action=clap::ArgAction::Count, global=true)]
Expand Down

0 comments on commit 45a9a1d

Please sign in to comment.