Skip to content

Commit

Permalink
feat: write in the deployment file its type
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Aug 21, 2024
1 parent 80121e0 commit d011e43
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
32 changes: 29 additions & 3 deletions deploy-multi-chain/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use serde_json::Value;
use std::env;
use std::fs;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::Path;
use std::process::Command;
use std::time::{SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -83,6 +85,9 @@ fn main() {
fs::create_dir_all(parent).expect("Failed to create directories");
}

// Append the type of deployment at the start of the deployment file
append_type_of_deployment(&deployment_path, broadcast_deployment.is_empty());

for chain in provided_chains {
let env_var = "FOUNDRY_PROFILE=optimized";
let command = "forge";
Expand Down Expand Up @@ -129,7 +134,7 @@ fn main() {
&script_name,
&chain,
&String::from_utf8_lossy(&output.stdout),
&broadcast_deployment,
broadcast_deployment.is_empty(),
);
}
}
Expand All @@ -141,6 +146,22 @@ fn main() {
.expect("Failed to run Prettier");
}

fn append_type_of_deployment(deployment_path: &str, is_broadcast_deployment: bool) {
let message = if is_broadcast_deployment {
" # This is a deployment simulation\n\n\n"
} else {
" # This deployment is broadcasted\n"
};

OpenOptions::new()
.append(true)
.create(true)
.open(deployment_path)
.expect("Failed to open the file")
.write_all(message.as_bytes())
.expect("Failed to write to the file");
}

// Function that reads the TOML chain configurations and extracts them
fn get_all_chains() -> Vec<String> {
// Define the path to the TOML file
Expand Down Expand Up @@ -199,15 +220,20 @@ fn get_deployment_path(is_deterministic: bool, with_timestamp: bool) -> String {
deployment_path
}

fn move_broadcast_file(script_name: &str, chain: &str, output: &str, broadcast_deployment: &str) {
fn move_broadcast_file(
script_name: &str,
chain: &str,
output: &str,
is_broadcast_deployment: bool,
) {
// Find the chain_id in the `output`
let chain_id = output
.split(&format!("broadcast/{}/", script_name))
.nth(1)
.and_then(|s| s.split('/').next())
.unwrap_or("");

let broadcast_file_path = if broadcast_deployment.is_empty() {
let broadcast_file_path = if is_broadcast_deployment {
format!(
"../broadcast/{}/{}/dry-run/run-latest.json",
script_name, chain_id
Expand Down
4 changes: 2 additions & 2 deletions script/protocol/Protocol.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ abstract contract ProtocolScript is BaseScript {
// Set the deployment file path.
deploymentFile = string.concat("deployments/", deterministicOrNot, ".md");

// Create the file .
vm.writeFile({ path: deploymentFile, data: string.concat("# ", nameMap[block.chainid], "\n\n") });
// Append the chain name to the deployment file.
_appendToFile(string.concat("# ", nameMap[block.chainid], "\n\n"));
}

/// @dev Function to append the deployed addresses to the deployment file.
Expand Down

0 comments on commit d011e43

Please sign in to comment.