octocat.dev.

A Developer's blog.About

Creating groups and formatting in GitHub Actions logs

Shubhan Chemburkar
Shubhan Chemburkar
Cover Image for Creating groups and formatting in GitHub Actions logs

GitHub Actions can have multiple steps, some more than others. If we group the output, it makes it cleaner to view and check. This post explains how to do just that very easily.

Group Syntax

To use groups, need to use a special output syntax. For directly using in your workflows, composite actions etc., use the below syntax:

🔗For Workflows and Actions

echo "::group::Name of Group"   
echo "::endgroup::"

If the above syntax does not work for your runner, check if below syntax works as an alternate:

echo ##[group]Name of Group
echo ##[endgroup]

This alternate syntax may be required mostly in composite powershell actions

🔗Using Groups from Javascript Actions

import * as core from "@actions/core"

core.startGroup("My Group");
core.info("Some log statement");
core.endGroup();

Reference: GitHub Actions Docs

Colors and Formatting in output

Color styling output helps to provide better context in logs

This can be achieved easily by using ansi-styles in Javascript actions

Just print using

import styles from 'ansi-styles';

// log(string message)

return `${styles.blue.open}Hello world!${styles.blue.close}`;

Discussion

For any queries or feedback, please start a new discussion on GitHub Discussions or at Twitter @shubhan3009.

Cover image Credits

Photo by Shahadat Rahman on Unsplash

The source code for this blog is available on GitHub.