generated from SwissLife-OSS/template
-
Notifications
You must be signed in to change notification settings - Fork 18
102 lines (86 loc) · 2.74 KB
/
ci.yml
File metadata and controls
102 lines (86 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: CI
run-name: CI ${{ github.event.pull_request.title }}
on:
pull_request:
concurrency:
group: ci-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
discover-tests:
runs-on: ubuntu-latest
outputs:
test-projects: ${{ steps.find-tests.outputs.projects }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8
9
10
- name: Find test projects
id: find-tests
run: |
# Use dotnet msbuild to evaluate and list test project references from traversal project
dotnet msbuild ./all.csproj -p:BuildTestsOnly=true -t:Restore -v:q -nologo
# Get the evaluated ProjectReference items using MSBuild
projects=$(dotnet msbuild ./all.csproj -p:BuildTestsOnly=true -getItem:ProjectReference 2>/dev/null | \
grep -E "Include=" | \
sed -E 's/.*Include="([^"]+)".*/\1/' | \
jq -R -s -c 'split("\n") | map(select(length > 0))')
# Fallback: parse the glob pattern directly if getItem doesn't work
if [ -z "$projects" ] || [ "$projects" == "[]" ]; then
projects=$(ls -1 test/**/*Tests.csproj 2>/dev/null | jq -R -s -c 'split("\n") | map(select(length > 0))')
fi
echo "projects=$projects" >> $GITHUB_OUTPUT
echo "Found test projects:"
echo "$projects" | jq -r '.[]'
shell: bash
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8
9
10
- name: Build projects
run: dotnet build ./all.csproj
shell: bash
tests:
needs: [discover-tests, build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.discover-tests.outputs.test-projects) }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8
9
10
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-output
- name: Docker Information
run: |
echo -e "\n\033[0;34mDocker System Info \033[0m"
docker system info
echo -e "\n\033[0;34mDocker Containers \033[0m"
docker ps -a
shell: bash
- name: Run tests for ${{ matrix.project }}
run: dotnet test ${{ matrix.project }} --no-build
shell: bash