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

Log Grouping on GitHub Actions #55

Closed
chrissimon-au opened this issue Nov 21, 2023 · 3 comments
Closed

Log Grouping on GitHub Actions #55

chrissimon-au opened this issue Nov 21, 2023 · 3 comments
Assignees

Comments

@chrissimon-au
Copy link
Contributor

Github Actions supports grouping log entries by emitting "workflow commands".

It would be quite nice if you could opt in to have the workflow commands emitted at the start and end of top-level stages (or pipelines). (They don't yet support nested groupings but once that's done, grouping pipelines and stages would be good.)

A few ideas on what this could look like...

Option to log before and after each stage

pipeline "name" {
   beforeEachStageEcho (fun ctx -> $"::group::{ctx.Name}")
   afterEachStageEcho (fun ctx -> $"::endgroup::")
}

Option to run arbitrary code before and after each stage

More flexible, but maybe more than is needed?

pipeline "name" {
   beforeEachStage (fun ctx -> ctx.RunCommand($"echo ::group::{ctx.Name}")
   afterEachStage (fun ctx -> ctx.RunCommand($"echo ::endgroup::")
}

Log group optimised

More restricted, but would still allow to take advantage of other log grouping, e.g. Azure Devops Piplines has a similar feature.

pipeline "name" {
   logGroups "::group::{name}" "::endgroup::"
}

Github Actions specific

Far more restrictive, but easiest to configure!

pipeline "name" {
   githubActionsLogGroups true
}
@chrissimon-au
Copy link
Contributor Author

I did experiment with an approach for doing this by composing nested stages:

let logGroup (s: Internal.StageContext) =
    stage s.Name {
        echo $"::group::{s.Name}"
        s
        echo "::endgroup::"
    }

Used like so:

pipeline "name" {

   logGroup <| stage "Name" {
      echo "here"
   }
}

But it wasn't ideal - when collapsed it looks like:

image

When not collapsed, it looks like:

image

The extra nested stages are redundant, and there is a lot of stage info logged before and after the collapse, which clutters things.

@albertwoo albertwoo self-assigned this Nov 21, 2023
@albertwoo
Copy link
Contributor

@chrissimon-au nice idea. And I like the "Option to run arbitrary code before and after each stage", implemented like below:

pipeline "test" {
    description "Format code and run tests"
    runBeforeEachStage (fun ctx -> if ctx.GetStageLevel() = 0 then printfn $"::group::{ctx.Name}")
    runAfterEachStage (fun ctx -> if ctx.GetStageLevel() = 0 then printfn "::endgroup::")
    stage_checkEnv
    stage_lint
    stage_test
    runIfOnlySpecified
}

It should be available in 1.0.5. 🎉

@chrissimon-au
Copy link
Contributor Author

Nice, thanks for the quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants