Skip to content

Add support for a "group-by-task" output format #2941

Description

@jonathanio

Description

When working with output: group in multi-cmd tasks, the grouping is at a per-cmd level, rather than at the level of each individual task. I've been doing a lot of refactoring recently, with some of my Taskfiles going from something like:

cmds:
  - cmd: |-
      if test; then
        run-cmd
        status=${?}
        echo "${status}" > .status-code
        if [[ ${?} -ne 0 ]]; then
          echo "(red)Failed!"
          exit "${status}"
        else
          echo "(green)Passed"
        fi

to:

cmds:
  - defer: "{{ if .EXIT_CODE }}echo '(red)Failed!'{{ end }}"
  - defer: "echo '{{ default 0 .EXIT_CODE }}' > .status-code"
  - cmd: run-cmd
  - cmd: echo "(green)Passed"

Which is a fair bit cleaner, and I can also then run multiple cmd blocks within the error/exit handling steps, which is nice.

However, when running it within a GitHub Workflow using the --output-group and --output-group-{begin,end} arguments, while the first outputs as a single group, the second runs with lots of groups:

::group::test
This is the output from run-cmd.
::endgroup::
::group::test
Passed!
::endgroup::

When I have multiple tasks running in parallel as well through deps, I get multiple groups for multiple tasks all interleaving as well, which makes the output complex to review, for example (as a real-world example):

::group::terraform:workspace
Workspace "production" is active.
Additional arguments provided:
  -var-file=terraform/variables/production.tfvars
::endgroup::
::group::terraform:init
Validated the backend prefix for GCS.
::endgroup::
::group::tflint:init
All plugins are already installed
::endgroup::
::group::tflint:init
Completed
::endgroup::
::group::terraform:fmt
Passed
::endgroup::
::group::tflint
Passed
::endgroup::
::group::terraform:init
Initializing the backend...

Successfully configured the backend "gcs"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...
- Finding goauthentik/authentik versions matching "2026.5.0"...
- Finding integrations/github versions matching "6.13.0"...
- Finding hashicorp/vault versions matching "5.10.1"...
- Using goauthentik/authentik v2026.5.0 from the shared cache directory
- Using integrations/github v6.13.0 from the shared cache directory
- Using hashicorp/vault v5.10.1 from the shared cache directory

Terraform has been successfully initialized!
::endgroup::
::group::terraform:init
Switched to workspace "production".
::endgroup::
::group::terraform:init
Completed
::endgroup::

It would be good if we could group not only by cmd but also by task. I don't know whether something like a group-by-task output option might be good, or a --output-group-by-task/TASK_OUTPUT_BY_TASK option as a way to get Taskfile to collate all the outputs from each cmd within a task.

There seems to be a bit of overlap with #2872 too, if the multiple groups within GitLab are caused by multiple cmds within the task creating multiple identical groups, like in this case. If there is an intention to create an output type for Gitlab, then maybe the --output-group-by-task might be the better option for this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formattingChanges related to output and formatting.

    Fields

    No fields configured for feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions