Repository: taiki-e/cargo-hack (language: rust)

Issue:
Easier-to-browse logs in CI
Modern CIs group all of the output for a command, making it easy to see cause-and-affect but this breaks down when there are "do everything" commands.

Some CI systems support special output directives so commands can provide their own grouping, e.g. [github](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines).  I feel like detecting a CI system and emitting these directives would improve the experience of using cargo-hack.

Downsides
- Piecemeal support for different CI systems as they implement it and cargo-hack supports it
- Raw logs will have extra chatter


Discussion / hints:

Fix patch:
diff --git a/.github/.cspell/project-dictionary.txt b/.github/.cspell/project-dictionary.txt
index e9ba2dbc..cc5bef4d 100644
--- a/.github/.cspell/project-dictionary.txt
+++ b/.github/.cspell/project-dictionary.txt
@@ -1,5 +1,6 @@
 binstall
 compat
+endgroup
 pacman
 qpmember
 subcrate
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3f048e33..c7556f5d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -62,11 +62,17 @@ jobs:
       - name: Install Rust
         run: rustup toolchain add ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
       - run: rustup toolchain add nightly --no-self-update
-      - uses: taiki-e/install-action@cargo-hack
-      - uses: taiki-e/install-action@cargo-minimal-versions
       - run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >>"${GITHUB_ENV}"
         if: startsWith(matrix.os, 'windows')
       - run: cargo test --workspace --all-features
+      - run: |
+          set -euxo pipefail
+          cargo install --path . --debug
+          cd tests/fixtures/real
+          cargo hack check --feature-powerset --workspace
+          cargo uninstall cargo-hack
+      - uses: taiki-e/install-action@cargo-hack
+      - uses: taiki-e/install-action@cargo-minimal-versions
       - run: cargo minimal-versions build --workspace --all-features --ignore-private
 
   build:
diff --git a/src/context.rs b/src/context.rs
index 237ad59f..c36a1b0b 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -28,6 +28,7 @@ pub(crate) struct Context {
     pub(crate) restore: restore::Manager,
     pub(crate) current_dir: PathBuf,
     pub(crate) version_range: Option<Vec<(u32, String)>>,
+    pub(crate) use_github_action_grouping: bool,
 }
 
 impl Context {
@@ -74,6 +75,8 @@ impl Context {
             restore,
             current_dir: env::current_dir()?,
             version_range: None,
+            // TODO: should be optional?
+            use_github_action_grouping: env::var_os("GITHUB_ACTIONS").is_some(),
         };
 
         this.version_range = this
diff --git a/src/main.rs b/src/main.rs
index d919326c..7a8036f4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -476,7 +476,7 @@ fn exec_cargo_inner(
     line: &mut ProcessBuilder<'_>,
     progress: &mut Progress,
 ) -> Result<()> {
-    if progress.count != 0 && !cx.print_command_list {
+    if progress.count != 0 && !cx.print_command_list && !cx.use_github_action_grouping {
         eprintln!();
     }
     progress.count += 1;
@@ -498,7 +498,19 @@ fn exec_cargo_inner(
         write!(msg, "running {line} on {}", cx.packages(id).name).unwrap();
     }
     write!(msg, " ({}/{})", progress.count, progress.total).unwrap();
-    info!("{msg}");
+    let _guard = if cx.use_github_action_grouping {
+        struct Guard;
+        impl Drop for Guard {
+            fn drop(&mut self) {
+                println!("::endgroup::");
+            }
+        }
+        println!("::group::{msg}");
+        Some(Guard)
+    } else {
+        info!("{msg}");
+        None
+    };
 
     line.run()
 }


Test patch:
diff --git a/tests/auxiliary/mod.rs b/tests/auxiliary/mod.rs
index 5e222051..885c9ac3 100644
--- a/tests/auxiliary/mod.rs
+++ b/tests/auxiliary/mod.rs
@@ -22,6 +22,7 @@ pub fn cargo_bin_exe() -> Command {
     cmd.env("CARGO_HACK_DENY_WARNINGS", "true");
     cmd.env_remove("RUSTFLAGS");
     cmd.env_remove("CARGO_TERM_COLOR");
+    cmd.env_remove("GITHUB_ACTIONS");
     cmd
 }