Skip to content

Commit

Permalink
Add comprehensive build information to version output
Browse files Browse the repository at this point in the history
- Included author and license information in the version output.
- Added dynamic retrieval of the compilation target using environment variables.
- Updated GitHub Actions workflow to set the TARGET environment variable.
- Refactored LONG_VERSION initialization to handle missing information gracefully.
  • Loading branch information
spezifisch committed Jul 27, 2024
1 parent 1c2355c commit d992702
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Build and test

on:
push:
Expand All @@ -24,6 +24,9 @@ jobs:
profile: minimal
override: true

- name: Set environment variables
run: echo "TARGET=$(rustc -vV | grep 'host: ' | cut -d' ' -f2)" >> $GITHUB_ENV

- name: Build
run: cargo build --release

Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
profile: minimal
override: true

- name: Set environment variables
run: echo "TARGET=$(rustc -vV | grep 'host: ' | cut -d' ' -f2)" >> $GITHUB_ENV

- name: Build
run: cargo build --release

Expand All @@ -45,6 +48,9 @@ jobs:
profile: minimal
override: true

- name: Set environment variables
run: echo "TARGET=$(rustc -vV | grep 'host: ' | cut -d' ' -f2)" >> $GITHUB_ENV

- name: Build
run: cargo build --release

Expand All @@ -67,4 +73,4 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: target/release/ifstat-rs
asset_name: ifstat-rs
asset_content_type: application/octet-stream
asset_content_type: application/octet-stream
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["spezifisch <spezifisch+JOKING@gmail.com>"]
edition = "2018"
description = "ifstat-rs: A tool to report network interface statistics."
repository = "https://github.com/spezifisch/ifstat-rs"
license = "MIT"

[dependencies]
tokio = { version = "1", features = ["full"] }
Expand Down
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use clap::Parser;
use regex::Regex;
use std::collections::HashMap;
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use lazy_static::lazy_static;

const AUTHOR: &str = env!("CARGO_PKG_AUTHORS");
const REPO_URL: &str = env!("CARGO_PKG_REPOSITORY");
const LICENSE: &str = env!("CARGO_PKG_LICENSE");

#[derive(Parser)]
#[clap(version = "1.0", author = AUTHOR, long_version = LONG_VERSION.as_str())]
Expand Down Expand Up @@ -44,16 +46,19 @@ lazy_static! {
let commit_hash = option_env!("VERGEN_GIT_SHA").unwrap_or("unknown");
let build_timestamp = option_env!("VERGEN_BUILD_TIMESTAMP").unwrap_or("unknown");
let rust_version = option_env!("VERGEN_RUSTC_SEMVER").unwrap_or("unknown");
let target = env::var("TARGET").unwrap_or_else(|_| "unknown".to_string());

format!(
"ifstat-rs: A tool to report network interface statistics.\n\n\
Built with Rust.\n\n\
"A tool to report network interface statistics.\n\n\
Author: {}\n\
License: {}\n\
Build info:\n\
Commit: {}\n\
Build Timestamp: {}\n\
Rust Version: {}\n\
Compilation Target: {}\n\
Repo: {}",
commit_hash, build_timestamp, rust_version, REPO_URL
AUTHOR, LICENSE, commit_hash, build_timestamp, rust_version, target, REPO_URL
)
};
}
Expand Down

0 comments on commit d992702

Please sign in to comment.