Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 5

Matrix strategy labels

Solved! Go to Solution.

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?

4 Replies
Highlighted
Solution
GitHub Staff
Message 2 of 5

Re: Matrix strategy labels

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.

 

Highlighted
Copilot Lvl 3
Message 3 of 5

Re: Matrix strategy labels

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.

Highlighted
GitHub Partner
Message 4 of 5

Re: Matrix strategy labels

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). 

matrix yml.png

 

Spoiler
matrix name.png
Highlighted
Copilot Lvl 3
Message 5 of 5

Re: Matrix strategy labels

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