Skip to content

Commit fb1d8c5

Browse files
authored
Merge pull request #122 from movementlabsxyz/l-monninger/movement-release-builder
Movement Labs Release Builder
2 parents 4b2f301 + ee6f0e9 commit fb1d8c5

File tree

7 files changed

+1755
-12932
lines changed

7 files changed

+1755
-12932
lines changed

aptos-move/aptos-release-builder/src/components/framework.rs

+71-34
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use aptos_temppath::TempPath;
88
use aptos_types::account_address::AccountAddress;
99
use git2::Repository;
1010
use serde::{Deserialize, Serialize};
11+
use std::path::PathBuf;
1112

1213
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Debug)]
1314
pub struct FrameworkReleaseConfig {
@@ -24,7 +25,67 @@ pub fn generate_upgrade_proposals(
2425
next_execution_hash: Vec<u8>,
2526
) -> Result<Vec<(String, String)>> {
2627
const APTOS_GIT_PATH: &str = "https://github.com/aptos-labs/aptos-core.git";
28+
generate_upgrade_proposals_with_repo(config, is_testnet, next_execution_hash, APTOS_GIT_PATH)
29+
}
30+
31+
pub fn generate_upgrade_proposals_with_repo(
32+
config: &FrameworkReleaseConfig,
33+
is_testnet: bool,
34+
next_execution_hash: Vec<u8>,
35+
repo_str: &str,
36+
) -> Result<Vec<(String, String)>> {
37+
let mut result = vec![];
38+
39+
let (commit_info, release_packages) = generate_upgrade_proposals_release_packages_with_repo(
40+
config,
41+
is_testnet,
42+
next_execution_hash.clone(),
43+
repo_str,
44+
)?;
45+
46+
for (account, release, move_script_path, script_name) in release_packages.into_iter() {
47+
// If we're generating a single-step proposal on testnet
48+
if is_testnet && next_execution_hash.is_empty() {
49+
release.generate_script_proposal_testnet(account, move_script_path.clone())?;
50+
// If we're generating a single-step proposal on mainnet
51+
} else if next_execution_hash.is_empty() {
52+
release.generate_script_proposal(account, move_script_path.clone())?;
53+
// If we're generating a multi-step proposal
54+
} else {
55+
let next_execution_hash_bytes = if result.is_empty() {
56+
next_execution_hash.clone()
57+
} else {
58+
get_execution_hash(&result)
59+
};
60+
release.generate_script_proposal_multi_step(
61+
account,
62+
move_script_path.clone(),
63+
next_execution_hash_bytes,
64+
)?;
65+
};
2766

67+
let mut script = format!(
68+
"// Framework commit hash: {}\n// Builder commit hash: {}\n",
69+
commit_info,
70+
aptos_build_info::get_git_hash()
71+
);
72+
73+
script.push_str(&std::fs::read_to_string(move_script_path.as_path())?);
74+
75+
result.push((script_name, script));
76+
}
77+
Ok(result)
78+
}
79+
80+
pub fn generate_upgrade_proposals_release_packages_with_repo(
81+
config: &FrameworkReleaseConfig,
82+
is_testnet: bool,
83+
next_execution_hash: Vec<u8>,
84+
repo_str: &str,
85+
) -> Result<(
86+
String,
87+
Vec<(AccountAddress, ReleasePackage, PathBuf, String)>,
88+
)> {
2889
let mut package_path_list = [
2990
("0x1", "aptos-move/framework/move-stdlib"),
3091
("0x1", "aptos-move/framework/aptos-stdlib"),
@@ -33,14 +94,14 @@ pub fn generate_upgrade_proposals(
3394
("0x4", "aptos-move/framework/aptos-token-objects"),
3495
];
3596

36-
let mut result: Vec<(String, String)> = vec![];
97+
let mut result = vec![];
3798

3899
let temp_root_path = TempPath::new();
39100
temp_root_path.create_as_dir()?;
40101

41102
let commit_info = if let Some(revision) = &config.git_hash {
42103
// If a commit hash is set, clone the repo from github and checkout to desired hash to a local temp directory.
43-
let repository = Repository::clone(APTOS_GIT_PATH, temp_root_path.path())?;
104+
let repository = Repository::clone(repo_str, temp_root_path.path())?;
44105
let (commit, _) = repository.revparse_ext(revision.as_str())?;
45106
let commit_info = commit
46107
.describe(&git2::DescribeOptions::default())?
@@ -100,37 +161,13 @@ pub fn generate_upgrade_proposals(
100161
..BuildOptions::default()
101162
};
102163
let package = BuiltPackage::build(package_path, options)?;
103-
let release = ReleasePackage::new(package)?;
104-
105-
// If we're generating a single-step proposal on testnet
106-
if is_testnet && next_execution_hash.is_empty() {
107-
release.generate_script_proposal_testnet(account, move_script_path.clone())?;
108-
// If we're generating a single-step proposal on mainnet
109-
} else if next_execution_hash.is_empty() {
110-
release.generate_script_proposal(account, move_script_path.clone())?;
111-
// If we're generating a multi-step proposal
112-
} else {
113-
let next_execution_hash_bytes = if result.is_empty() {
114-
next_execution_hash.clone()
115-
} else {
116-
get_execution_hash(&result)
117-
};
118-
release.generate_script_proposal_multi_step(
119-
account,
120-
move_script_path.clone(),
121-
next_execution_hash_bytes,
122-
)?;
123-
};
124-
125-
let mut script = format!(
126-
"// Framework commit hash: {}\n// Builder commit hash: {}\n",
127-
commit_info,
128-
aptos_build_info::get_git_hash()
129-
);
130-
131-
script.push_str(&std::fs::read_to_string(move_script_path.as_path())?);
132-
133-
result.push((script_name, script));
164+
result.push((
165+
account,
166+
ReleasePackage::new(package)?,
167+
move_script_path,
168+
script_name,
169+
));
134170
}
135-
Ok(result)
171+
172+
Ok((commit_info, result))
136173
}

aptos-move/aptos-release-builder/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ pub fn initialize_aptos_core_path(overriden_path: Option<PathBuf>) {
4343
};
4444
}
4545

46-
pub(crate) fn aptos_core_path() -> PathBuf {
46+
pub fn aptos_core_path() -> PathBuf {
4747
APTOS_CORE_PATH
4848
.get_or_init(aptos_core_path_at_compile_time)
4949
.clone()
5050
}
5151

52-
pub(crate) fn aptos_framework_path() -> PathBuf {
52+
pub fn aptos_framework_path() -> PathBuf {
5353
let mut path = aptos_core_path();
5454
path.push("aptos-move/framework/aptos-framework");
5555
path

0 commit comments

Comments
 (0)