-
Notifications
You must be signed in to change notification settings - Fork 1
131 lines (126 loc) · 4.37 KB
/
dotnet.yml
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: Build and Test
on:
push:
paths:
- 'Gangs*/**'
- '.github/workflows/dotnet.yml'
- 'Core/**'
- 'Commands/**'
- 'coverage.runsettings'
pull_request:
paths:
- 'Gangs*/**'
- '.github/workflows/dotnet.yml'
- 'Core/**'
- 'Commands/**'
- 'coverage.runsettings'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ 6.0.x, 7.0.x, 8.0.x, 9.0.x ] # Test on multiple .NET versions
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Cache .NET packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
test:
permissions:
pull-requests: write
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: [ 8.0.x, 9.0.x ]
services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: gangs
ports:
- 3306:3306
options: --health-cmd "mysqladmin ping --silent" --health-interval 10s
mariadb:
image: mariadb:latest
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: yes
MARIADB_DATABASE: gangs
ports:
- 3307:3306
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Cache .NET packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test with MariaDB
env:
DB_CONNECTION_STRING: "Server=localhost;Port=3307;Database=gangs;User=root"
run: dotnet test GangsTest/GangsTest.csproj --no-build --verbosity normal
- name: Test with MySQL
env:
DB_CONNECTION_STRING: "Server=localhost;Port=3306;Database=gangs;User=root"
run: dotnet test GangsTest/GangsTest.csproj --no-build --verbosity normal
- name: Generate Code Coverage Report
env:
DB_CONNECTION_STRING: "Server=localhost;Port=3306;Database=gangs;User=root"
if: ${{ matrix.dotnet-version == '9.0.x' }}
run: dotnet test --no-build --verbosity normal --collect:"XPlat Code Coverage" --logger trx --results-directory coverage GangsTest/GangsTest.csproj --settings coverage.runsettings
- name: Code Coverage Summary Report
uses: irongut/[email protected]
if: ${{ matrix.dotnet-version == '9.0.x' }}
with:
filename: 'coverage/*/coverage.cobertura.xml'
badge: true
format: 'markdown'
output: 'both'
thresholds: '33 75'
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request' && matrix.dotnet-version == '9.0.x'
with:
recreate: true
path: code-coverage-results.md
- name: Export Code Coverage
if: ${{ matrix.dotnet-version == '9.0.x' }}
run: echo "CODE_COVERAGE=$(tail -n 1 code-coverage-results.md | grep -oP '(?<=\*\*Summary\*\* \|\s\*\*)[0-9]+(?=%)')" >> $GITHUB_ENV
- name: Create Test Coverage Badge
uses: Schneegans/[email protected]
id: create_coverage_badge
if: matrix.dotnet-version == '9.0.x' && github.ref_name == 'main'
with:
auth: ${{ secrets.GIST_AUTH_TOKEN }}
gistID: 72f982ea80cb7dabb6e91f21d6594ba8
filename: code-coverage.json
label: 'Code Coverage'
message: ${{ env.CODE_COVERAGE }}%
valColorRange: ${{ env.CODE_COVERAGE }}
maxColorRange: 100
minColorRange: 33
- name: Write to Job Summary
if: ${{ matrix.dotnet-version == '9.0.x' }}
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY