Skip to content

Commit 240dfaa

Browse files
committed
Limit manual test runs to a few versions
1 parent da10b72 commit 240dfaa

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

.github/workflows/build.yaml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ on:
1717
required: false
1818
default: ""
1919
type: string
20+
max_versions:
21+
description: Maximum number of version tags to build for this manual run
22+
required: false
23+
default: "1"
24+
type: string
2025

2126
env:
2227
IMAGE_NAME: ${{ inputs.image_name || vars.IMAGE_NAME || 'nikolaik/python-nodejs' }}
@@ -31,8 +36,8 @@ jobs:
3136
runs-on: ubuntu-latest
3237
needs: [test]
3338
outputs:
34-
version_matrix: ${{ steps.set-matrix.outputs.matrix }}
35-
arch_matrix: ${{ steps.set-matrix.outputs.arch_matrix }}
39+
version_matrix: ${{ steps.filter-matrix.outputs.version_matrix }}
40+
arch_matrix: ${{ steps.filter-matrix.outputs.arch_matrix }}
3641
steps:
3742
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
3843
with:
@@ -45,6 +50,43 @@ jobs:
4550
run: |
4651
FORCE=$(if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.force }}" == "true" ]]; then echo "--force"; elif git log --pretty=format:"%s" HEAD^..HEAD | grep -q '\[force\]'; then echo "--force"; else echo ""; fi)
4752
uv run dpn $FORCE build-matrix --event ${{ github.event_name }}
53+
- name: Filter build matrix for manual runs
54+
id: filter-matrix
55+
run: |
56+
version_matrix='${{ steps.set-matrix.outputs.matrix }}'
57+
arch_matrix='${{ steps.set-matrix.outputs.arch_matrix }}'
58+
max_versions='${{ github.event_name == 'workflow_dispatch' && inputs.max_versions || '0' }}'
59+
60+
if [[ -z "${version_matrix}" ]]; then
61+
echo "version_matrix=" >> "$GITHUB_OUTPUT"
62+
echo "arch_matrix=" >> "$GITHUB_OUTPUT"
63+
exit 0
64+
fi
65+
66+
filtered_version_matrix="$(jq -cn \
67+
--argjson matrix "${version_matrix}" \
68+
--arg max_versions "${max_versions}" '
69+
($matrix.include
70+
| if ($max_versions | tonumber) > 0 then .[:($max_versions | tonumber)] else . end
71+
) as $include
72+
| if ($include | length) == 0 then empty else {include: $include} end
73+
')"
74+
75+
if [[ -z "${filtered_version_matrix}" ]]; then
76+
echo "version_matrix=" >> "$GITHUB_OUTPUT"
77+
echo "arch_matrix=" >> "$GITHUB_OUTPUT"
78+
exit 0
79+
fi
80+
81+
filtered_arch_matrix="$(jq -cn \
82+
--argjson matrix "${arch_matrix}" \
83+
--argjson selected "${filtered_version_matrix}" '
84+
($selected.include | map(.key)) as $keys
85+
| {include: ($matrix.include | map(select(.key as $key | $keys | index($key))))}
86+
')"
87+
88+
echo "version_matrix=${filtered_version_matrix}" >> "$GITHUB_OUTPUT"
89+
echo "arch_matrix=${filtered_arch_matrix}" >> "$GITHUB_OUTPUT"
4890
4991
5092
build-arch:

0 commit comments

Comments
 (0)