BrandonMFong
BrandonMFong

Reputation: 101

Github Actions Output Text Color

I have this GitHub action that runs my PowerShell test scripts. The test scripts outputs "[ERROR]" on an error and "[WARNING]" on a warning. Screenshot of colored GitHub Actions log I am wondering if there is any documentation on other keywords that are highlighted. The GitHub actions are running on 'windows-latest' in a pwsh/PowerShell shell.

Upvotes: 8

Views: 12400

Answers (2)

StasGrin
StasGrin

Reputation: 1810

It might be late or not relevant for specific PowerShell or Vstest software but more to help anyone like me searching for an answer on how to make colourized output in GitHub Actions (and eventually ending up here).

The solution is pretty simple - use text wrapped in ANSI colour markup! I found some source examples for typescript and shell scripts. Yes, simple as that - if you can control the output then wrap your text with special markup and that would be it!

P.S.
More info and the most packed guide on ANSI colour output is here: List of ANSI color escape sequences

Upvotes: 2

VonC
VonC

Reputation: 1324997

The colors are not the result of GitHub Action itself, but of the testing framework used.

See for instance microsoft/vstest issue 2370 "Support Colorized Output in GitHub Actions"

xUnit.net does not attempt any colorization here. Our messages are passed to the VSTest API with just text and a level. All colorization in dotnet test is owned by VSTest.

What you see in a GitHub Action is the result of the tool used by that Action.

As mentioned in "A better logs experience with GitHub Actions" in Sept. 2020:

We want to be more mindful about color usage, which means we also need to acknowledge that people build their own scripts, commands, and tools to output useful information.

That’s why we are increasing the color support, including:

  • ANSI colors
  • 8-bit colors
  • 24-bit colors

This enables richer content and better integration when rendering information coming from third-party sources.

https://github.blog/wp-content/uploads/2020/09/color.png?resize=1024%2C699?w=1024

Upvotes: 5

Related Questions