Skip to content

Commit 75d7786

Browse files
Add dynamic test discovery to CI workflow
The test workflow now automatically discovers all Umbraco.Ai* projects and runs their tests in parallel. Projects without test projects are gracefully skipped with clear logging. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 5efdfb1 commit 75d7786

1 file changed

Lines changed: 131 additions & 0 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
13+
jobs:
14+
discover-projects:
15+
runs-on: ubuntu-latest
16+
name: Discover Projects
17+
outputs:
18+
projects: ${{ steps.discover.outputs.projects }}
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
sparse-checkout: |
25+
Umbraco.Ai
26+
Umbraco.Ai.*
27+
sparse-checkout-cone-mode: false
28+
29+
- name: Discover projects
30+
id: discover
31+
run: |
32+
# Dynamically discover all Umbraco.Ai* projects
33+
# Umbraco.Ai/ -> "Core" (Umbraco.Ai)
34+
# Umbraco.Ai.<name>/ -> "<Name>" (Umbraco.Ai.<Name>)
35+
36+
PROJECTS="[]"
37+
38+
for dir in Umbraco.Ai*/; do
39+
if [ -d "$dir" ]; then
40+
dir_name=$(basename "$dir")
41+
42+
# Find solution file in the directory
43+
solution_file=$(find "$dir" -maxdepth 1 -name "*.sln" | head -n 1)
44+
45+
if [ -n "$solution_file" ]; then
46+
solution_name=$(basename "$solution_file")
47+
48+
if [ "$dir_name" = "Umbraco.Ai" ]; then
49+
# Core project
50+
project_json=$(jq -n \
51+
--arg name "Core" \
52+
--arg path "$dir_name" \
53+
--arg solution "$solution_name" \
54+
'{name: $name, path: $path, solution: $solution}')
55+
elif [[ "$dir_name" =~ ^Umbraco\.Ai\.(.+)$ ]]; then
56+
# Add-on or provider project
57+
project_name="${BASH_REMATCH[1]}"
58+
project_json=$(jq -n \
59+
--arg name "$project_name" \
60+
--arg path "$dir_name" \
61+
--arg solution "$solution_name" \
62+
'{name: $name, path: $path, solution: $solution}')
63+
fi
64+
65+
PROJECTS=$(echo "$PROJECTS" | jq --argjson project "$project_json" '. + [$project]')
66+
else
67+
echo "Warning: No solution file found in $dir_name"
68+
fi
69+
fi
70+
done
71+
72+
echo "Discovered projects:"
73+
echo "$PROJECTS" | jq .
74+
75+
# Output as JSON for matrix
76+
echo "projects=$(echo "$PROJECTS" | jq -c .)" >> $GITHUB_OUTPUT
77+
78+
test:
79+
runs-on: ubuntu-latest
80+
name: Test ${{ matrix.project.name }}
81+
needs: discover-projects
82+
if: needs.discover-projects.outputs.projects != '[]'
83+
84+
strategy:
85+
fail-fast: false
86+
matrix:
87+
project: ${{ fromJson(needs.discover-projects.outputs.projects) }}
88+
89+
steps:
90+
- name: Checkout repository
91+
uses: actions/checkout@v4
92+
93+
- name: Setup .NET
94+
uses: actions/setup-dotnet@v4
95+
with:
96+
dotnet-version: '10.0.x'
97+
98+
- name: Restore dependencies
99+
run: dotnet restore ${{ matrix.project.path }}/${{ matrix.project.solution }}
100+
101+
- name: Build
102+
run: dotnet build ${{ matrix.project.path }}/${{ matrix.project.solution }} --configuration Release --no-restore
103+
104+
- name: Check for test projects
105+
id: check-tests
106+
run: |
107+
# Check if solution contains any test projects
108+
test_projects=$(dotnet sln ${{ matrix.project.path }}/${{ matrix.project.solution }} list | grep -i "test" || true)
109+
if [ -z "$test_projects" ]; then
110+
echo "has_tests=false" >> $GITHUB_OUTPUT
111+
echo "⚠️ No test projects found in ${{ matrix.project.name }}"
112+
else
113+
echo "has_tests=true" >> $GITHUB_OUTPUT
114+
echo "✓ Found test projects:"
115+
echo "$test_projects"
116+
fi
117+
118+
- name: Run tests
119+
if: steps.check-tests.outputs.has_tests == 'true'
120+
run: dotnet test ${{ matrix.project.path }}/${{ matrix.project.solution }} --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx"
121+
122+
- name: Skip tests (none found)
123+
if: steps.check-tests.outputs.has_tests == 'false'
124+
run: echo "⚠️ Skipping tests - no test projects found in this solution"
125+
126+
- name: Upload test results
127+
if: always() && steps.check-tests.outputs.has_tests == 'true'
128+
uses: actions/upload-artifact@v4
129+
with:
130+
name: test-results-${{ matrix.project.name }}
131+
path: '**/TestResults/*.trx'

0 commit comments

Comments
 (0)