Skip to content

Commit 0d5aa01

Browse files
authored
Merge pull request #135 from trepmal/add/coverage-input
2 parents dd23312 + 9d14852 commit 0d5aa01

1 file changed

Lines changed: 59 additions & 2 deletions

File tree

.github/workflows/reusable-testing.yml

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ on:
1313
type: string
1414
required: false
1515
default: '4.9'
16+
with-coverage:
17+
description: 'Include coverages tests.'
18+
type: boolean
19+
required: false
20+
default: true
1621

1722
# Cancels all previous workflow runs for the same branch that have not yet completed.
1823
concurrency:
@@ -222,7 +227,31 @@ jobs:
222227
id: set-matrix
223228
run: |
224229
if [[ $FILE_EXISTS == 'true' ]]; then
225-
echo "matrix=$(jq -c '.include |= map(with_entries(select(.key == "php", .key == "coverage"))) | .include |= map(select(.php >= "${{ inputs.minimum-php }}")) | .include |= unique_by(.php)' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
230+
echo "matrix=$(jq -c \
231+
--argjson with_coverage_flag "${{ inputs.with-coverage }}" \
232+
--arg minimum_php "${{ inputs.minimum-php }}" \
233+
--arg minimum_wp "${{ inputs.minimum-wp }}" \
234+
'
235+
.include |= (
236+
map(
237+
# First, select only the versions that meet all minimum requirements
238+
select(
239+
(.php >= $minimum_php) and
240+
(.wp == "latest" or .wp >= $minimum_wp)
241+
) |
242+
243+
# Next, update the coverage flag on the remaining items
244+
if $with_coverage_flag == false and .coverage == true then
245+
.coverage = false
246+
else
247+
.
248+
end
249+
) |
250+
251+
# Finally, get the unique entries
252+
unique_by(.php)
253+
)
254+
' <<< "$BASE_MATRIX")" >> $GITHUB_OUTPUT
226255
else
227256
echo "matrix=" >> $GITHUB_OUTPUT
228257
fi
@@ -313,7 +342,35 @@ jobs:
313342
id: set-matrix
314343
run: |
315344
if [[ $FILE_EXISTS == 'true' ]]; then
316-
echo "matrix=$(jq -c '.include |= map(select(.wp == "4.9").wp |= "${{ inputs.minimum-wp }}") | .include |= map(select(.php >= "${{ inputs.minimum-php }}"))' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
345+
echo "matrix=$(jq -c \
346+
--argjson with_coverage_flag "${{ inputs.with-coverage }}" \
347+
--arg minimum_php "${{ inputs.minimum-php }}" \
348+
--arg minimum_wp "${{ inputs.minimum-wp }}" \
349+
'
350+
# First, select only the versions that meet all minimum requirements
351+
.include |= (
352+
map(
353+
select(
354+
.php >= $minimum_php
355+
) |
356+
# Next, update the coverage flag on the remaining items
357+
if $with_coverage_flag == false and .coverage == true then
358+
.coverage = false
359+
else
360+
.
361+
end
362+
)
363+
) |
364+
365+
# Reassign WP4.9 to minimum_wp
366+
.include |= (
367+
map(
368+
select(
369+
.wp == "4.9"
370+
).wp |= $minimum_wp
371+
)
372+
)
373+
' <<< "$BASE_MATRIX" )" >> $GITHUB_OUTPUT
317374
else
318375
echo "matrix=" >> $GITHUB_OUTPUT
319376
fi

0 commit comments

Comments
 (0)