aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-29 21:08:07 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-29 21:28:44 +0800
commitc2a786e63c31b1c090d7a43db2484c390f9eb95f (patch)
tree5488b4904b01b4614dcb3e59ff3f50a51d3fc62f
parent0617ce6a527567f4545558fda632dd8d7e06606d (diff)
Prompt user before temporarily committing in CI
-rw-r--r--dev_tools/src/bin/ci.rs44
1 files changed, 31 insertions, 13 deletions
diff --git a/dev_tools/src/bin/ci.rs b/dev_tools/src/bin/ci.rs
index 0547c34..3169b95 100644
--- a/dev_tools/src/bin/ci.rs
+++ b/dev_tools/src/bin/ci.rs
@@ -1,3 +1,4 @@
+use std::io::Write;
use std::process::exit;
use tools::{cargo_tomls, eprintln_cargo_style, println_cargo_style, run_cmd};
@@ -10,36 +11,53 @@ fn main() {
let needs_commit_temp = !{ run_cmd!("git diff-index --quiet HEAD --").is_ok() };
if needs_commit_temp {
- run_cmd!("git add .").unwrap();
- run_cmd!("git commit -m \"CI Temp\"").unwrap();
+ print!("Working tree is not clean, temporarily commit? [y/N]:");
+ std::io::stdout().flush().unwrap();
+ let mut input = String::new();
+ std::io::stdin().read_line(&mut input).unwrap();
+ let input = input.trim();
+ if input == "y" || input == "Y" || input == "yes" || input == "Yes" {
+ run_cmd!("git add .").unwrap();
+ run_cmd!("git commit -m \"[DO NOT PUSH] CI TEMP [DO NOT PUSH]\"").unwrap();
+ } else {
+ eprintln_cargo_style!("Aborting.");
+ exit(2)
+ }
}
if let Err(exit_code) = ci() {
- if needs_commit_temp {
- run_cmd!("git restore .").unwrap();
- run_cmd!("git reset --soft HEAD~1").unwrap();
- }
+ restore_workspace().unwrap();
exit(exit_code)
}
- println_cargo_style!("Done: All check passed!");
-
let is_worktree_clean = run_cmd!("git diff-index --quiet HEAD --").is_ok();
if !is_worktree_clean {
- eprintln_cargo_style!("Documents needs refresh!");
+ eprintln_cargo_style!("The repository was contaminated during CI, failing!");
+
+ // Print git status
+ println!();
+ let _ = run_cmd!("git status");
+
if needs_commit_temp {
- run_cmd!("git restore .").unwrap();
- run_cmd!("git reset --soft HEAD~1").unwrap();
+ restore_workspace().unwrap();
}
exit(1)
}
+ println_cargo_style!("Done: All check passed!");
+
if needs_commit_temp {
- run_cmd!("git restore .").unwrap();
- run_cmd!("git reset --soft HEAD~1").unwrap();
+ restore_workspace().unwrap();
}
}
+fn restore_workspace() -> Result<(), i32> {
+ run_cmd!("git reset --hard --quiet")?;
+ run_cmd!("git reset --soft HEAD~1 --quiet")?;
+ run_cmd!("git reset --quiet")?;
+ Ok(())
+}
+
fn ci() -> Result<(), i32> {
build_all()?;
clippy_all()?;