Skip to content

Integration tests failing in CI because of missing ANSI color codes #298

@jorisroovers

Description

@jorisroovers

Our CI builds broke on the integration tests for the gitlint commit message hook. This happened without any change in the code as far as I can tell. The build actually broke a while back, I just hadn’t noticed since I’m in a low activity period wrt gitlint maintenance.

My best guess is that this is because of a github CI environment change, because all the tests run fine locally and they were working fine a while back.

Specifically, several tests are failing on missing ANSI color characters in the gitlint hook output. Our integration tests check for these ANSI color characters, but in the CI run the ANSI color codes are no longer there. It seems all the failing tests have the same root cause (missing ANSI color codes).

Example failing tests: test_commit_hook_no_violations. Here’s where we check for the ANSI codes in the test, those are missing from the test output in CI.

"gitlint: \x1b[32mOK\x1b[0m (no violations in commit message)\n",

gitlint uses click to do the coloring, which uses colorama under-the-hood. See here:

if exit_code == GITLINT_SUCCESS:
click.echo("gitlint: " + click.style("OK", fg='green') + " (no violations in commit message)")
continue
click.echo("-----------------------------------------------")
click.echo("gitlint: " + click.style("Your commit message contains violations.", fg='red'))

This is the only place where gitlint uses terminal colors.

The only reason I can think that those colors being disabled is because click/colorama is not detecting a session terminal (= no tty connected to stdin).

This is probably caused in how we invoke gitlint from the integration tests, using the sh library:

gitlint/qa/shell.py

Lines 8 to 11 in 63500a5

if USE_SH_LIB:
from sh import git, echo, gitlint # pylint: disable=unused-import,no-name-in-module,import-error
gitlint = gitlint.bake(_unify_ttys=True, _tty_in=True) # pylint: disable=invalid-name

Side-note: I’ve done most of the legwork to remove the need for sh in the integration tests (a dependency I ultimately want to remove), but the hook tests are the last ones that depend on it, because of some stdin/stdout convenience functions provided by sh that I haven’t gotten around to eliminating.

What I don’t understand though, is that this has now become a problem, while it was working fine before.

I did find actions/runner#241, which might be related, but again, that doesn’t explain why tests worked for a long time.

I’ve tried a few things in #297, but have not been able to solve this 😒 stdin/tty problems 😱

Metadata

Metadata

Assignees

No one assigned

    Labels

    developmentIssues that are not user-facing but related to gitlint developmentgithub_actionsPull requests that update GitHub Actions code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions