Repository navigation
131 lines (117 loc) · 4.79 KB
/
Copy pathtest.yml
File metadata and controls
131 lines (117 loc) · 4.79 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Reusable Test
on:
workflow_call:
inputs:
dotnet-version:
description: .NET SDK version
required: false
type: string
default: '10.0.x'
test-dir:
description: Directory containing unit test project
required: false
type: string
default: 'Tests'
arch-test-dir:
description: Directory containing architecture test project
required: false
type: string
default: 'ArchTests'
arch-phases:
description: Comma-separated list of arch-test phases to run (A,B,C,D,E,Full)
required: false
type: string
default: 'A,B,C,D,E,Full'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Check Tests directory
id: check_tests
run: |
if [ -d "${{ inputs.test-dir }}" ]; then
csproj=$(find ${{ inputs.test-dir }} -maxdepth 1 -name '*.Tests.csproj' -print -quit 2>/dev/null)
if [ -n "$csproj" ]; then
echo "has_tests=true" >> $GITHUB_OUTPUT
echo "csproj=$(basename $csproj)" >> $GITHUB_OUTPUT
else
echo "has_tests=false" >> $GITHUB_OUTPUT
fi
else
echo "has_tests=false" >> $GITHUB_OUTPUT
fi
- name: Setup .NET
if: steps.check_tests.outputs.has_tests == 'true'
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ inputs.dotnet-version }}
- name: Restore dependencies
if: steps.check_tests.outputs.has_tests == 'true'
run: dotnet restore ${{ inputs.test-dir }}/${{ steps.check_tests.outputs.csproj }}
- name: Build
if: steps.check_tests.outputs.has_tests == 'true'
run: dotnet build ${{ inputs.test-dir }}/${{ steps.check_tests.outputs.csproj }} --no-restore -c Release
- name: Test
if: steps.check_tests.outputs.has_tests == 'true'
run: dotnet test ${{ inputs.test-dir }}/${{ steps.check_tests.outputs.csproj }} --no-build -c Release --verbosity normal
arch-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
phase: [A, B, C, D, E, Full]
steps:
- uses: actions/checkout@v7
- name: Check if phase is enabled
id: phase-check
run: |
PHASES="${{ inputs.arch-phases }}"
if echo "$PHASES" | grep -qw "${{ matrix.phase }}"; then
echo "enabled=true" >> $GITHUB_OUTPUT
else
echo "enabled=false" >> $GITHUB_OUTPUT
fi
- name: Check ArchTests directory
if: steps.phase-check.outputs.enabled == 'true'
id: check_arch
run: |
if [ -d "${{ inputs.arch-test-dir }}" ]; then
csproj=$(find ${{ inputs.arch-test-dir }} -maxdepth 1 -name '*.ArchTests.csproj' -print -quit 2>/dev/null)
if [ -n "$csproj" ]; then
echo "has_arch=true" >> $GITHUB_OUTPUT
echo "csproj=$(basename $csproj)" >> $GITHUB_OUTPUT
else
echo "has_arch=false" >> $GITHUB_OUTPUT
fi
else
echo "has_arch=false" >> $GITHUB_OUTPUT
fi
- name: Setup .NET
if: steps.phase-check.outputs.enabled == 'true' && steps.check_arch.outputs.has_arch == 'true'
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ inputs.dotnet-version }}
- name: Restore dependencies
if: steps.phase-check.outputs.enabled == 'true' && steps.check_arch.outputs.has_arch == 'true'
run: dotnet restore ${{ inputs.arch-test-dir }}/${{ steps.check_arch.outputs.csproj }}
- name: Build ArchTests
if: steps.phase-check.outputs.enabled == 'true' && steps.check_arch.outputs.has_arch == 'true'
run: dotnet build ${{ inputs.arch-test-dir }}/${{ steps.check_arch.outputs.csproj }} --no-restore -c Release
- name: Run ArchTests Phase ${{ matrix.phase }}
if: steps.phase-check.outputs.enabled == 'true' && steps.check_arch.outputs.has_arch == 'true'
run: |
FILTER=""
case "${{ matrix.phase }}" in
A) FILTER="Phase=A|Phase=General" ;;
B) FILTER="Phase=A|Phase=B|Phase=General" ;;
C) FILTER="Phase=A|Phase=B|Phase=C|Phase=General" ;;
D) FILTER="Phase=A|Phase=B|Phase=C|Phase=D|Phase=General" ;;
E) FILTER="Phase=A|Phase=B|Phase=C|Phase=D|Phase=E|Phase=General" ;;
Full) FILTER="" ;;
esac
if [ -n "$FILTER" ]; then
dotnet test ${{ inputs.arch-test-dir }}/${{ steps.check_arch.outputs.csproj }} --no-build -c Release --filter "$FILTER" --verbosity normal
else
dotnet test ${{ inputs.arch-test-dir }}/${{ steps.check_arch.outputs.csproj }} --no-build -c Release --verbosity normal
fi