Skip to content

Instantly share code, notes, and snippets.

@ohaval
Created December 20, 2022 07:04
Show Gist options
  • Save ohaval/84933dfb570d201fba4d907752e169c3 to your computer and use it in GitHub Desktop.
Save ohaval/84933dfb570d201fba4d907752e169c3 to your computer and use it in GitHub Desktop.
Example showing how to set a dynamic matrix sequence based on input
name: Dynamic Matrix
on:
push:
workflow_dispatch:
inputs:
someInput:
description: 'Some input'
required: true
type: choice
options: [ one, two, three ]
jobs:
set-matrix:
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set matrix in output
id: set-matrix
run: |
if [ "${{ inputs.someInput }}" ]; then
echo "someInput is set"
echo 'matrix=[ "${{ inputs.someInput }}" ]' >> $GITHUB_OUTPUT
else
echo "someInput is empty"
echo 'matrix=[ "one", "two", "three", "four", "five" ]' >> $GITHUB_OUTPUT
fi
simple-print-job:
runs-on: ubuntu-22.04
needs: [ set-matrix ]
strategy:
matrix:
value: ${{ fromJson(needs.set-matrix.outputs.matrix) }}
steps:
- name: Print matrix value
run: echo "${{ matrix.value }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment