16

I have a GitHub Actions workflow dealing with new releases. Some last steps build the application for different platforms. Instead of creating multiple steps where each one builds for a different platform or creating a step running multiple commands I'm looking for a way to loop a step for each item in an array.

I know there is a matrix for jobs so this is my pseudo implementation to show what I'm looking for:

jobs:
  do_it:
    runs-on: ubuntu-latest

    steps:
      - name: For each entry in the array...
        strategy:
          matrix:
            target: [ this, that, something ]
        run: echo ${{ matrix.target }}

Is it possible to create something similar to a matrix so it will loop the step multiple times?

As a side note, I know there is a similar question but I don't want to split the job into multiple jobs because then I have to deal with all the build artifacts.

2 Answers 2

0

Posting this "late" answer hoping that someone finds it useful:

There is no direct or "native" way to loop through a GitHub action step, but you can achieve that with 2 different approaches:

  • Designing your workflow to have a job with a matrix, then create another job that depends on that matrix, you can share build artifacts between workflows with job outputs and upload/download actions
  • Create a custom (composite) action that takes inputs as an array (idea/workaround), then loop through your inputs with bash or JavaScript (if you use JS actions).
Sign up to request clarification or add additional context in comments.

Comments

-2

If your action uses the workflow_dispatch event, you can trigger the action again by running a step that runs that same workflow:

- run: gh workflow run run-tests.yml
  env:
    GH_TOKEN: ${{ github.token }}

Comments

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.