Skip to content

Commit c8bbcd7

Browse files
committed
feat: improve the --version output
1 parent 8872617 commit c8bbcd7

File tree

11 files changed

+138
-40
lines changed

11 files changed

+138
-40
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
!crates/
33
!Cargo.toml
44
!Cargo.lock
5-
.env
5+
.env
6+
!.git/**

.github/workflows/build.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,31 @@ concurrency:
2424
jobs:
2525

2626
check:
27-
name: Check ${{ matrix.package }}
27+
name: Check ${{ matrix.package.name }}
2828
runs-on: ubuntu-latest
2929
strategy:
3030
matrix:
3131
package:
32-
- "yozefu-lib"
33-
- "yozefu-app"
34-
- "yozefu-command"
35-
- "yozefu-tui"
36-
- "yozefu-wasm-types"
37-
- "yozefu"
32+
- name: yozefu-lib
33+
command: cargo check --locked --package yozefu-lib
34+
- name: yozefu-app
35+
command: cargo check --locked --package yozefu-app
36+
- name: yozefu-command
37+
command: cargo check --locked --package yozefu-command
38+
- name: yozefu-tui
39+
command: cargo check --locked --package yozefu-tui
40+
- name: yozefu-wasm-types
41+
command: cargo check --locked --package yozefu-wasm-types
42+
- name: yozefu
43+
command: cargo run --locked -- --version
3844
steps:
3945
- uses: actions/checkout@v4
4046
- uses: actions-rust-lang/setup-rust-toolchain@v1
4147
with:
4248
toolchain: stable
4349
- uses: Swatinem/rust-cache@v2
4450
- name: Run cargo check
45-
run: cargo check --locked --release --package ${{ matrix.package }}
51+
run: ${{ matrix.package.command }}
4652

4753
build:
4854
name: Build w/o features
@@ -193,7 +199,7 @@ jobs:
193199
docker:
194200
name: Docker image
195201
runs-on: ubuntu-latest
196-
needs: [check]
202+
# needs: [check]
197203
permissions:
198204
contents: read
199205
packages: write
@@ -204,10 +210,13 @@ jobs:
204210
uses: actions/checkout@v4
205211
- name: Set up Docker Buildx
206212
uses: docker/setup-buildx-action@v3
207-
- name: Build and push
213+
- name: Build
208214
uses: docker/build-push-action@v6
209-
id: push
210215
with:
216+
context: .
217+
build-args: |
218+
GITHUB_REF_NAME=$GITHUB_REF_NAME
219+
GITHUB_SHA=$GITHUB_SHA
211220
push: false
212221
cache-from: type=gha
213222
cache-to: type=gha,mode=max

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ jobs:
199199
uses: docker/build-push-action@v6
200200
id: push
201201
with:
202+
context: .
202203
push: true
203204
tags: ${{ steps.meta.outputs.tags }}
204205
cache-from: type=gha

Cargo.lock

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ WORKDIR /app
33
RUN --mount=type=bind,source=crates,target=crates \
44
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
55
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
6+
--mount=type=bind,source=.git,target=.git \
67
--mount=type=cache,target=/app/target/ \
78
--mount=type=cache,target=/usr/local/cargo/registry/ \
89
<<EOF
910
set -e
1011
apt-get update && apt-get install --no-install-recommends -y build-essential cmake libclang-dev
12+
ls -lah
1113
cargo build --release --all-features --locked
1214
cp ./target/release/yozf /tmp/yozf
1315
EOF
@@ -31,6 +33,7 @@ ln -fs "/bin/app" /usr/local/bin/yozefu
3133
ln -fs "/bin/app" /usr/bin/yozf
3234
ln -fs "/bin/app" /usr/local/bin/yozefu
3335
EOF
36+
RUN /bin/app --version
3437

3538
USER yozefu
3639
WORKDIR /home/yozefu

crates/command/Cargo.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,21 @@ rdkafka = { version = "0.37.0", features = [
4040
"libz-static",
4141
"curl-static",
4242
"zstd",
43-
"external-lz4"
43+
"external-lz4",
4444
] }
4545
extism = { version = "1.10.0" }
4646
indexmap = "2.8.0"
4747
tui = { workspace = true }
4848
app = { workspace = true }
4949
lib = { workspace = true }
5050
reqwest = { version = "0.12.15", features = ["json"] }
51+
const_format = { version = "0.2.34", features = ["rust_1_64"] }
52+
const-str = "0.6.2"
5153

5254
[features]
53-
ssl-vendored = [
54-
"rdkafka/ssl-vendored",
55-
"tui/ssl-vendored",
56-
"app/ssl-vendored"
57-
]
55+
ssl-vendored = ["rdkafka/ssl-vendored", "tui/ssl-vendored", "app/ssl-vendored"]
5856
gssapi-vendored = [
5957
"rdkafka/gssapi-vendored",
6058
"tui/gssapi-vendored",
61-
"app/gssapi-vendored"
59+
"app/gssapi-vendored",
6260
]

crates/command/src/cli.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use crate::cluster::Cluster;
33
use crate::command::{Command, MainCommand, UtilityCommands};
44
use crate::theme::init_themes_file;
5+
use crate::version::VERSION_MESSAGE;
56
use app::APPLICATION_NAME;
67
use app::configuration::{ClusterConfig, GlobalConfig, SchemaRegistryConfig, YozefuConfig};
78
use clap::command;
@@ -14,14 +15,6 @@ use tui::error::TuiError;
1415
pub use clap::Parser;
1516
use indexmap::IndexMap;
1617

17-
const VERSION_MESSAGE: &str = concat!(
18-
env!("CARGO_PKG_VERSION"),
19-
"\n",
20-
env!("CARGO_PKG_REPOSITORY"),
21-
"\n",
22-
env!("CARGO_PKG_AUTHORS")
23-
);
24-
2518
// https://github.com/clap-rs/clap/issues/975
2619
/// CLI parser
2720
#[derive(Parser)]

crates/command/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod command;
77
mod headless;
88
mod log;
99
mod theme;
10+
mod version;
1011
use app::configuration::GlobalConfig;
1112
pub use clap::Parser;
1213
pub use cli::Cli;

crates/command/src/version.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//! Inspired of <https://vallentin.dev/blog/post/versioning>
2+
//!
3+
//! Github environment variables <https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables>
4+
//! The version message looks like this:
5+
//! ```
6+
//! yozefu 0.0.9 (develop:13aedf2, debug build, macos [aarch64])
7+
//! https://github.com/MAIF/yozefu
8+
//! Yann Prono <[email protected]>
9+
//! ```
10+
use const_format::{formatcp, str_index, str_split};
11+
use const_str::split_lines;
12+
use std::env::consts::{ARCH, OS};
13+
14+
#[cfg(debug_assertions)]
15+
const BUILD_TYPE: &str = "debug";
16+
17+
#[cfg(not(debug_assertions))]
18+
const BUILD_TYPE: &'static str = "release";
19+
20+
const GIT_BRANCH: &str = match option_env!("GITHUB_REF_NAME") {
21+
Some(v) => v,
22+
None => {
23+
const FIRST_LINE: &str = split_lines!(include_str!("../../../.git/HEAD"))[0];
24+
str_split!(FIRST_LINE, "/")[2]
25+
}
26+
};
27+
28+
const GIT_COMMIT: &str = match option_env!("GITHUB_SHA") {
29+
Some(v) => v,
30+
None => "unknown",
31+
};
32+
33+
pub(super) const VERSION_MESSAGE: &str = formatcp!(
34+
"{} ({}:{}, {} build, {} [{}]) \n{}\n{}",
35+
env!("CARGO_PKG_VERSION"),
36+
GIT_BRANCH,
37+
str_index!(GIT_COMMIT, 0..7),
38+
BUILD_TYPE,
39+
OS,
40+
ARCH,
41+
env!("CARGO_PKG_REPOSITORY"),
42+
env!("CARGO_PKG_AUTHORS"),
43+
);

deny.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ exceptions = [
110110
{ allow = ["BSL-1.0"], crate = "lazy-bytes-cast" },
111111
{ allow = ["Zlib"], crate = "throbber-widgets-tui" },
112112
{ allow = ["Zlib"], crate = "adler32" },
113+
{ allow = ["Zlib"], crate = "const_format" },
114+
{ allow = ["Zlib"], crate = "konst_macro_rules" },
115+
{ allow = ["Zlib"], crate = "const_format_proc_macros" },
116+
{ allow = ["Zlib"], crate = "konst" }
113117
]
114118

115119
# Some crates don't have (easily) machine readable licensing information,

0 commit comments

Comments
 (0)