Group log lines in GitHub Actions
Fold log output in GitHub Actions by printing ::group::Title and ::endgroup::. A wrapper function keeps the pair together and passes the command's status on.
A build step prints three hundred lines, and the one you need is hidden among them.
group() {
local title=$1; shift
echo "::group::$title"
"$@"; local rc=$?
echo "::endgroup::"
return $rc
}
group "Install" echo "installing 42 packages"
group "Test" sh -c 'echo "running tests"; exit 3'
echo "test group status: $?"::group::Install
installing 42 packages
::endgroup::
::group::Test
running tests
::endgroup::
test group status: 3The runner watches the output for lines that begin with ::. Everything between ::group::title and ::endgroup:: is folded under the title in the log, as the workflow commands documentation describes. Outside the runner, as above, the lines are printed literally. The wrapper closes the group even when the command fails and returns its exit status, so the step still fails.
GitHub does not support nested groups, so wrap one level only. The wrapper runs the command in the current shell, so a function works as well as a program. On a developer machine the marker lines are noise, so print them only when the GITHUB_ACTIONS variable is set.