Skip to content

Commit

Permalink
feat: make checked files collapsible
Browse files Browse the repository at this point in the history
  • Loading branch information
BD103 committed Mar 12, 2024
1 parent 3e0c94d commit b7ef2af
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions write-rustdoc-hide-lines/src/main.rs
Expand Up @@ -31,26 +31,41 @@ fn check(folders: impl Iterator<Item = PathBuf> + ExactSizeIterator) -> ExitCode
// An aggregate list of all unformatted files, empty by default.
let mut unformatted_files = Vec::new();

// Detect if we're running through Github Actions or not.
// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
let is_ci = env::var("GITHUB_ACTIONS").is_ok_and(|x| x == "true");

for folder in folders {
println!("\nChecking folder {:?}", folder);
if is_ci {
// Create an collapsible group for all files checked.
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines
println!("::group::Checking folder {:?}", folder);
} else {
println!("\nChecking folder {:?}", folder);
}

// Checks folders, exiting early if an error occurred.
match formatter::check(&folder) {
// Merge new unformatted files into existing unformatted files.
Ok(mut unformatted) => unformatted_files.append(&mut unformatted),
Err(error) => {
if is_ci {
// End group if an error occured, so it is not hidden.

Check warning on line 53 in write-rustdoc-hide-lines/src/main.rs

View workflow job for this annotation

GitHub Actions / typos

"occured" should be "occurred".
println!("::endgroup::");
}

eprintln!("Error: {}", error);

return ExitCode::FAILURE;
}
}

if is_ci {
println!("::endgroup::");
}
}

if !unformatted_files.is_empty() {
// Detect if we're running through Github Actions or not.
// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
let is_ci = env::var("GITHUB_ACTIONS").is_ok_and(|x| x == "true");

eprintln!("\nThe following files are not formatted:");

for path in unformatted_files {
Expand Down

0 comments on commit b7ef2af

Please sign in to comment.