Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group logs on GitHub Actions #206

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
Comment on lines +78 to +79
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added opt-out flag in #214.

};

this.version_range = this
Expand Down
16 changes: 14 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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