Created
December 20, 2022 07:04
-
-
Save ohaval/84933dfb570d201fba4d907752e169c3 to your computer and use it in GitHub Desktop.
Example showing how to set a dynamic matrix sequence based on input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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