Skip to content

Commit

Permalink
fix version
Browse files Browse the repository at this point in the history
  • Loading branch information
cycle-five committed Jun 30, 2024
1 parent 34fb8e9 commit 76759ea
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 29 deletions.
68 changes: 66 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ reqwest = { version = "0.12.4", default-features = false, features = [
"cookies",
] }
tracing = "0.1.40"
vergen = { version = "8", features = ["git", "cargo", "si", "build", "gitcl"] }


[workspace.dependencies.sqlx]
Expand Down Expand Up @@ -84,7 +85,12 @@ ci = "github"
# The installers to generate for each app
installers = ["shell", "homebrew", "msi"]
# Target platforms to build apps for (Rust target-triple syntax)
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
targets = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
]
# Publish jobs to run in CI
pr-run-mode = "plan"
# Whether to install an updater program
Expand Down
10 changes: 8 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
fn main() {
fn main() -> Result<(), Box<dyn std::error::Error>> {
// For the githash of the build
vergen::EmitBuilder::builder()
.all_build()
.all_git()
.emit()?;
// make sure tarpaulin is included in the build
println!("cargo::rustc-check-cfg=cfg(tarpaulin_include)");
println!("cargo:rustc-check-cfg=cfg(tarpaulin_include)");
// generated by `sqlx migrate build-script`
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
Ok(())
}
3 changes: 3 additions & 0 deletions crack-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ mockall = "0.12.1"
tungstenite = "0.23.0"
async-tungstenite = "0.26.0"
sqlx = { workspace = true }

[build-dependencies]
vergen = { workspace = true }
17 changes: 7 additions & 10 deletions crack-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::process::Command;
fn main() {
fn main() -> Result<(), Box<dyn std::error::Error>> {
// make sure tarpaulin is included in the build
println!("cargo::rustc-check-cfg=cfg(tarpaulin_include)");
// note: add error checking yourself.
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
println!("cargo:rustc-check-cfg=cfg(tarpaulin_include)");
vergen::EmitBuilder::builder()
.all_build()
.all_git()
.emit()?;
Ok(())
}
6 changes: 3 additions & 3 deletions crack-core/src/commands/utility/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::guild::operations::GuildSettingsOperations;
use crate::{
messaging::{message::CrackedMessage, messages::UNKNOWN},
utils::send_reply,
Context, Error,
Context, CrackedError, Error,
};

/// Get the build version of this bot.
Expand All @@ -14,10 +14,10 @@ pub async fn version(ctx: Context<'_>) -> Result<(), Error> {

/// Get the build version of this bot, internal function.
pub async fn version_internal(ctx: Context<'_>) -> Result<(), Error> {
let guild_id = ctx.guild_id().unwrap();
let guild_id = ctx.guild_id().ok_or(CrackedError::NoGuildId)?;
let reply_with_embed = ctx.data().get_reply_with_embed(guild_id).await;
let current = option_env!("CARGO_PKG_VERSION").unwrap_or_else(|| UNKNOWN);
let hash = option_env!("GIT_HASH").unwrap_or_else(|| UNKNOWN);
let hash = option_env!("VERGEN_GIT_SHA").unwrap_or_else(|| UNKNOWN);

Check warning on line 20 in crack-core/src/commands/utility/version.rs

View check run for this annotation

Codecov / codecov/patch

crack-core/src/commands/utility/version.rs#L16-L20

Added lines #L16 - L20 were not covered by tests
let _ = send_reply(
&ctx,
CrackedMessage::Version {
Expand Down
2 changes: 1 addition & 1 deletion crack-core/src/messaging/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl Display for CrackedMessage {
Self::UserMuted { mention, id } => f.write_str(&format!("{MUTED}\n{mention} {id}")),
Self::UserUnmuted { mention, id } => f.write_str(&format!("{UNMUTED}\n{mention} {id}")),
Self::Version { current, hash } => f.write_str(&format!(
"{} [{}]({}/tag/v{})\n{}({}/latest)\n{}({}/tree/{})",
"{} [{}]({}/tag/v{})\n{}({}/latest)\n{}({}tree/{})",
VERSION,
current,
RELEASES_LINK,
Expand Down
4 changes: 4 additions & 0 deletions cracktunes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ keywords = ["music", "discord", "bot", "crack", "tunes", "cracktunes"]
categories = ["multimedia::audio"]
homepage = "https://cracktun.es/"
repository = "https://git.sr.ht/~cycle-five/cracktunes"
build = "build.rs"

[features]
default = ["crack-tracing", "ignore-presence-log"]
Expand Down Expand Up @@ -67,3 +68,6 @@ tracing-bunyan-formatter = { version = "0.3.0", optional = true }

[dev-dependencies]
sqlx = { workspace = true }

[build-dependencies]
vergen = { workspace = true }
19 changes: 9 additions & 10 deletions cracktunes/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::process::Command;
fn main() {
// use std::process::Command;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// make sure tarpaulin is included in the build.
println!("cargo::rustc-check-cfg=cfg(tarpaulin_include)");
// git hash for the build version.
let output = Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.unwrap();
let git_hash = String::from_utf8(output.stdout).unwrap();
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
println!("cargo:rustc-check-cfg=cfg(tarpaulin_include)");
// Git hash of the build.
vergen::EmitBuilder::builder()
.all_build()
.all_git()
.emit()?;
Ok(())
}

0 comments on commit 76759ea

Please sign in to comment.