David
David

Reputation: 36354

Github Action use matrices with reuse-able workflow

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.

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?

Upvotes: 7

Views: 10344

Answers (2)

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.

Upvotes: 4

Nick Baum
Nick Baum

Reputation: 156

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:

Upvotes: 13

Related Questions