I noticed that making changes to the exports script before a release could cause modules to not build properly if breaking changes got pushed out. To prevent this, I'm making it so that the hash of the commit is put in the tag for the exports script image and that the CLI tool will use that hash when building the `Containerfile`.
45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use shadow_rs::SdResult;
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
use std::process::Command;
|
|
|
|
fn main() -> SdResult<()> {
|
|
shadow_rs::new_hook(hook)
|
|
}
|
|
|
|
fn hook(mut file: &File) -> SdResult<()> {
|
|
let hash = Command::new("git")
|
|
.args(["rev-parse", "HEAD"])
|
|
.output()
|
|
.map(|x| {
|
|
String::from_utf8(x.stdout)
|
|
.ok()
|
|
.map(|x| x.trim().to_string())
|
|
})
|
|
.unwrap_or(None);
|
|
|
|
let short_hash = Command::new("git")
|
|
.args(["rev-parse", "--short", "HEAD"])
|
|
.output()
|
|
.map(|x| {
|
|
String::from_utf8(x.stdout)
|
|
.ok()
|
|
.map(|x| x.trim().to_string())
|
|
})
|
|
.unwrap_or(None);
|
|
|
|
let hook_const: &str = &format!(
|
|
"{}\n{}",
|
|
&format!(
|
|
"pub const BB_COMMIT_HASH: &str = \"{}\";",
|
|
hash.unwrap_or_default()
|
|
),
|
|
&format!(
|
|
"pub const BB_COMMIT_HASH_SHORT: &str = \"{}\";",
|
|
short_hash.unwrap_or_default()
|
|
)
|
|
);
|
|
|
|
writeln!(file, "{hook_const}")?;
|
|
Ok(())
|
|
}
|