How to Add Colors to Continuous Integration Output
Today I have a tip for your CI. I learned this tip from Jan Mikes.
A small tip that made my everyday work with CI more colorful.
- Do you use Travis, Github Actions, or Gitlab CI?
- Do you use composer, PHPUnit, ECS, Rector, or PHPStan?
- Do you have colors enabled in
phpunit.xml
?
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<!-- ... -->
</phpunit>
- Do you use composer scripts to prevent typos and re-use CI tool setup?
...but still missing the colored output?
Sad Black/White Continuous Integration World
For many years I've run Travis, Gitlab, and now Github Actions. I never knew the output could be readable for humans, so I always looked at the final checkmark for all the scripts.
It was ✅ or ❌.
When the CI runs the scripts:
scripts:
- composer install
- composer fix-cs
This was usually the output:


One day, Something Changed
The colors came to my life. I could read again, and the output was the same as in local environment!


What happened? Did they fix something on Github Actions? Or composer (and all the other tools were) was fixed?
No, just one new word appeared:
scripts:
- - composer install
+ - composer install --ansi
{
"scripts": {
- "fix-cs": "vendor/bin/ecs check --fix"
+ "fix-cs": "vendor/bin/ecs check --fix --ansi"
}
}
Since then, I enjoy failed CI jobs more and find faster what went wrong.
Happy coding!