Context
I've got a workflow with 2 jobs.
- The first job generates a list of tasks (with
name
andtype
) as output - The second job uses 3 different actions, where each action is associated to a task
type
to be executed.
Minimal example to reproduce
jobs:
orchestration:
runs-on: ubuntu-latest
outputs:
tasks: ${{ steps.tasks.outputs.tasks }}
steps:
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Build Tasks Array
id: tasks
run: |
import json
import os
tasks = []
for i in range(1, 20):
task_type = "TYPE1" if i % 3 == 1 else ("TYPE2" if i % 3 == 2 else "TYPE3")
tasks.append({"taskId": f"task{i}", "type": task_type})
print("Tasks list:", tasks)
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"tasks={json.dumps(tasks)}\n")
shell: python
process:
runs-on: ubuntu-latest
needs: [orchestration]
strategy:
matrix:
tasks: ${{fromJson(needs.orchestration.outputs.tasks)}}
steps:
- if: contains( matrix.tasks.type , 'TYPE1')
uses: owner/action-type1@v1
with:
TASK_ID: ${{ matrix.tasks.taskId }}
- if: contains( matrix.tasks.type , 'TYPE2')
uses: owner/action-type2@v1
with:
TASK_ID: ${{ matrix.tasks.taskId }}
- if: contains( matrix.tasks.type , 'TYPE3')
uses: owner/action-type3@v1
with:
TASK_ID: ${{ matrix.tasks.taskId }}
Issue
As shared in the example above, I use matrix strategy to run the second job, according to the output from the first job.
However, the order in which the matrix jobs are executed import here, and I would like them to run following the same order as the list generated on the first job: task1 --> task2 --> task3 ...
How can I guarantee matrix strategy jobs are executed in a specific sequence on GitHub Actions?
What I tried
According to the official documentation:
The order of the variables in the matrix determines the order in which the jobs are created.
However, when running in parallel, the strategy matrix order is not respected (task 10 can run before task 1).
max-parallel
under the pipeline failed. I put it understrategy
as per official docs and it works: docs.github.com/en/actions/using-jobs/… – Astrograph