From c2a786e63c31b1c090d7a43db2484c390f9eb95f Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 29 May 2026 21:08:07 +0800 Subject: Prompt user before temporarily committing in CI --- dev_tools/src/bin/ci.rs | 44 +++++++++++++++++++++++++++++++------------- 1 file 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()?; -- cgit