-
Notifications
You must be signed in to change notification settings - Fork 94
159 lines (132 loc) · 4.95 KB
/
dotnet-core.yml
File metadata and controls
159 lines (132 loc) · 4.95 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: .NET
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
DOTNET_VERSION: '8.0.x'
WORKING_DIRECTORY: './src'
CONFIGURATION: 'Release'
jobs:
build-and-test:
name: 🏗️ Build & Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false
steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔧 Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 📦 Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: 🔄 Restore dependencies
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dotnet restore --verbosity minimal
- name: 🏗️ Build solution
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore --verbosity minimal
- name: 🧪 Run unit tests
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dotnet test --configuration ${{ env.CONFIGURATION }} --no-build --verbosity minimal --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByFile="**/Program.cs"
- name: 📊 Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.os }}
path: ${{ env.WORKING_DIRECTORY }}/TestResults/
- name: 📈 Upload coverage reports
uses: actions/upload-artifact@v4
if: always() && matrix.os == 'ubuntu-latest'
with:
name: coverage-reports
path: ${{ env.WORKING_DIRECTORY }}/TestResults/**/coverage.cobertura.xml
security-scan:
name: 🔒 Security Scan
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔧 Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 🔐 Run security scan
working-directory: ${{ env.WORKING_DIRECTORY }}
run: |
dotnet list package --vulnerable --include-transitive || true
dotnet list package --deprecated || true
code-quality:
name: 📏 Code Quality
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'pull_request' && !cancelled()
steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔧 Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 📊 Download coverage reports
uses: actions/download-artifact@v4
with:
name: coverage-reports
path: coverage/
continue-on-error: true
- name: 📈 Generate coverage report
run: |
if [ -d "coverage" ] && [ "$(find coverage -name 'coverage.cobertura.xml' | wc -l)" -gt 0 ]; then
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:"coverage/**/coverage.cobertura.xml" -targetdir:"coverage-report" -reporttypes:"MarkdownSummaryGithub"
else
echo "⚠️ No coverage files found. Skipping coverage report generation."
mkdir -p coverage-report
echo "# ⚠️ Coverage Report Not Available" > coverage-report/SummaryGithub.md
echo "Coverage data was not generated in the build-and-test job." >> coverage-report/SummaryGithub.md
fi
- name: 💬 Comment coverage on PR
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request' && hashFiles('coverage-report/SummaryGithub.md') != ''
with:
recreate: true
path: coverage-report/SummaryGithub.md
publish-packages:
name: 📦 Publish Packages
runs-on: ubuntu-latest
needs: [build-and-test, security-scan]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔧 Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 📦 Create packages
working-directory: ${{ env.WORKING_DIRECTORY }}
run: dotnet pack --configuration ${{ env.CONFIGURATION }} --output ./packages
- name: 📤 Upload packages artifact
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ${{ env.WORKING_DIRECTORY }}/packages/*.nupkg