@@ -8,6 +8,7 @@ use aptos_temppath::TempPath;
8
8
use aptos_types:: account_address:: AccountAddress ;
9
9
use git2:: Repository ;
10
10
use serde:: { Deserialize , Serialize } ;
11
+ use std:: path:: PathBuf ;
11
12
12
13
#[ derive( Serialize , Deserialize , Clone , Eq , PartialEq , Debug ) ]
13
14
pub struct FrameworkReleaseConfig {
@@ -24,7 +25,67 @@ pub fn generate_upgrade_proposals(
24
25
next_execution_hash : Vec < u8 > ,
25
26
) -> Result < Vec < ( String , String ) > > {
26
27
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
+ } ;
27
66
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
+ ) > {
28
89
let mut package_path_list = [
29
90
( "0x1" , "aptos-move/framework/move-stdlib" ) ,
30
91
( "0x1" , "aptos-move/framework/aptos-stdlib" ) ,
@@ -33,14 +94,14 @@ pub fn generate_upgrade_proposals(
33
94
( "0x4" , "aptos-move/framework/aptos-token-objects" ) ,
34
95
] ;
35
96
36
- let mut result: Vec < ( String , String ) > = vec ! [ ] ;
97
+ let mut result = vec ! [ ] ;
37
98
38
99
let temp_root_path = TempPath :: new ( ) ;
39
100
temp_root_path. create_as_dir ( ) ?;
40
101
41
102
let commit_info = if let Some ( revision) = & config. git_hash {
42
103
// 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 ( ) ) ?;
44
105
let ( commit, _) = repository. revparse_ext ( revision. as_str ( ) ) ?;
45
106
let commit_info = commit
46
107
. describe ( & git2:: DescribeOptions :: default ( ) ) ?
@@ -100,37 +161,13 @@ pub fn generate_upgrade_proposals(
100
161
..BuildOptions :: default ( )
101
162
} ;
102
163
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
+ ) ) ;
134
170
}
135
- Ok ( result)
171
+
172
+ Ok ( ( commit_info, result) )
136
173
}
0 commit comments