Skip to content

Problem matchers do not work on colored output #2341

Open

Description

@ian-h-chamberlain

Describe the bug
Color codes appear to affect regex matching of problem matchers

To Reproduce
Steps to reproduce the behavior:

  1. Create a problem matcher that matches plaintext, e.g. "regexp": "Hello world"
  2. Run an action that produces color output, for example: bash -c "printf '\e[31mHello\e[0m world!\n'"
  3. Observe that no match appears in the actions output or inline on a PR "files" tab.

As a more real-life example, I have created a minimal reproduction with colored output and missing the expected annotations:
https://github.com/ian-h-chamberlain/actions-color-repro/actions/runs/3777593125

However, when I updated the workflow to disable color output, annotations appear as expected:
ian-h-chamberlain/actions-color-repro#1
https://github.com/ian-h-chamberlain/actions-color-repro/actions/runs/3777594485

Expected behavior
Most (all?) are written against plain (un-colored) text, but it would be nice to have colorized output in the action logs while still supporting colored output.

This document indicates that color codes should be stripped before applying matchers.

Runner Version and Platform

Version of your runner? Current runner version: '2.299.1'

OS of the machine running the runner? ubuntu-latest

What's not working?

See the "expected behavior" above.

Other notes

I believe this logic is incomplete for stripping ANSI color codes:

private static readonly Regex _colorCodeRegex = new(@"\x0033\[[0-9;]*m?", RegexOptions.Compiled | RegexOptions.CultureInvariant);

var stripped = line.Contains(_colorCodePrefix) ? _colorCodeRegex.Replace(line, string.Empty) : line;

Here is a sample logs from a more realistic run which I believe show a wider range of ANSI control codes that might be encountered by tools that use color: 6_Run clippy linting.txt

Activity

  1. added a commit that references this issue on Dec 25, 2022
  2. added
    keepLabel can be added as soon as we are sure the work on the issue is necessary
    on Dec 26, 2022
  3. ian-h-chamberlain commented on Mar 4, 2023

    @ian-h-chamberlain
    Author

    @ruvceskistefan since you triaged this to add the keep label, maybe you know who might be able to review the PR to fix this (#2430) ? It's a fairly small change and this would be a nice quality of life improvement for the runner. Thanks!

  4. added a commit that references this issue on Apr 3, 2023
  5. jsoref commented on Jun 17, 2025

    @jsoref
    Contributor

    I suppose I should feel honored that my fork was linked for this ticket.

    Note that instead of using https://github.com/jsoref/actions-runner/blob/f9c2bf1dd72541bf039c3c5fa4129814181ca261/docs/adrs/0276-problem-matchers.md?plain=1#L113, you can use:

    Note, strip color codes when evaluating regular expressions.

    We're pretty sure that we're also tripping on this issue. (As it happens, I do have tooling that is vaguely aware of ansi color codes -- specifically for the purpose of ignoring them -- but I can't claim that my tooling is any better than anyone else's.)

  6. jenseng commented on Jun 17, 2025

    @jenseng

    Until this is fixed, I've just resorted to rolling my own problem matchers that handle ANSI escape codes, though this can be a bit tedious to get right 🥲.

    For example, here's a modified eslint-stylish.json I use (instead of the default one provided by actions/setup-node):

    {
      "problemMatcher": [
        {
          "owner": "eslint-stylish",
          "pattern": [
            {
              "regexp": "^(?:\\x1b\\[\\d+m)*([^\\s].*?)(?:\\x1b\\[\\d+m)*$",
              "file": 1
            },
            {
              "regexp": "^(?:\\x1b\\[\\d+m)*\\s+(?:\\x1b\\[\\d+m)*(\\d+):(\\d+)(?:\\x1b\\[\\d+m)*\\s+(?:\\x1b\\[\\d+m)*(error|warning|info)(?:\\x1b\\[\\d+m)*\\s+(.*)\\s\\s+(?:\\x1b\\[\\d+m)*(.*?)(?:\\x1b\\[\\d+m)*$",
              "line": 1,
              "column": 2,
              "severity": 3,
              "message": 4,
              "code": 5,
              "loop": true
            }
          ]
        }
      ]
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingkeepLabel can be added as soon as we are sure the work on the issue is necessary

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions