Length function in Context Syntax

Hey all. I’m currently working on creating a Github Action that runs several runners via a matrix. Each runner should run 1/N tests of our test suite. In order to achieve this, I’d like to be able to compute the length of the matrix array. I don’t see such a function in the docs

Currently, I have to hard code this value.

Desired usage:

    echo "Running 1 / ${{ length(matrix) }} tests:

I realize this could probably be achieved by converting matrix to JSON and then processing that json, but that seems messy.

Thanks!

Edit:
After playing around with a build, this is worse than I thought; in a runner the matrix object isn’t the entire matrix, but just the matrix entry assigned to this runner; we don’t have the entire array to take the length of.

@szunami,

You can get the total number of jobs in a matrix from the strategy context.

  • strategy.job-total: the total number of jobs in the matrix.
  • strategy.job-index: the index (starts from 0) of current running job in the matrix.

For your case, you can try like as below:

- name: run tests
  run: echo "Running $((${{ strategy.job-index }} + 1)) / ${{ strategy.job-total }} tests:"

The following is a simple example as reference: