From c58b553e73156c99028427e0f0f2631f8ead82f2 Mon Sep 17 00:00:00 2001 From: shibedrill Date: Wed, 9 Oct 2024 12:30:29 -0400 Subject: [PATCH] Added build script env var exports --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- build.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++ src/command/devel.rs | 12 ++++++++++- src/main.rs | 5 ++++- 6 files changed, 66 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa5d86e..859996d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1563,7 +1563,7 @@ dependencies = [ [[package]] name = "shibe-bot" -version = "0.4.0" +version = "0.4.1" dependencies = [ "anyhow", "dotenvy", diff --git a/Cargo.toml b/Cargo.toml index 04a2dd1..7c295cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "shibe-bot" description = "A Discord bot written in Rust, using Poise." license = "MIT" readme = "README.md" -version = "0.4.0" +version = "0.4.1" edition = "2021" build = "build.rs" diff --git a/README.md b/README.md index 7d4f3e8..d8ff59b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Shibe Bot 0.4.0 +# Shibe Bot 0.4.1 [![Rust](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml/badge.svg)](https://github.com/shibedrill/shibe-bot/actions/workflows/rust.yml) [![GitHub License](https://img.shields.io/github/license/shibedrill/shibe-bot)](LICENSE.txt) diff --git a/build.rs b/build.rs index b208c67..b9cdc28 100644 --- a/build.rs +++ b/build.rs @@ -11,5 +11,53 @@ fn main() -> Result<(), Error> { .add_instructions(&cargo)? .add_instructions(&rustc)? .emit()?; + + let git_commit_id = std::process::Command::new("git") + .arg("rev-parse") + .arg("--short") + .arg("HEAD") + .output()?; + let git_commit_date = std::process::Command::new("git") + .arg("show") + .arg("-s") + .arg("--format=%ci") + .output()?; + let git_commit_message = std::process::Command::new("git") + .arg("show") + .arg("-s") + .arg("--format=%s") + .output()?; + let git_commit_author_name = std::process::Command::new("git") + .arg("show") + .arg("-s") + .arg("--format=%an") + .output()?; + let git_commit_author_email = std::process::Command::new("git") + .arg("show") + .arg("-s") + .arg("--format=%ae") + .output()?; + + println!( + "cargo:rustc-env=GIT_COMMIT_ID={}", + String::from_utf8(git_commit_id.stdout)? + ); + println!( + "cargo:rustc-env=GIT_COMMIT_DATE={}", + String::from_utf8(git_commit_date.stdout)? + ); + println!( + "cargo:rustc-env=GIT_COMMIT_MSG={}", + String::from_utf8(git_commit_message.stdout)? + ); + println!( + "cargo:rustc-env=GIT_COMMIT_AUTHOR_NAME={}", + String::from_utf8(git_commit_author_name.stdout)? + ); + println!( + "cargo:rustc-env=GIT_COMMIT_AUTHOR_EMAIL={}", + String::from_utf8(git_commit_author_email.stdout)? + ); + Ok(()) } diff --git a/src/command/devel.rs b/src/command/devel.rs index e6aa8bc..275813d 100644 --- a/src/command/devel.rs +++ b/src/command/devel.rs @@ -5,13 +5,23 @@ use crate::Error; #[poise::command(slash_command)] pub async fn version(ctx: Context<'_>) -> Result<(), Error> { ctx.say(format!( - "Bot version: {}\n\ + "Source:\n\ + \tPackage version: {}\n\ + \tCommit ID: {}\n\ + \tCommit date: {}\n\ + \tCommit author: {} ({})\n\ + \tCommit message: {}\n\ Build:\n\ \tBuild date: {}\n\ \tBuild timestamp: {}\n\ \tTarget triple: {}\n\ \trustc version: {}\n", env!("CARGO_PKG_VERSION"), + env!("GIT_COMMIT_ID"), + env!("GIT_COMMIT_DATE"), + env!("GIT_COMMIT_AUTHOR_NAME"), + env!("GIT_COMMIT_AUTHOR_EMAIL"), + env!("GIT_COMMIT_MSG"), env!("VERGEN_BUILD_DATE"), env!("VERGEN_BUILD_TIMESTAMP"), env!("VERGEN_CARGO_TARGET_TRIPLE"), diff --git a/src/main.rs b/src/main.rs index bcba500..150c930 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,10 @@ async fn main() { // Build client let mut client = serenity::ClientBuilder::new(token, intents) .framework(framework) - .activity(ActivityData::custom(format!("Version {}!", env!("CARGO_PKG_VERSION")))) + .activity(ActivityData::custom(format!( + "Version {}!", + env!("CARGO_PKG_VERSION") + ))) .await .unwrap_or_else(|e| { error!("Building client failed: {}", e);