Skip to content

Commit

Permalink
Now filtering nf-test dry-run by --tag, picking up Executed instead o…
Browse files Browse the repository at this point in the history
…f related and capped shards with max_shards
  • Loading branch information
GallVp committed Dec 3, 2024
1 parent d6a1aab commit 46637d4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
18 changes: 13 additions & 5 deletions .github/actions/nf-test-shard/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
name: "Get number of shards"
description: "Get the number of nf-test shards for the current CI job"
inputs:
tags:
description: "Tags to pass as argument for nf-test --tag parameter"
required: true
max_shards:
description: "Maximum number of shards allowed"
required: true
outputs:
shard:
description: "Array of shard numbers"
Expand All @@ -22,22 +29,23 @@ runs:
shell: bash
run: |
# Run nf-test to get the number of related tests
nftest_output=$(nf-test test --dry-run --changed-since HEAD^ --filter pipeline)
nftest_output=$(nf-test test --dry-run --changed-since HEAD^ --filter pipeline --tag ${{ inputs.tags }})
echo "nf-test dry-run output: $nftest_output"
# Default values for shard and total_shards
shard="[]"
total_shards=0
# Check if there are related tests
if echo "$nftest_output" | grep -q 'Found 0 related test(s)'; then
if echo "$nftest_output" | grep -q 'Nothing to do'; then
echo "No related tests found."
else
# Extract the number of related tests
number_of_shards=$(echo "$nftest_output" | grep -o 'Found [0-9]* related test' | tail -1 | awk '{print $2}')
number_of_shards=$(echo "$nftest_output" | sed -n 's|.*Executed \([0-9]*\) tests.*|\1|p')
if [[ -n "$number_of_shards" && "$number_of_shards" -gt 0 ]]; then
shard=$(seq 1 "$number_of_shards" | jq -R . | jq -c -s .)
total_shards="$number_of_shards"
shards_to_run=$(( $number_of_shards < ${{ inputs.max_shards }} ? $number_of_shards : ${{ inputs.max_shards }} ))
shard=$(seq 1 "$shards_to_run" | jq -R . | jq -c -s .)
total_shards="$shards_to_run"
else
echo "Unexpected output format. Falling back to default values."
fi
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/nf-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inputs:
description: "Filter test cases by specified types (e.g., module, pipeline, workflow or function)"
required: true
tags:
description: "Test tags to be run"
description: "Tags to pass as argument for nf-test --tag parameter"
required: true

runs:
Expand Down Expand Up @@ -75,7 +75,7 @@ runs:
--filter ${{ inputs.filters }} \
--tap=test.tap \
--verbose \
${{ inputs.tags }}
--tag ${{ inputs.tags }}
# TODO If no test.tap, then make one to spoof?
- uses: pcolby/tap-summary@0959cbe1d4422e62afc65778cdaea6716c41d936 # v1
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/nf-test-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
uses: ./.github/actions/nf-test-shard
env:
NFT_VER: ${{ env.NFT_VER }}
with:
tags: "cpu"
max_shards: 2

- name: Set outputs
id: set-outputs
Expand Down Expand Up @@ -81,7 +84,7 @@ jobs:
shard: ${{ matrix.shard }}
total_shards: ${{ needs.get-shards.outputs.total_shards }}
filters: ${{ matrix.filters }}
tags: "--tag gpu"
tags: "gpu"

confirm-pass:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/nf-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:
uses: ./.github/actions/nf-test-shard
env:
NFT_VER: ${{ env.NFT_VER }}
with:
tags: "cpu"
max_shards: 5

- name: Set outputs
id: set-outputs
Expand Down Expand Up @@ -84,6 +87,7 @@ jobs:
shard: ${{ matrix.shard }}
total_shards: ${{ needs.get-shards.outputs.total_shards }}
filters: ${{ matrix.filters }}
tags: "cpu"

confirm-pass:
runs-on: ubuntu-latest
Expand Down

0 comments on commit 46637d4

Please sign in to comment.