Home

Awesome

phpunit-matcher-action

This action uses the built in PHPUnit --teamcity formatter to add annotations to your Github Actions builds.

PHPUnit Action Matcher Logs Example

PHPUnit Action Matcher Context Example

Usage

To configure these matchers, add the following step to your workflow YAML file before running PHPUnit with the --teamcity flag.

- name: Configure matchers
  uses: mheap/phpunit-matcher-action@v1

Here's a complete workflow example (located at .github/workflows/phpunit.yml) that runs your tests and adds annotations for failures

name: PHPUnit
on: [pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Composer dependencies
      run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
    - name: Configure matchers
      uses: mheap/phpunit-matcher-action@v1
    - name: Run Tests
      run: ./vendor/bin/phpunit --teamcity test

If you run your tests in a container and the Teamcity output will have a different base path, you can specify it using the base_path input:

- name: Configure matchers
  uses: mheap/phpunit-matcher-action@v1
  with:
    base_path: /path/to/other/folder

How this works

Problem matchers work by defining a regular expression to extract information such as the file, line number and severity from any output logs. Each matcher has to be registered with Github Actions by adding ::add-matcher::/path/to/matcher.json to the output.

This action generates regular expressions based on the Github workspace, writes out matcher files and then registers them with the Action runner.

It uses the Teamcity output as it contains all of the required information (file path, failure message and line number).