Can I specify the version of a github-actions action in a matrix?

I would like to run a build against multiple versions of a given action.

I managed to do what I want with conditions, but I think there’s a better way and it could simply be a syntax issue more than a logic issue here.

I first tried with something like this:

- uses: webbertakken/unity-builder@${{ matrix.unityBuilderVersion }}

But gitlab-actions fails early with the following error:

The workflow is not valid. .github/workflows/main.yml (Line: 66, Col: 15): Unrecognized named-value: ‘matrix’. Located at position 1 within expression: matrix.unityBuilderVersion

I’m trying to identify a very specific bug in a given action and I’d like to see which github-action version introduced it or not. I managed to do it, but it could be much easier on the eyes.

Here’s the workflow file. I’ve added comments on the related sections:

name: Actions 😎

on: [push, pull_request]

env:
  UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}

jobs:
  buildAndTestForSomePlatforms:
    name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }} with unity-builder version ${{ matrix.unityBuilderVersion }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        projectPath:
          - .
        unityVersion:
          - 2020.1.7f1
        targetPlatform:
          - StandaloneOSX
          - StandaloneWindows64
          - StandaloneLinux64
          - WebGL
        
        # This is the actions versions I want to try. I would expect to only use this
        
        unityBuilderVersion:
          - master
          - v0.1
          - v0.10
          - v0.11
          - v0.12
          - v0.13
          - v0.14
          - v0.15
          - v0.2
          - v0.3
          - v0.4
          - v0.5
          - v0.6
          - v0.7
          - v0.8
          - v0.9
          - v1.0
          - v1.1
          - v1.2
          - v1.3
          - v1.4
    steps:
      - uses: actions/checkout@v2
        with:
          lfs: true
      - uses: actions/cache@v1.1.0
        with:
          path: ${{ matrix.projectPath }}/Library
          key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
          restore-keys: |
            Library-${{ matrix.projectPath }}-
            Library-
 
      # Here starts the conditions with repeated unityBuilderVersion matrix.
      # I wish I could only have used something like this:
      #   - uses: webbertakken/unity-builder@${{ matrix.unityBuilderVersion }}
      # but github actions complained about this 

      - if: matrix.unityBuilderVersion == 'master'
        uses: webbertakken/unity-builder@master
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.1'
        uses: webbertakken/unity-builder@v0.1
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.10'
        uses: webbertakken/unity-builder@v0.10
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.11'
        uses: webbertakken/unity-builder@v0.11
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.12'
        uses: webbertakken/unity-builder@v0.12
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.13'
        uses: webbertakken/unity-builder@v0.13
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.14'
        uses: webbertakken/unity-builder@v0.14
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.15'
        uses: webbertakken/unity-builder@v0.15
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.2'
        uses: webbertakken/unity-builder@v0.2
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.3'
        uses: webbertakken/unity-builder@v0.3
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.4'
        uses: webbertakken/unity-builder@v0.4
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.5'
        uses: webbertakken/unity-builder@v0.5
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.6'
        uses: webbertakken/unity-builder@v0.6
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.7'
        uses: webbertakken/unity-builder@v0.7
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.8'
        uses: webbertakken/unity-builder@v0.8
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v0.9'
        uses: webbertakken/unity-builder@v0.9
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v1.0'
        uses: webbertakken/unity-builder@v1.0
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v1.1'
        uses: webbertakken/unity-builder@v1.1
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v1.2'
        uses: webbertakken/unity-builder@v1.2
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v1.3'
        uses: webbertakken/unity-builder@v1.3
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - if: matrix.unityBuilderVersion == 'v1.4'
        uses: webbertakken/unity-builder@v1.4
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
          customParameters: '-nographics'
      - uses: actions/upload-artifact@v2
        with:
          name: ${{ matrix.targetPlatform }}-unity-builder-${{ matrix.unityBuilderVersion }}
          path: build/${{ matrix.targetPlatform }}

The env context is only available in with and name keys, or in a step’s if. Similarly, the matrix context is apparently not usable in the key uses. This limitation doesn’t seem to be documented:

Here’s an untested attempt to bypass this restriction:

steps:
  - name: Get unity-builder action version from matrix
    id: unity-builder-action
    run: echo "::set-output name=version::${{ matrix.unityBuilderVersion }}"
  - uses: webbertakken/unity-builder@${{ steps.unity-builder-action.outputs.version }}
    ...

@gableroux, @Simran-B,

Using output to pass the version ref of action also does not work. It returns the syntax error (see here).

According to my tests, it seems that the value of ‘uses’ key does not support receiving any type of variables, such as environment variables, output parameters and matrix parameters. It needs directly using the explicit action name (or path) and version ref to set the value of ‘uses’ key.

1 Like

What a pity. But I guess it makes sense if you consider that there’s a security option to only permit certain actions. With a dynamic value computed at run time, it wouldn’t be possible anymore to tell ahead of time whether all involved actions are allowed to be used. Could use clarification in the docs.

1 Like