Dynamic Matrix Generation in GitHub Actions
===========================================

An example job with a dynamically-generated matrix conditional on if the workflow is triggered by schedule or a push to a ref starting with actions/.

push-pr-nightly.yml

on:
  schedule:
    - cron: '0 8 * * *'
  push:
    branches: [master]
  pull_request:
    branches: [master]
  workflow_dispatch:

jobs:
  gen-matrix:
    runs-on: [ubuntu-latest]
    outputs:
      matrix: ${{ steps.gen.outputs.matrix }}
    steps:
    - id: gen
      run:
        if ${{ github.event_name == 'schedule' || startsWith(github.head_ref, 'actions/') }}; then
            echo 'matrix=[
              {"os":"rhel", "VMAJ":"8", "VMIN":"5"},
              {"os":"sles", "VMAJ":"15", "VMIN":"3"},
              {"os":"ubuntu", "VMAJ":"18", "VMIN":"04"},
              {"os":"ubuntu", "VMAJ":"20", "VMIN":"04"},
              {"os":"ubuntu", "VMAJ":"22", "VMIN":"04"}
            ]' >> ${GITHUB_OUTPUT};
        else
            echo 'matrix=[
              {"os":"rhel", "VMAJ":"8", "VMIN":"5"}
            ]' >> ${GITHUB_OUTPUT};
        fi

  run:
    needs: gen-matrix
    runs-on: [ubuntu-latest]
    strategy:
      matrix:
        include: ${{ fromJSON(needs.gen-matrix.outputs.matrix) }}
    steps:
    - run: echo ${{ matrix.os }} ${{ matrix.VMAJ }}.${{ matrix.VMIN }}
· actions