Reference other contexts inside matrix?

Hey GitHub Actions experts,

After reading the docs around matrix in workflow syntax , I was wondering if it’s possible to reference another context inside matrix.

It can be pretty useful if I need to use some information about the commit when constructing the matrix section. Apart from that, sometimes, it’s also possible that one field in the matrix section relies on another field in the same matrix def.

my_job:
    strategy:
      matrix:
        field1: [val1, val2, val3]
        field2: [join({{ matrix.field1 }}, 'suffix1'), join({{ matrix.field1 }}, 'suffix2')]
      max-parallel: 2
    steps:
      ...

I’ve tried myself with a simple workflow as below, and it doesn’t work. Has anyone had the same idea before? 

name: reference-context-inside-matrix

on: [push]

jobs:
  build:
    strategy:
      matrix:
        fruit: ['apple', 'banana']
        workflow: ${{ github.workflow }}

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Run a one-line script
      run: echo Hello, world, ${{ matrix.fruit }}
    - name: Run a one-line script
      run: echo Hello, world, ${{ matrix.workflow }}

Github Actions doesn’t support referring other contexts expressions inside matrix.

In your sample workflow, what’s your purpose of adding workflow to matrix? It just has one value. You could use ${{ github.workflow }} directly in your jobs.

>>It can be pretty useful if I need to use some information about the commit when constructing the matrix section.

Do you have any other examples ? I could try to find a work around for your scenario.

An example I have is publishing multiple docker images.

I created a build workflow based around the idea of defining the name:tag combinations of the images in a strategy matrix e.g.

strategy:
            matrix:
                docker_image_name:
                    - 'testname'
                    - 'newtestname'
                docker_image_tag:
                    - 'latest'
                    - "${{ github.sha }}"
                    - "${{ github.ref }}"

This approach turns out to not work since “{{ github.sha }}" and "{{ github.ref }}” cause the following error:

Using expression in matrix is not supported now.  You could ask for this feature in the Feedback form for GitHub Actions.