-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy path04-advanced-features--07-dynamic-matrix.yaml
More file actions
53 lines (48 loc) · 1.45 KB
/
Copy path04-advanced-features--07-dynamic-matrix.yaml
File metadata and controls
53 lines (48 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Dynamic Matrix
on:
workflow_dispatch:
inputs:
length:
description: "Number of foo/bar pairs to generate"
required: true
default: "2"
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
include: ${{ steps.gen.outputs.include }}
steps:
- name: Generate paired list (foo = random, bar = random)
id: gen
env:
LENGTH: ${{ github.event.inputs.length }}
shell: bash
run: |
set -euo pipefail
n="${LENGTH:-2}"
# Generally I would extract this type of logic to a separate
# Taskfile task to make it easier to iterate/validate
include_json=$(
{
for ((i=1; i<=n; i++)); do
foo_val=$((RANDOM % 100))
bar_val=$((RANDOM % 100))
jq -n -c \
--argjson foo "$foo_val" \
--argjson bar "$bar_val" \
'{foo:$foo, bar:$bar}'
done
} | jq -s -c .
)
# Output the array for `matrix.include`
echo "include=$include_json" >> "$GITHUB_OUTPUT"
execute:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.generate-matrix.outputs.include) }}
steps:
- name: Use matrix values (paired randoms)
run: echo "Matrix - foo=${{ matrix.foo }}, bar=${{ matrix.bar }}"