Skip to content

Commit

Permalink
Group logs on GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 6, 2023
1 parent 58d1d91 commit 100d7c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/.cspell/project-dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
binstall
compat
endgroup
pacman
qpmember
subcrate
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
1 change: 1 addition & 0 deletions tests/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 100d7c9

Please sign in to comment.