Skip to content

Commit 860909e

Browse files
committed
.github: PackageMatrix: Bugfix empty packages list
The list of packages in the generated matrix can sometimes be empty, which is invalid and will result in the actual matrix of job runners failing to generate (because all values must be a non-empty array). This commit performs a final validation of job matrix, removing all default configs if the package list is empty, and removing the includes list if it is empty.
1 parent 191d9cc commit 860909e

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

.github/workflows/PackageMatrix.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
runs-on: ubuntu-latest
7777

7878
outputs:
79-
matrix: ${{ steps.filter-matrix.outputs.matrix || steps.set-packages.outputs.matrix }}
79+
matrix: ${{ steps.clean-matrix.outputs.matrix }}
8080

8181
steps:
8282
- name: Checkout repository
@@ -171,3 +171,51 @@ jobs:
171171
echo "::endgroup::"
172172
echo ""
173173
echo "matrix=$OUTPUT" >> "$GITHUB_OUTPUT"
174+
175+
- name: Clean matrix if no packages found
176+
if: always()
177+
id: clean-matrix
178+
shell: bash
179+
env:
180+
MATRIX: ${{ steps.filter-matrix.outputs.matrix || steps.set-packages.outputs.matrix }}
181+
DEFAULT_CONFIG: ${{ inputs.default-config }}
182+
run: |
183+
echo "Checking if matrix has any packages..."
184+
185+
# Check if packages array is empty
186+
PACKAGES_COUNT=$(echo "$MATRIX" | jq '.packages | length')
187+
188+
echo "Packages count: $PACKAGES_COUNT"
189+
190+
if [ "$PACKAGES_COUNT" -eq 0 ]; then
191+
echo "No packages found - removing default-config dimensions and packages, keeping include only"
192+
# Keep only include, remove packages and all default-config dimensions
193+
OUTPUT=$(echo "$MATRIX" | jq '{include: .include}')
194+
else
195+
echo "Packages found - keeping matrix as-is"
196+
OUTPUT="$MATRIX"
197+
fi
198+
199+
# Remove include if it's an empty array (regardless of packages count)
200+
INCLUDE_COUNT=$(echo "$OUTPUT" | jq '.include | length')
201+
echo "Include count: $INCLUDE_COUNT"
202+
203+
if [ "$INCLUDE_COUNT" -eq 0 ]; then
204+
echo "Include array is empty - removing it"
205+
OUTPUT=$(echo "$OUTPUT" | jq 'del(.include)')
206+
fi
207+
208+
# Check if we have an empty JSON object and return empty string instead
209+
OBJECT_KEYS=$(echo "$OUTPUT" | jq 'keys | length')
210+
if [ "$OBJECT_KEYS" -eq 0 ]; then
211+
echo "Matrix is completely empty - returning empty string"
212+
OUTPUT=''
213+
fi
214+
215+
echo "::group::Final matrix JSON"
216+
echo "$OUTPUT" | jq .
217+
echo "::endgroup::"
218+
echo ""
219+
# Ensure compact JSON output for GitHub Actions
220+
COMPACT_OUTPUT=$(echo "$OUTPUT" | jq -c .)
221+
echo "matrix=$COMPACT_OUTPUT" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)