fgalan
fgalan

Reputation: 12312

GitHub Actions job name based on matrix index instead of matrix value

I'm using GitHub Actions to run a workflow using a matrix strategy, as follows (simplified):

name: Functional Tests
...
jobs:
  functional:
    ...
    strategy:
      matrix:
        range:
          - -e FT_FROM_IX=0 -e FT_TO_IX=300
          - -e FT_FROM_IX=301 -e FT_TO_IX=600
          - -e FT_FROM_IX=601 -e FT_TO_IX=900
          - -e FT_FROM_IX=901 -e FT_TO_IX=1200
          - -e FT_FROM_IX=1201

    steps:
      - uses: actions/checkout@v2

      - name: Run functional test
        run: |
          docker run  --network host -t --rm ${{ matrix.range }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts functional

It works fine, but I get a ugly description at GitHub because the matrix.range value appears as part of the job name:

enter image description here

I would like to have my jobs numbered (e.g. functional-1, functional-2, etc.). Is that possible using some expression to get the index of the matrix element (something like ${{ matrix.range.index }}) or any other way?

Upvotes: 3

Views: 2311

Answers (1)

AranS
AranS

Reputation: 1891

I had a similar use case, found a simple solution:

  1. Change matrix range to a list of objects, containing order and range.
  2. Concatenate order with the job's name key.
  3. Use range key as before.

Hopefully, Github Actions will add an index to the matrix jobs, simplifying the way we distinguish between them.

name: Functional Tests
...
jobs:
  functional:
    name: functional - ${{ matrix.payload.order }}
    ...
    strategy:
      matrix:
        payload:
          - { order: 1, range: '-e FT_FROM_IX=0 -e FT_TO_IX=300' }
          - { order: 2, range: '-e FT_FROM_IX=301 -e FT_TO_IX=600' }
          - { order: 3, range: '-e FT_FROM_IX=601 -e FT_TO_IX=900' }
          ...

    steps:
      - uses: actions/checkout@v2

      - name: Run functional test
        run: |
          docker run  --network host -t --rm ${{ matrix.payload.range }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts functional

Upvotes: 5

Related Questions