From c2abf3fcb8d4c3e09ed37ee68bd66faa42a088b3 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Sun, 5 May 2024 00:44:22 -0400 Subject: [PATCH] fix: Git sha not present during `cargo install` (#176) --- Cargo.lock | 20 +++++++++--------- Cargo.toml | 7 ++++--- Earthfile | 12 ++++++++--- README.md | 2 +- build.rs | 42 +------------------------------------- src/commands/bug_report.rs | 7 ++----- src/commands/template.rs | 6 +++++- 7 files changed, 32 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b652638..42e5192 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -405,9 +405,9 @@ dependencies = [ [[package]] name = "const_fn" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" +checksum = "373e9fafaa20882876db20562275ff58d50e0caa2590077fe7ce7bef90211d0d" [[package]] name = "const_format" @@ -641,9 +641,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.18.2" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b3ba52851e73b46a4c3df1d89343741112003f0f6f13beb0dfac9e457c3fdcd" +checksum = "232e6a7bfe35766bf715e55a88b39a700596c0ccfd88cd3680b4cdb40d66ef70" dependencies = [ "bitflags 2.4.2", "libc", @@ -790,9 +790,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "jobserver" -version = "0.1.28" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] @@ -849,9 +849,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.15" +version = "1.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" +checksum = "5e143b5e666b2695d28f6bca6497720813f699c9602dd7f5cac91008b8ada7f9" dependencies = [ "cc", "libc", @@ -1676,9 +1676,9 @@ checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] diff --git a/Cargo.toml b/Cargo.toml index d5722f3..570abbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,8 @@ license.workspace = true [package.metadata.release] pre-release-hook = ["git", "cliff", "-o", "CHANGELOG.md", "--tag", "{{version}}"] pre-release-replacements = [ - { file = "install.sh", search="VERSION=v\\d+\\.\\d+\\.\\d+", replace = "VERSION=v{{version}}" } + { file = "install.sh", search = "VERSION=v\\d+\\.\\d+\\.\\d+", replace = "VERSION=v{{version}}" }, + { file = "README.md", search = "v\\d+\\.\\d+\\.\\d+", replace = "v{{version}}" } ] [dependencies] @@ -64,7 +65,7 @@ open = "5" os_info = "3.7" # update os module config and tests when upgrading os_info requestty = { version = "0.5", features = ["macros", "termion"] } semver = { version = "1.0.22", features = ["serde"] } -shadow-rs = { version = "0.26" } +shadow-rs = "0.26" urlencoding = "2.1.3" users = "0.11.0" @@ -88,7 +89,7 @@ default = [] rusty-hook = "0.11.2" [build-dependencies] -shadow-rs = { version = "0.26.1", default-features = false } +shadow-rs = "0.26" dunce = "1.0.4" [lints] diff --git a/Earthfile b/Earthfile index ce48c82..d51c98a 100644 --- a/Earthfile +++ b/Earthfile @@ -53,15 +53,21 @@ build-scripts: FROM alpine LABEL org.opencontainers.image.source="https://github.com/blue-build/cli" COPY --dir scripts/ / - FOR script IN $(ls /scripts | grep -e '.*\.sh$') + FOR script IN "$(ls /scripts | grep -e '.*\.sh$')" RUN echo "Making ${script} executable" && \ - chmod +x scripts/${script} + chmod +x "scripts/${script}" END DO --pass-args +LABELS ARG EARTHLY_GIT_HASH - SAVE IMAGE --push $IMAGE:$EARTHLY_GIT_HASH-build-scripts + SAVE IMAGE --push "$IMAGE:$EARTHLY_GIT_HASH-build-scripts" + + ARG TAGGED="false" + ARG LATEST="false" + IF [ "$TAGGED" = "true" ] && [ "$LATEST" ] + SAVE IMAGE --push "$IMAGE:latest-build-scripts" + END blue-build-cli: ARG BASE_IMAGE="registry.fedoraproject.org/fedora-toolbox" diff --git a/README.md b/README.md index 4651679..a564a76 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ A CLI tool built for creating Containerfile templates based on the Ublue Communi This is the best way to install as it gives you the opportunity to build for your specific environment. ```bash -cargo install --locked blue-build +cargo install --git https://github.com/blue-build/cli.git --tag v0.8.6 ``` ### Podman/Docker diff --git a/build.rs b/build.rs index 2050cad..b37dff2 100644 --- a/build.rs +++ b/build.rs @@ -1,45 +1,5 @@ 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(()) + shadow_rs::new() } diff --git a/src/commands/bug_report.rs b/src/commands/bug_report.rs index 2a8e905..8f29a53 100644 --- a/src/commands/bug_report.rs +++ b/src/commands/bug_report.rs @@ -33,10 +33,7 @@ pub struct BugReportCommand { impl BlueBuildCommand for BugReportCommand { fn try_run(&mut self) -> anyhow::Result<()> { - debug!( - "Generating bug report for hash: {}\n", - shadow::BB_COMMIT_HASH - ); + debug!("Generating bug report for hash: {}\n", shadow::COMMIT_HASH); debug!("Shadow Versioning:\n{}", shadow::VERSION.trim()); self.create_bugreport() @@ -295,7 +292,7 @@ fn generate_github_issue( .bb_version(shadow::PKG_VERSION) .build_rust_channel(shadow::BUILD_RUST_CHANNEL) .build_time(shadow::BUILD_TIME) - .git_commit_hash(shadow::BB_COMMIT_HASH) + .git_commit_hash(shadow::COMMIT_HASH) .os_name(format!("{}", environment.os_type)) .os_version(format!("{}", environment.os_version)) .pkg_branch_tag(get_pkg_branch_tag()) diff --git a/src/commands/template.rs b/src/commands/template.rs index 440bf4b..3d1ef20 100644 --- a/src/commands/template.rs +++ b/src/commands/template.rs @@ -119,7 +119,11 @@ impl TemplateCommand { .recipe(&recipe_de) .recipe_path(recipe_path.as_path()) .registry(self.get_registry()) - .exports_tag(shadow::BB_COMMIT_HASH) + .exports_tag(if shadow::COMMIT_HASH.is_empty() { + "latest" + } else { + shadow::COMMIT_HASH + }) .build(); let output_str = template.render()?;