8

I've been rooting through the Github Action documentation around re-useable workflows and am attempting to piece together a chain of matrices.

My pseudo workflow looks something like the following steps.

  • Job 1: Figure out files changed under a path & output them as json
  • Job 2: Iterate the file list as a matrix and invoke another workflow.
  • Job 3 (in other workflow): Simply use another matrix definition in conjunction with the single input value to perform a set of steps.

It would seem a relatively simple objective. Yet it looks like workflow re-useable calls do not support strategy. Correct me if I'm wrong?

2 Answers 2

16

GitHub Actions matrix supports now reusable workflows (since 22.08.22):

jobs:
  ReuseableMatrixJobForDeployment:
    strategy:
      matrix:
        target: [dev, stage, prod]
    uses: octocat/octo-repo/.github/workflows/deployment.yml@main
    with:
      target: ${{ matrix.target }}

References:

Sign up to request clarification or add additional context in comments.

Comments

5

edit: The situation has changed since posting this. There is now an accepted answer.

It appears matrix (strategy) can't be used with reusable actions, at least right now. See GH Actions docs.

Given that reusable actions went GA literally yesterday, I expect this might eventually change. Notice the announcement shows an example with a matrix... And the replacement conveniently leaves out what's being called.

As far as I understand it, the limitation can be rephrased as "you can't write a C style for loop" - you can't have the caller workflow use strategy on a job that is a reusable action call. However you can reverse the relationship: Move strategy into the reused workflow (callee). Then, you can also pass in the matrix in inputs as a JSON encoded in a string. See the discussion about this workaround.

That's certainly not good enough for me, but judge yourself.

1 Comment

The link to the discussion is now dead. GitHub docs describe this workaround at docs.github.com/en/enterprise-cloud@latest/actions/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.