Skip to content

Commit c7adfd7

Browse files
committed
ci: shard CLI integration tests
1 parent 993fc23 commit c7adfd7

2 files changed

Lines changed: 107 additions & 2 deletions

File tree

.github/workflows/main.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,33 @@ jobs:
1616
uses: tryAGI/workflows/.github/workflows/dotnet-sdk-build-test-publish.yml@main
1717
with:
1818
project-path: AutoSDK.slnx
19-
additional-test-arguments: '--logger GitHubActions --no-build'
19+
additional-test-arguments: '--logger GitHubActions --no-build --filter "FullyQualifiedName!~AutoSDK.IntegrationTests"'
2020
secrets:
2121
nuget-key: ${{ secrets.NUGET_KEY }}
2222

23+
test-cli-integration:
24+
name: test-cli-integration (shard ${{ matrix.shard }})
25+
runs-on: ubuntu-latest
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
shard: [0, 1, 2, 3]
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v7
33+
34+
- name: Setup .NET
35+
uses: actions/setup-dotnet@v5
36+
with:
37+
dotnet-version: 10.0.x
38+
39+
- name: Run integration test shard
40+
run: ./scripts/run-test-shard.sh
41+
src/tests/AutoSDK.IntegrationTests.Cli/AutoSDK.IntegrationTests.Cli.csproj
42+
${{ matrix.shard }}
43+
4
44+
Release
45+
2346
test-cli:
2447
runs-on: ubuntu-latest
2548
strategy:
@@ -86,7 +109,7 @@ jobs:
86109
release:
87110
name: Release
88111
runs-on: ubuntu-latest
89-
needs: [publish, test-cli]
112+
needs: [publish, test-cli, test-cli-integration]
90113
if: startsWith(github.ref, 'refs/tags/v')
91114
steps:
92115
- name: Checkout

scripts/run-test-shard.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ $# -lt 3 || $# -gt 4 ]]; then
6+
echo "Usage: $0 <project> <zero-based-shard-index> <shard-count> [configuration]" >&2
7+
exit 2
8+
fi
9+
10+
project=$1
11+
shard_index=$2
12+
shard_count=$3
13+
configuration=${4:-Release}
14+
15+
if ! [[ $shard_index =~ ^[0-9]+$ && $shard_count =~ ^[1-9][0-9]*$ ]]; then
16+
echo "Shard index and count must be non-negative integers, with a positive count." >&2
17+
exit 2
18+
fi
19+
20+
if (( shard_index >= shard_count )); then
21+
echo "Shard index $shard_index is outside the $shard_count available shards." >&2
22+
exit 2
23+
fi
24+
25+
dotnet build "$project" --configuration "$configuration" --nologo
26+
27+
tests=()
28+
while IFS= read -r test_name; do
29+
tests+=("$test_name")
30+
done < <(
31+
dotnet test "$project" \
32+
--configuration "$configuration" \
33+
--nologo \
34+
--no-build \
35+
--list-tests |
36+
awk '
37+
/The following Tests are available:/ { capture = 1; next }
38+
capture && /^ / {
39+
sub(/^[[:space:]]+/, "")
40+
sub(/[[:space:]]+$/, "")
41+
print
42+
}
43+
'
44+
)
45+
46+
if (( ${#tests[@]} == 0 )); then
47+
echo "No tests were discovered in $project." >&2
48+
exit 1
49+
fi
50+
51+
duplicate_names=$(printf '%s\n' "${tests[@]}" | sort | uniq -d)
52+
if [[ -n $duplicate_names ]]; then
53+
echo "Test names must be unique for name-based sharding. Duplicates:" >&2
54+
echo "$duplicate_names" >&2
55+
exit 1
56+
fi
57+
58+
filters=()
59+
for test_index in "${!tests[@]}"; do
60+
if (( test_index % shard_count == shard_index )); then
61+
filters+=("Name=${tests[$test_index]}")
62+
fi
63+
done
64+
65+
if (( ${#filters[@]} == 0 )); then
66+
echo "Shard $shard_index has no tests." >&2
67+
exit 1
68+
fi
69+
70+
filter=$(IFS='|'; printf '%s' "${filters[*]}")
71+
printf 'Running shard %d of %d with %d of %d tests.\n' \
72+
"$((shard_index + 1))" \
73+
"$shard_count" \
74+
"${#filters[@]}" \
75+
"${#tests[@]}"
76+
77+
dotnet test "$project" \
78+
--configuration "$configuration" \
79+
--nologo \
80+
--logger GitHubActions \
81+
--no-build \
82+
--filter "$filter"

0 commit comments

Comments
 (0)