Added build script env var exports

This commit is contained in:
August 2024-10-09 12:30:29 -04:00
parent 4c5c73e670
commit c58b553e73
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
6 changed files with 66 additions and 5 deletions

2
Cargo.lock generated
View File

@ -1563,7 +1563,7 @@ dependencies = [
[[package]]
name = "shibe-bot"
version = "0.4.0"
version = "0.4.1"
dependencies = [
"anyhow",
"dotenvy",

View File

@ -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"

View File

@ -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)

View File

@ -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(())
}

View File

@ -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"),

View File

@ -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);