Matrix strategy labels

The matrix strategy is a great way to run different commands with the same starting steps, to DRY up a workflow. As far as I can tell though there’s no way to effectively label each run, unless i’m missing something?

Take this example:

name: PHP lints and tests workflow
on:
  push:

jobs:
  php-lints-and-tests:
    name: PHPStan
    runs-on: ubuntu-latest
    strategy:
      matrix:
        args:
          - 'php -d memory_limit=-1 ./vendor/bin/phpstan analyse --no-progress --level=7 app/src
          - 'php -d display_errors=On -d memory_limit=512M vendor/bin/phpcs -p --encoding=utf-8 --standard=tests/phpcs-ruleset.xml --error-severity=1 app/src'
          - 'php -d display_errors=On -d memory_limit=512M -d date.timezone=UTC vendor/bin/phpunit -c phpunitall.xml.dist'
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Composer installp
        run: composer.phar install --prefer-dist

      - name: PHP
        run: ${{ matrix.args }}

This works fine,  but each job in the matrix is listed as the command. Yaml does support key value pairs but I can’t see how to use a key as the job label. Is this possible?

1 Like

You could do something like:

name: PHP lints and tests workflow
on:
  push:

jobs:
  php-lints-and-tests:
    name: PHPStan ${{ matrix.legs.name }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        legs:
          - {name: 'meaningful name', args: 'php -d memory_limit=-1 ./vendor/bin/phpstan analyse --no-progress --level=7 app/src' }
          - {name: 'meaningful name 2', args: 'php -d display_errors=On -d memory_limit=512M vendor/bin/phpcs -p --encoding=utf-8 --standard=tests/phpcs-ruleset.xml --error-severity=1 app/src' }
          - {name: 'meaningful naem 3', args: 'php -d display_errors=On -d memory_limit=512M -d date.timezone=UTC vendor/bin/phpunit -c phpunitall.xml.dist' }
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Composer installp
        run: composer.phar install --prefer-dist

      - name: PHP
        run: ${{ matrix.legs.args }}

legs is arbitrary could be any key name you like as is name.  But hopefully you get the idea and it helps you.

1 Like

Hi,

thanks for that but in the UI the Job label is still displayed like this:

stan.png

It doesn’t look like the legs.name property is used anywhere.

Please check your workflow yml, is there any typos?

I tested chrispat’s yml, the job name works fine (please ignore the failure in PHP step). 

1 Like

It did work after all. I had 2 versions of the same workflow and I was checking the wrong one. Oh dear!!