Skip to content

Instantly share code, notes, and snippets.

@GideonPARANOID
Created March 19, 2024 10:00
Show Gist options
  • Save GideonPARANOID/0c34a3163ddd7b03b63a8639071c0eb2 to your computer and use it in GitHub Desktop.
Save GideonPARANOID/0c34a3163ddd7b03b63a8639071c0eb2 to your computer and use it in GitHub Desktop.
Dynamic parallelism for a triggerable GHA workflow
name: Dynamic parallelism
run-name: Dynamic parallelism ${{ github.ref_name }} with ${{ toJson(inputs) }}
on:
workflow_dispatch:
inputs:
parallelism:
description: How many jobs to run in parallel
required: true
type: string
default: '1'
jobs:
init:
name: Init
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
list: ${{ steps.build.outputs.list }}
steps:
- name: ⬇️ Checkout repository
uses: actions/checkout@v4
- name: 🏗️ Build matrix
id: build
run: echo "list=`node -e 'process.stdout.write(JSON.stringify(new Array(${{ inputs.parallelism }}).fill(1).map((value, index) => index + 1)))'`" >> $GITHUB_OUTPUT
dynamic:
name: Dynamic
needs: [init]
timeout-minutes: 15
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
index: ${{ fromJson(needs.init.outputs.list) }}
steps:
- name: ⬇️ Checkout repository
uses: actions/checkout@v4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment