-
Notifications
You must be signed in to change notification settings - Fork 0
354 lines (304 loc) · 13.4 KB
/
Copy pathserver-test.yml
File metadata and controls
354 lines (304 loc) · 13.4 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
name: Server Test
# ============================================
# サーバーテストワークフロー
# - 単体テスト(xUnit)
# - 統合テスト(Testcontainers + PostgreSQL)
# - コードカバレッジレポート
# - 脆弱性パッケージ検査
# ============================================
on:
# 手動実行
workflow_dispatch:
# PR 時に自動実行(サーバー関連ファイル変更時)
pull_request:
branches: [main, develop]
paths:
- 'src/Game.Server/**'
- 'src/Game.Shared/**'
- 'src/Game.Realtime/**'
- 'test/Game.Server.Tests/**'
- 'test/Game.Realtime.Tests/**'
- '.github/workflows/server-test.yml'
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DOTNET_VERSION: '9.0.x'
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
# ============================================
# 脆弱性パッケージ検査
# ============================================
vulnerability-check:
name: Vulnerability Check
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup .NET
uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore packages
run: dotnet restore src/Game.Server/Game.Server.csproj
- name: Check for vulnerable packages
run: |
OUTPUT=$(dotnet list src/Game.Server/Game.Server.csproj package --vulnerable --include-transitive 2>&1)
echo "$OUTPUT"
if echo "$OUTPUT" | grep -q "has the following vulnerable packages"; then
echo ""
echo "::error::Vulnerable packages detected. Update affected packages or review the vulnerabilities."
exit 1
fi
echo "No vulnerable packages found."
# ============================================
# 単体テスト(高速・Dockerなし)
# ============================================
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup .NET
uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Cache NuGet packages
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: |
dotnet restore test/Game.Server.Tests/Game.Server.Tests.csproj
dotnet restore test/Game.Realtime.Tests/Game.Realtime.Tests.csproj
- name: Build
run: |
dotnet build test/Game.Server.Tests/Game.Server.Tests.csproj --no-restore --configuration Release
dotnet build test/Game.Realtime.Tests/Game.Realtime.Tests.csproj --no-restore --configuration Release
- name: Run unit tests
run: |
dotnet test test/Game.Server.Tests/Game.Server.Tests.csproj \
--no-build \
--configuration Release \
--filter "FullyQualifiedName!~Integration" \
--logger "trx;LogFileName=unit-test-results.trx" \
--results-directory TestResults \
--collect:"XPlat Code Coverage" \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
dotnet test test/Game.Realtime.Tests/Game.Realtime.Tests.csproj \
--no-build \
--configuration Release \
--filter "FullyQualifiedName!~Integration" \
--logger "trx;LogFileName=realtime-unit-test-results.trx" \
--results-directory TestResults \
--collect:"XPlat Code Coverage" \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
- name: Upload test results
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: Unit-Test-Results
path: TestResults/
retention-days: 7
- name: Publish test results
uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 # v3.0.0
if: always()
with:
name: Unit Test Report
path: TestResults/*.trx
reporter: dotnet-trx
# ============================================
# 統合テスト(Testcontainers + PostgreSQL)
# ============================================
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
timeout-minutes: 20
# 単体テスト成功後に実行
needs: unit-tests
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup .NET
uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Cache NuGet packages
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore test/Game.Server.Tests/Game.Server.Tests.csproj
- name: Build
run: dotnet build test/Game.Server.Tests/Game.Server.Tests.csproj --no-restore --configuration Release
- name: Run integration tests
run: |
dotnet test test/Game.Server.Tests/Game.Server.Tests.csproj \
--no-build \
--configuration Release \
--filter "FullyQualifiedName~Integration" \
--logger "trx;LogFileName=integration-test-results.trx" \
--results-directory TestResults \
--collect:"XPlat Code Coverage" \
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
env:
# Testcontainers 設定
TESTCONTAINERS_RYUK_DISABLED: false
DOCKER_HOST: unix:///var/run/docker.sock
- name: Upload test results
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: Integration-Test-Results
path: TestResults/
retention-days: 7
- name: Publish test results
uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 # v3.0.0
if: always()
with:
name: Integration Test Report
path: TestResults/*.trx
reporter: dotnet-trx
# ============================================
# コードカバレッジレポート
# ============================================
coverage-report:
name: Coverage Report
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests]
if: always() && (needs.unit-tests.result == 'success' || needs.integration-tests.result == 'success')
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Download unit test coverage
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: Unit-Test-Results
path: TestResults/Unit
continue-on-error: true
- name: Download integration test coverage
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: Integration-Test-Results
path: TestResults/Integration
continue-on-error: true
- name: Setup .NET
uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 # v5.2.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Install ReportGenerator
run: dotnet tool install --global dotnet-reportgenerator-globaltool
- name: Generate coverage report
run: |
# カバレッジファイルを検索
coverage_files=$(find TestResults -name "coverage.opencover.xml" -o -name "coverage.cobertura.xml" | tr '\n' ';')
if [ -n "$coverage_files" ]; then
reportgenerator \
-reports:"$coverage_files" \
-targetdir:CoverageReport \
-reporttypes:"Html;MarkdownSummaryGithub;XmlSummary;Badges" \
-assemblyfilters:"+Game.Server;+Game.Shared;+Game.Realtime;+Game.Realtime.Shared" \
-classfilters:"-*Migrations*"
# サマリーを GitHub Step Summary に出力
if [ -f "CoverageReport/SummaryGithub.md" ]; then
cat CoverageReport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
fi
else
echo "No coverage files found" >> $GITHUB_STEP_SUMMARY
fi
- name: Check coverage threshold
if: success()
run: |
# 現在の実測値: Line 28.4%, Branch 20% (2026-04-02時点)
# カバレッジ向上に伴い段階的に引き上げること
THRESHOLD=20
if [ -f "CoverageReport/Summary.xml" ]; then
LINE_COVERAGE=$(grep -oP 'Linecoverage>\K[0-9.]+' CoverageReport/Summary.xml | head -1)
BRANCH_COVERAGE=$(grep -oP 'Branchcoverage>\K[0-9.]+' CoverageReport/Summary.xml | head -1)
echo "Line Coverage: ${LINE_COVERAGE:-N/A}%"
echo "Branch Coverage: ${BRANCH_COVERAGE:-N/A}%"
LINE_INT=${LINE_COVERAGE%.*}
if [ "${LINE_INT:-0}" -lt "$THRESHOLD" ]; then
echo "::error::Line coverage ${LINE_COVERAGE}% is below threshold ${THRESHOLD}%"
exit 1
fi
echo "Coverage check passed: ${LINE_COVERAGE}% >= ${THRESHOLD}%"
else
echo "::warning::Coverage summary XML not found, skipping threshold check"
fi
# PRコメント投稿:
# - marocchino/sticky-pull-request-comment: header指定でstickyコメント(上書き更新)がネイティブ対応、pathパラメータでファイル直接読込可能
# - gh pr comment: sticky機能を自前実装する必要がありメンテナンスコスト増
- name: Post coverage to PR
if: github.event_name == 'pull_request' && always()
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
with:
header: coverage-report
path: CoverageReport/SummaryGithub.md
- name: Upload coverage report
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: Coverage-Report
path: CoverageReport/
retention-days: 7
# ============================================
# サマリーレポート
# ============================================
summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests, coverage-report, vulnerability-check]
if: always()
steps:
- name: Generate summary
run: |
echo "## Server Test Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Test Suite | Status |" >> $GITHUB_STEP_SUMMARY
echo "|------------|--------|" >> $GITHUB_STEP_SUMMARY
# Unit Tests
if [ "${{ needs.unit-tests.result }}" == "success" ]; then
echo "| Unit Tests | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
elif [ "${{ needs.unit-tests.result }}" == "skipped" ]; then
echo "| Unit Tests | ⏭️ Skipped |" >> $GITHUB_STEP_SUMMARY
else
echo "| Unit Tests | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
# Integration Tests
if [ "${{ needs.integration-tests.result }}" == "success" ]; then
echo "| Integration Tests | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
elif [ "${{ needs.integration-tests.result }}" == "skipped" ]; then
echo "| Integration Tests | ⏭️ Skipped |" >> $GITHUB_STEP_SUMMARY
else
echo "| Integration Tests | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
# Coverage Report
if [ "${{ needs.coverage-report.result }}" == "success" ]; then
echo "| Coverage Report | ✅ Generated |" >> $GITHUB_STEP_SUMMARY
elif [ "${{ needs.coverage-report.result }}" == "skipped" ]; then
echo "| Coverage Report | ⏭️ Skipped |" >> $GITHUB_STEP_SUMMARY
else
echo "| Coverage Report | ⚠️ Issues |" >> $GITHUB_STEP_SUMMARY
fi
# Vulnerability Check
if [ "${{ needs.vulnerability-check.result }}" == "success" ]; then
echo "| Vulnerability Check | ✅ No Issues |" >> $GITHUB_STEP_SUMMARY
elif [ "${{ needs.vulnerability-check.result }}" == "skipped" ]; then
echo "| Vulnerability Check | ⏭️ Skipped |" >> $GITHUB_STEP_SUMMARY
else
echo "| Vulnerability Check | ❌ Vulnerable Packages Found |" >> $GITHUB_STEP_SUMMARY
fi