Nested variable substitution

I am using a matrix to run my unit tests in a variety of environments. I have a dependencies file per environment. I want to use the hash of this in the cache restore key so I need to define the file to look for using the ${{ matrix.stack }} variable (which is just a string) like so:

key: ${{ runner.os }}-conda-stage-${{ matrix.stack }}-${{ hashFiles('env/${{ matrix.stack }}_environment.yml') }}

The nested expansion of ${{ matrix.stack }} within the hashFiles call doesn’t happen so the key defaults to:

key: ${{ runner.os }}-conda-stage-${{ matrix.stack }}-

Therefore the cached environment is always restored even when the environment file is changed.

Nested expressions are not supported I think?

You can do the following however:

key: ${{ format('{0}-conda-stage-{1}-{2}', runner.os, matrix.stack, hashFiles(format('env/{0}_environment.yml', matrix.stack))) }}


Fantastic, that’s worked perfectly. I’d missed the format function! Thanks very much.