|
6 | 6 | //! cargo auto update_automation_tasks_rs |
7 | 7 | //! If you want to customize it, copy the code into main.rs and modify it there. |
8 | 8 |
|
9 | | -use crate::cgl; |
10 | 9 | use crate::cl; |
11 | | -use crate::ende; |
12 | 10 |
|
13 | | -use cargo_auto_lib::CargoTomlPublicApiMethods; |
14 | | -use cargo_auto_lib::ShellCommandLimitedDoubleQuotesSanitizerTrait; |
15 | 11 | #[allow(unused_imports)] |
16 | 12 | pub use cl::{BLUE, GREEN, RED, RESET, YELLOW}; |
17 | 13 |
|
@@ -76,212 +72,3 @@ pub fn panic_set_hook(panic_info: &std::panic::PanicHookInfo) { |
76 | 72 | eprintln!("Location: {file}:{line}:{column}"); |
77 | 73 | } |
78 | 74 | } |
79 | | - |
80 | | -#[allow(dead_code)] |
81 | | -/// cargo doc, then copies to /docs/ folder, because this is a GitHub standard folder |
82 | | -pub fn task_doc() { |
83 | | - let cargo_toml = cl::CargoToml::read(); |
84 | | - cl::auto_cargo_toml_to_md(); |
85 | | - cl::auto_lines_of_code(""); |
86 | | - // In cargo_auto_lib we have sample data that we don't want to change, avoid this lines. |
87 | | - if cargo_toml.package_name() != "cargo_auto_lib" { |
88 | | - cl::auto_plantuml(&cargo_toml.package_repository().unwrap()); |
89 | | - cl::auto_playground_run_code(); |
90 | | - } |
91 | | - cl::auto_md_to_doc_comments(); |
92 | | - |
93 | | - cl::run_shell_command_static("cargo doc --no-deps --document-private-items").unwrap_or_else(|e| panic!("{e}")); |
94 | | - // copy target/doc into docs/ because it is GitHub standard |
95 | | - cl::run_shell_command_static("rsync -a --info=progress2 --delete-after target/doc/ docs/").unwrap_or_else(|e| panic!("{e}")); |
96 | | - |
97 | | - // Create simple index.html file in docs directory |
98 | | - cl::ShellCommandLimitedDoubleQuotesSanitizer::new( |
99 | | - r#"printf "<meta http-equiv=\"refresh\" content=\"0; url={url_sanitized_for_double_quote}/index.html\" />\n" > docs/index.html"#, |
100 | | - ) |
101 | | - .unwrap_or_else(|e| panic!("{e}")) |
102 | | - .arg("{url_sanitized_for_double_quote}", &cargo_toml.package_name().replace("-", "_")) |
103 | | - .unwrap_or_else(|e| panic!("{e}")) |
104 | | - .run() |
105 | | - .unwrap_or_else(|e| panic!("{e}")); |
106 | | - |
107 | | - // pretty html |
108 | | - #[cfg(target_family = "unix")] |
109 | | - cl::auto_doc_tidy_html().unwrap_or_else(|e| panic!("{e}")); |
110 | | - |
111 | | - cl::run_shell_command_static("cargo fmt").unwrap_or_else(|e| panic!("{e}")); |
112 | | - // message to help user with next move |
113 | | - println!( |
114 | | - r#" |
115 | | - {YELLOW}After `cargo auto doc`, ctrl-click on `docs/index.html`. |
116 | | - It will show the index.html in VSCode Explorer, then right-click and choose "Show Preview". |
117 | | - This works inside the CRUSTDE container, because of the extension "Live Preview" |
118 | | - <https://marketplace.visualstudio.com/items?itemName=ms-vscode.live-server> |
119 | | -"# |
120 | | - ); |
121 | | -} |
122 | | - |
123 | | -/// commit and push |
124 | | -pub fn task_commit_and_push(arg_2: Option<String>) { |
125 | | - let Some(message) = arg_2 else { |
126 | | - eprintln!("{RED}Error: Message for commit is mandatory.{RESET}"); |
127 | | - // early exit |
128 | | - return; |
129 | | - }; |
130 | | - |
131 | | - // If needed, ask to create new local git repository |
132 | | - if !cl::git_is_local_repository() { |
133 | | - cl::new_local_repository(&message).unwrap(); |
134 | | - } |
135 | | - |
136 | | - // If needed, ask to create a GitHub remote repository |
137 | | - if !cgl::git_has_remote() || !cgl::git_has_upstream() { |
138 | | - cgl::new_remote_github_repository().unwrap(); |
139 | | - cgl::description_and_topics_to_github(); |
140 | | - } else { |
141 | | - // if description or topics/keywords/tags have changed |
142 | | - cgl::description_and_topics_to_github(); |
143 | | - |
144 | | - // separate commit for docs if they changed, to not make a lot of noise in the real commit |
145 | | - if std::path::Path::new("docs").exists() { |
146 | | - cl::run_shell_command_static(r#"git add docs && git diff --staged --quiet || git commit -m "update docs" "#) |
147 | | - .unwrap_or_else(|e| panic!("{e}")); |
148 | | - } |
149 | | - |
150 | | - cl::add_message_to_unreleased(&message); |
151 | | - // the real commit of code |
152 | | - cl::ShellCommandLimitedDoubleQuotesSanitizer::new( |
153 | | - r#"git add -A && git diff --staged --quiet || git commit -m "{message_sanitized_for_double_quote}" "#, |
154 | | - ) |
155 | | - .unwrap_or_else(|e| panic!("{e}")) |
156 | | - .arg("{message_sanitized_for_double_quote}", &message) |
157 | | - .unwrap_or_else(|e| panic!("{e}")) |
158 | | - .run() |
159 | | - .unwrap_or_else(|e| panic!("{e}")); |
160 | | - |
161 | | - cl::run_shell_command_static("git push").unwrap_or_else(|e| panic!("{e}")); |
162 | | - } |
163 | | -} |
164 | | - |
165 | | -#[allow(dead_code)] |
166 | | -/// create a new release on github |
167 | | -pub fn task_github_new_release() { |
168 | | - let cargo_toml = cl::CargoToml::read(); |
169 | | - let version = cargo_toml.package_version(); |
170 | | - // take care of tags |
171 | | - let tag_name_version = cl::git_tag_sync_check_create_push(&version); |
172 | | - |
173 | | - let github_owner = cargo_toml.github_owner().unwrap(); |
174 | | - let repo_name = cargo_toml.package_name(); |
175 | | - let now_date = cl::now_utc_date_iso(); |
176 | | - let release_name = format!("Version {} ({})", &version, now_date); |
177 | | - let branch = "main"; |
178 | | - |
179 | | - // First, the user must write the content into file RELEASES.md in the section ## Unreleased. |
180 | | - // Then the automation task will copy the content to GitHub release |
181 | | - let version_body_text = cl::body_text_from_releases_md().unwrap(); |
182 | | - // Create a new Version title and modify RELEASES.md. |
183 | | - cl::create_new_version_in_releases_md(&release_name).unwrap(); |
184 | | - |
185 | | - // Commit and push of modified Version in RELEASES.md |
186 | | - cl::ShellCommandLimitedDoubleQuotesSanitizer::new(r#"git add -A && git commit -m "{message_sanitized_for_double_quote}" "#) |
187 | | - .unwrap_or_else(|e| panic!("{e}")) |
188 | | - .arg("{message_sanitized_for_double_quote}", &release_name) |
189 | | - .unwrap_or_else(|e| panic!("{e}")) |
190 | | - .run() |
191 | | - .unwrap_or_else(|e| panic!("{e}")); |
192 | | - |
193 | | - cl::run_shell_command_static("git push").unwrap_or_else(|e| panic!("{e}")); |
194 | | - |
195 | | - // GitHub api call to create the Release |
196 | | - let request = cgl::github_api_create_new_release( |
197 | | - &github_owner, |
198 | | - &repo_name, |
199 | | - &tag_name_version, |
200 | | - &release_name, |
201 | | - branch, |
202 | | - &version_body_text, |
203 | | - ); |
204 | | - let json_value = ende::github_api_token_with_oauth2_mod::send_to_github_api_with_secret_token(request).unwrap(); |
205 | | - // early exit on error |
206 | | - if let Some(error_message) = json_value.get("message") { |
207 | | - eprintln!("{RED}{error_message}{RESET}"); |
208 | | - if let Some(errors) = json_value.get("errors") { |
209 | | - let errors = errors.as_array().unwrap(); |
210 | | - for error in errors.iter() { |
211 | | - if let Some(code) = error.get("code") { |
212 | | - eprintln!("{RED}{code}{RESET}"); |
213 | | - } |
214 | | - } |
215 | | - } |
216 | | - panic!("{RED}Call to GitHub API returned an error.{RESET}") |
217 | | - } |
218 | | - |
219 | | - println!(" {YELLOW}New GitHub release created: {release_name}.{RESET}"); |
220 | | - |
221 | | - // region: upload asset only for executables, not for libraries |
222 | | - |
223 | | - let release_id = json_value.get("id").unwrap().as_i64().unwrap().to_string(); |
224 | | - println!(" {YELLOW}Now uploading release asset. This can take some time if the files are big. Wait...{RESET}"); |
225 | | - // Linux executable binary tar-gz-ed compress files tar.gz |
226 | | - let executable_path = format!("target/release/{repo_name}"); |
227 | | - if std::fs::exists(&executable_path).unwrap() { |
228 | | - let compressed_name = format!("{repo_name}-{tag_name_version}-x86_64-unknown-linux-gnu.tar.gz"); |
229 | | - |
230 | | - cl::ShellCommandLimitedDoubleQuotesSanitizer::new( |
231 | | - r#"tar -zcvf "{compressed_name_sanitized_for_double_quote}" "{executable_path_sanitized_for_double_quote}" "#, |
232 | | - ) |
233 | | - .unwrap_or_else(|e| panic!("{e}")) |
234 | | - .arg("{compressed_name_sanitized_for_double_quote}", &compressed_name) |
235 | | - .unwrap_or_else(|e| panic!("{e}")) |
236 | | - .arg("{executable_path_sanitized_for_double_quote}", &executable_path) |
237 | | - .unwrap_or_else(|e| panic!("{e}")) |
238 | | - .run() |
239 | | - .unwrap_or_else(|e| panic!("{e}")); |
240 | | - |
241 | | - // upload asset |
242 | | - cgl::github_api_upload_asset_to_release(&github_owner, &repo_name, &release_id, &compressed_name); |
243 | | - |
244 | | - cl::ShellCommandLimitedDoubleQuotesSanitizer::new(r#"rm "{compressed_name_sanitized_for_double_quote}" "#) |
245 | | - .unwrap_or_else(|e| panic!("{e}")) |
246 | | - .arg("{compressed_name_sanitized_for_double_quote}", &compressed_name) |
247 | | - .unwrap_or_else(|e| panic!("{e}")) |
248 | | - .run() |
249 | | - .unwrap_or_else(|e| panic!("{e}")); |
250 | | - println!(r#" {YELLOW}Asset uploaded. Open and edit the description on GitHub Releases in the browser.{RESET}"#); |
251 | | - } |
252 | | - |
253 | | - // Windows executable binary zipped |
254 | | - // Prerequisites: Install zip into the container from the parent WSL: |
255 | | - // podman exec --user=root crustde_vscode_cnt apt-get install -y zip |
256 | | - // compress file with zip because it is Windows |
257 | | - let executable_path = format!("target/x86_64-pc-windows-gnu/release/{repo_name}.exe"); |
258 | | - if std::fs::exists(&executable_path).unwrap() { |
259 | | - let compressed_name = format!("{repo_name}-{tag_name_version}-x86_64-pc-windows-gnu.zip"); |
260 | | - |
261 | | - cl::ShellCommandLimitedDoubleQuotesSanitizer::new( |
262 | | - r#"zip "{compressed_name_sanitized_for_double_quote}" "{executable_path_sanitized_for_double_quote}" "#, |
263 | | - ) |
264 | | - .unwrap_or_else(|e| panic!("{e}")) |
265 | | - .arg("{compressed_name_sanitized_for_double_quote}", &compressed_name) |
266 | | - .unwrap_or_else(|e| panic!("{e}")) |
267 | | - .arg("{executable_path_sanitized_for_double_quote}", &executable_path) |
268 | | - .unwrap_or_else(|e| panic!("{e}")) |
269 | | - .run() |
270 | | - .unwrap_or_else(|e| panic!("{e}")); |
271 | | - |
272 | | - // upload asset |
273 | | - cgl::github_api_upload_asset_to_release(&github_owner, &repo_name, &release_id, &compressed_name); |
274 | | - |
275 | | - cl::ShellCommandLimitedDoubleQuotesSanitizer::new(r#"rm "{compressed_name_sanitized_for_double_quote}" "#) |
276 | | - .unwrap_or_else(|e| panic!("{e}")) |
277 | | - .arg("{compressed_name_sanitized_for_double_quote}", &compressed_name) |
278 | | - .unwrap_or_else(|e| panic!("{e}")) |
279 | | - .run() |
280 | | - .unwrap_or_else(|e| panic!("{e}")); |
281 | | - |
282 | | - println!(r#" {YELLOW}Asset uploaded. Open and edit the description on GitHub Releases in the browser.{RESET}"#); |
283 | | - } |
284 | | - // endregion: upload asset only for executables, not for libraries |
285 | | - |
286 | | - println!(r#"{GREEN}https://github.com/{github_owner}/{repo_name}/releases{RESET} "#); |
287 | | -} |
0 commit comments