-
Notifications
You must be signed in to change notification settings - Fork 1
218 lines (193 loc) · 8.71 KB
/
Copy pathbackend.yml
File metadata and controls
218 lines (193 loc) · 8.71 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
name: Azure App Service CI/CD
on:
push:
branches:
- main
paths:
- ".github/workflows/backend.yml"
- "src/Directory.Build.props"
- "src/Directory.Packages.props"
- "src/global.json"
- "src/backend/services/TaskAgent/src/**/*.cs"
- "src/backend/services/TaskAgent/src/**/*.csproj"
- "src/backend/services/TaskAgent/src/**/*.json"
- "src/backend/services/TaskAgent/src/**/*.cshtml"
- "src/backend/services/TaskAgent/src/**/*.css"
- "src/backend/services/TaskAgent/src/**/*.js"
- "src/backend/services/TaskAgent/tests/**/*.cs"
- "src/backend/services/TaskAgent/tests/**/*.csproj"
- "src/backend/TaskAgent.ServiceDefaults/**/*.cs"
- "src/backend/TaskAgent.ServiceDefaults/**/*.csproj"
- "src/backend/TaskAgentWeb.slnx"
pull_request:
branches:
- main
paths:
- "src/backend/**"
- "!src/backend/**/*.md"
env:
AZURE_WEBAPP_NAME: app-taskagent-prod
AZURE_WEBAPP_PACKAGE_PATH: src/backend/services/TaskAgent/src/TaskAgent.WebApi/published
CONFIGURATION: Release
DOTNET_CORE_VERSION: 10.0.x
WORKING_DIRECTORY: src/backend/services/TaskAgent/src/TaskAgent.WebApi
SOLUTION_PATH: src/backend/TaskAgentWeb.slnx
TESTS_DIRECTORY: src/backend/services/TaskAgent/tests
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
name: Test
steps:
- uses: actions/checkout@v5
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
global-json-file: src/global.json
- name: Restore Solution
run: dotnet restore "${{ env.SOLUTION_PATH }}"
- name: Build Test Projects
run: dotnet build "${{ env.SOLUTION_PATH }}" --configuration ${{ env.CONFIGURATION }} --no-restore
- name: Run Unit Tests with Coverage
run: |
dotnet test "${{ env.TESTS_DIRECTORY }}/TaskAgent.Domain.UnitTests" \
--configuration ${{ env.CONFIGURATION }} \
--no-build \
--logger "trx;LogFileName=domain-tests.trx" \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults/Domain
dotnet test "${{ env.TESTS_DIRECTORY }}/TaskAgent.Application.UnitTests" \
--configuration ${{ env.CONFIGURATION }} \
--no-build \
--logger "trx;LogFileName=application-tests.trx" \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults/Application
- name: Run Integration Tests
run: |
dotnet test "${{ env.TESTS_DIRECTORY }}/TaskAgent.Infrastructure.IntegrationTests" \
--configuration ${{ env.CONFIGURATION }} \
--no-build \
--logger "trx;LogFileName=integration-tests.trx" \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults/Infrastructure
- name: Generate Combined Coverage Report
if: ${{ !cancelled() }}
run: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator \
-reports:"./TestResults/**/coverage.cobertura.xml" \
-targetdir:"./TestResults/CoverageReport" \
-reporttypes:"Html;JsonSummary;Cobertura"
- name: Generate Test Summary
if: ${{ !cancelled() }}
run: |
echo "## 🧪 Backend Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Count tests from TRX files
echo "### 📊 Test Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Project | Tests | Status |" >> $GITHUB_STEP_SUMMARY
echo "|---------|-------|--------|" >> $GITHUB_STEP_SUMMARY
# Domain Tests
if [ -f "./TestResults/Domain/domain-tests.trx" ]; then
DOMAIN_TOTAL=$(grep -oP 'total="\K[0-9]+' ./TestResults/Domain/domain-tests.trx | head -1 || echo "0")
DOMAIN_PASSED=$(grep -oP 'passed="\K[0-9]+' ./TestResults/Domain/domain-tests.trx | head -1 || echo "0")
echo "| Domain.UnitTests | $DOMAIN_PASSED/$DOMAIN_TOTAL | ✅ |" >> $GITHUB_STEP_SUMMARY
else
echo "| Domain.UnitTests | - | ⚠️ |" >> $GITHUB_STEP_SUMMARY
fi
# Application Tests
if [ -f "./TestResults/Application/application-tests.trx" ]; then
APP_TOTAL=$(grep -oP 'total="\K[0-9]+' ./TestResults/Application/application-tests.trx | head -1 || echo "0")
APP_PASSED=$(grep -oP 'passed="\K[0-9]+' ./TestResults/Application/application-tests.trx | head -1 || echo "0")
echo "| Application.UnitTests | $APP_PASSED/$APP_TOTAL | ✅ |" >> $GITHUB_STEP_SUMMARY
else
echo "| Application.UnitTests | - | ⚠️ |" >> $GITHUB_STEP_SUMMARY
fi
# Infrastructure Tests
if [ -f "./TestResults/Infrastructure/integration-tests.trx" ]; then
INFRA_TOTAL=$(grep -oP 'total="\K[0-9]+' ./TestResults/Infrastructure/integration-tests.trx | head -1 || echo "0")
INFRA_PASSED=$(grep -oP 'passed="\K[0-9]+' ./TestResults/Infrastructure/integration-tests.trx | head -1 || echo "0")
echo "| Infrastructure.IntegrationTests | $INFRA_PASSED/$INFRA_TOTAL | ✅ |" >> $GITHUB_STEP_SUMMARY
else
echo "| Infrastructure.IntegrationTests | - | ⚠️ |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
# Coverage Summary from ReportGenerator JSON
echo "### 📈 Coverage Summary (Combined)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f "./TestResults/CoverageReport/Summary.json" ]; then
echo "| Metric | Coverage |" >> $GITHUB_STEP_SUMMARY
echo "|--------|----------|" >> $GITHUB_STEP_SUMMARY
LINE_COV=$(cat ./TestResults/CoverageReport/Summary.json | jq -r '.summary.linecoverage // 0')
BRANCH_COV=$(cat ./TestResults/CoverageReport/Summary.json | jq -r '.summary.branchcoverage // 0')
METHOD_COV=$(cat ./TestResults/CoverageReport/Summary.json | jq -r '.summary.methodcoverage // 0')
echo "| Lines | ${LINE_COV}% |" >> $GITHUB_STEP_SUMMARY
echo "| Branches | ${BRANCH_COV}% |" >> $GITHUB_STEP_SUMMARY
echo "| Methods | ${METHOD_COV}% |" >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ Coverage summary not available" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "📥 **Download Reports:**" >> $GITHUB_STEP_SUMMARY
echo "- \`backend-test-results\` - TRX test results" >> $GITHUB_STEP_SUMMARY
echo "- \`backend-coverage\` - HTML coverage report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: Upload Test Results
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: backend-test-results
path: ./TestResults/**/**.trx
retention-days: 30
- name: Upload Coverage Reports
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: backend-coverage
path: ./TestResults/CoverageReport/
retention-days: 30
build:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
name: Build
steps:
- uses: actions/checkout@v5
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
global-json-file: src/global.json
- name: Restore
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
- name: Build
run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
- name: Publish
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}"
- name: Publish Artifacts
uses: actions/upload-artifact@v4
with:
name: webapp
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
deploy:
runs-on: ubuntu-latest
needs: build
if: false # Deployment disabled - no Azure App Service instances
name: Deploy
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v5
with:
name: webapp
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.app_taskagent_prod_SPN }}
- name: Deploy to Azure WebApp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}