Skip to content

Commit

Permalink
chore(clusters): remove git as a dependency for cluster util (#931)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->
Fixes RVT-3781
## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Jun 25, 2024
1 parent 7c2897a commit 7c7eec3
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 54 deletions.
90 changes: 89 additions & 1 deletion svc/Cargo.lock

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

2 changes: 1 addition & 1 deletion svc/pkg/cluster/util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ types = { path = "../../../../lib/types/core" }
uuid = { version = "1", features = ["v4", "serde"] }

[build-dependencies]
merkle_hash = "3.6"
hex = "0.4"
sha2 = "0.10"
tokio = { version = "1.29", features = ["full"] }
58 changes: 6 additions & 52 deletions svc/pkg/cluster/util/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use sha2::{Digest, Sha256};
use tokio::{fs, process::Command};
use tokio::fs;
use merkle_hash::MerkleTree;

// NOTE: This only gets the hash of the folder. Any template variables changed in the install scripts
// will not update the hash.
Expand All @@ -23,57 +23,11 @@ async fn main() {
// Add rereun statement
println!("cargo:rerun-if-changed={}", server_install_path.display());

let mut util_path = current_dir.clone();
util_path.pop();
let util_path = util_path
.join("worker")
.join("src")
.join("workers")
.join("server_install");

// Compute the git diff between the current branch and the local changes
let cmd = Command::new("git")
.arg("diff")
.arg("--minimal")
.arg("HEAD")
.arg("--")
.arg(util_path)
.output()
.await
let tree = MerkleTree::builder(server_install_path.display().to_string())
.hash_names(true)
.build()
.unwrap();

if !cmd.status.success() {
panic!(
"failed to get git diff ({}):\n{}",
cmd.status,
String::from_utf8(cmd.stderr).unwrap()
);
}

let source_diff = String::from_utf8(cmd.stdout).unwrap();

// If there is no diff, use the git commit hash
let source_hash = if source_diff.is_empty() {
let cmd = Command::new("git")
.arg("rev-parse")
.arg("HEAD:svc/pkg/cluster/worker/src/workers/server_install")
.output()
.await
.unwrap();

if !cmd.status.success() {
panic!(
"failed to get git diff ({}):\n{}",
cmd.status,
String::from_utf8(cmd.stderr).unwrap()
);
}

String::from_utf8(cmd.stdout).unwrap()
} else {
// Get hash of diff
hex::encode(Sha256::digest(source_diff.as_bytes()))
};
let source_hash = hex::encode(tree.root.item.hash);

fs::write(out_dir.join("hash.txt"), source_hash.trim())
.await
Expand Down

0 comments on commit 7c7eec3

Please sign in to comment.