From 33a7a426a625c46d94a41227ec22b426393ea616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20P=C5=82aczek?= Date: Tue, 10 Sep 2024 02:08:20 +0100 Subject: [PATCH] refactor: use tag as version --- .github/workflows/publish.yml | 31 +++++++++++++++++++++++-------- Cargo.lock | 2 +- Cargo.toml | 2 +- build.rs | 28 ++-------------------------- src/main.rs | 10 +++++----- templates/index.html | 2 +- 6 files changed, 33 insertions(+), 42 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1969816..dd994eb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -49,23 +49,38 @@ jobs: DRY_RUN: true - name: Static build (ARM64) - run: RUSTFLAGS='-C target-feature=+crt-static' cargo build --locked --release --target=aarch64-unknown-linux-gnu + run: cargo build --locked --release --target=aarch64-unknown-linux-gnu + env: + RUSTFLAGS: "-C target-feature=+crt-static" + RSPI_BIOS_VERSION: ${{ steps.tag-dry.outputs.new_tag }} - name: Static build (ARMv7) - run: RUSTFLAGS='-C target-feature=+crt-static' cargo build --locked --release --target=armv7-unknown-linux-gnueabihf + run: cargo build --locked --release --target=armv7-unknown-linux-gnueabihf + env: + RUSTFLAGS: "-C target-feature=+crt-static" + RSPI_BIOS_VERSION: ${{ steps.tag-dry.outputs.new_tag }} - name: Static deb build (ARM64) - run: RUSTFLAGS='-C target-feature=+crt-static' cargo deb --deb-version ${{ steps.tag-dry.outputs.new_tag }} --locked --target=aarch64-unknown-linux-gnu + run: cargo deb --deb-version $RSPI_BIOS_VERSION --locked --target=aarch64-unknown-linux-gnu + env: + RUSTFLAGS: "-C target-feature=+crt-static" + RSPI_BIOS_VERSION: ${{ steps.tag-dry.outputs.new_tag }} - name: Static deb build (ARMv7) - run: RUSTFLAGS='-C target-feature=+crt-static' cargo deb --deb-version ${{ steps.tag-dry.outputs.new_tag }} --locked --target=armv7-unknown-linux-gnueabihf + run: cargo deb --deb-version $RSPI_BIOS_VERSION --locked --target=armv7-unknown-linux-gnueabihf + env: + RUSTFLAGS: "-C target-feature=+crt-static" + RSPI_BIOS_VERSION: ${{ steps.tag-dry.outputs.new_tag }} - name: Rename binaries run: | - cp target/aarch64-unknown-linux-gnu/release/rspi-bios ./rspi-bios_${{ steps.tag-dry.outputs.new_tag }}_aarch64-unknown-linux-gnu - cp target/armv7-unknown-linux-gnueabihf/release/rspi-bios ./rspi-bios_${{ steps.tag-dry.outputs.new_tag }}_armv7-unknown-linux-gnueabihf - cp target/aarch64-unknown-linux-gnu/debian/rspi-bios_${{ steps.tag-dry.outputs.new_tag }}_arm64.deb ./rspi-bios_${{ steps.tag-dry.outputs.new_tag }}_arm64.deb - cp target/armv7-unknown-linux-gnueabihf/debian/rspi-bios_${{ steps.tag-dry.outputs.new_tag }}_armhf.deb ./rspi-bios_${{ steps.tag-dry.outputs.new_tag }}_armhf.deb + cp target/aarch64-unknown-linux-gnu/release/rspi-bios ./rspi-bios_$RSPI_BIOS_VERSION_aarch64-unknown-linux-gnu + cp target/armv7-unknown-linux-gnueabihf/release/rspi-bios ./rspi-bios_$RSPI_BIOS_VERSION_armv7-unknown-linux-gnueabihf + cp target/aarch64-unknown-linux-gnu/debian/rspi-bios_$RSPI_BIOS_VERSION_arm64.deb ./rspi-bios_$RSPI_BIOS_VERSION_arm64.deb + cp target/armv7-unknown-linux-gnueabihf/debian/rspi-bios_$RSPI_BIOS_VERSION_armhf.deb ./rspi-bios_$RSPI_BIOS_VERSION_armhf.deb + env: + RSPI_BIOS_VERSION: ${{ steps.tag-dry.outputs.new_tag }} + - name: Tag (Real run) id: tag-real diff --git a/Cargo.lock b/Cargo.lock index 5bfbfdb..2c7388a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1016,7 +1016,7 @@ dependencies = [ [[package]] name = "rspi-bios" -version = "1.0.0" +version = "1.0.0-dev" dependencies = [ "askama", "axum", diff --git a/Cargo.toml b/Cargo.toml index 70a9623..22617bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rspi-bios" -version = "1.0.0" +version = "1.0.0-dev" authors = ["Piotr Placzek "] edition = "2021" rust-version = "1.74" diff --git a/build.rs b/build.rs index b7d7bf0..21871ce 100644 --- a/build.rs +++ b/build.rs @@ -1,28 +1,4 @@ -use std::process::Command; - -// https://stackoverflow.com/a/44407625/19020549 - -#[allow(clippy::unnecessary_wraps)] -fn try_main() -> Result<(), Box> { - let Ok(output) = Command::new("git") - .args(["rev-parse", "--short", "HEAD"]) - .output() - else { - return Err("Failed to get current Git commit using command".into()); - }; - - let Ok(git_hash) = String::from_utf8(output.stdout) else { - return Err("Failed to convert Git output to UTF-8 string".into()); - }; - - println!("cargo:rustc-env=GIT_HASH={git_hash}"); - - Ok(()) -} - fn main() { - if let Err(e) = try_main() { - eprintln!("Error: {e:#?}"); - std::process::exit(1) - } + let version = std::env::var("RSPI_BIOS_VERSION").unwrap_or_else(|_| "dev".to_string()); + println!("cargo:rustc-env=RSPI_BIOS_VERSION={version}"); } diff --git a/src/main.rs b/src/main.rs index 383cd18..9b8a5da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use sysinfo::{Disks, Networks, ProcessesToUpdate, System}; #[derive(Parser, Debug)] -#[command(version = env!("GIT_HASH"), about)] +#[command(version = env!("RSPI_BIOS_VERSION"), about)] struct Args { #[arg(long, value_parser = parse_duration, default_value = "5")] system_refresh_interval: Duration, @@ -171,9 +171,9 @@ async fn main() { } tracing::info!("Logging to {log_path:?}"); tracing::debug!( - "Running {} built from Git commit {}", + "Running {} version {}", env!("CARGO_CRATE_NAME"), - env!("GIT_HASH") + env!("RSPI_BIOS_VERSION") ); tracing::info!("Creating TLS config"); @@ -269,7 +269,7 @@ struct IndexTemplate { process_count: usize, rx: u64, tx: u64, - git_hash: String, + version: String, os_version: String, cpu_arch: String, } @@ -372,7 +372,7 @@ async fn index_handler( process_count, rx: total_rx, tx: total_tx, - git_hash: env!("GIT_HASH").to_string(), + version: env!("RSPI_BIOS_VERSION").to_string(), os_version: state.os_version.lock().await.to_string(), cpu_arch: state.cpu_arch.lock().await.to_string(), }; diff --git a/templates/index.html b/templates/index.html index 32b782c..a37fa15 100644 --- a/templates/index.html +++ b/templates/index.html @@ -170,7 +170,7 @@
  • - 12/05/2023-04/BCM2711/RPI4B-UEFI-{{ git_hash }} + 12/05/2023-04/BCM2711/RPI4B-UEFI-{{ version }}