Skip to content

Commit 6b07266

Browse files
committed
ci(backend): enhance CI workflow for backend testing and deployment
1 parent 1ef5c37 commit 6b07266

1 file changed

Lines changed: 127 additions & 4 deletions

File tree

.github/workflows/backend.yml

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,169 @@ on:
1414
- "src/backend/services/TaskAgent/src/**/*.cshtml"
1515
- "src/backend/services/TaskAgent/src/**/*.css"
1616
- "src/backend/services/TaskAgent/src/**/*.js"
17+
- "src/backend/services/TaskAgent/tests/**/*.cs"
18+
- "src/backend/services/TaskAgent/tests/**/*.csproj"
1719
- "src/backend/TaskAgent.ServiceDefaults/**/*.cs"
1820
- "src/backend/TaskAgent.ServiceDefaults/**/*.csproj"
1921
- "src/backend/TaskAgentWeb.sln"
22+
pull_request:
23+
branches:
24+
- main
25+
paths:
26+
- "src/backend/**"
27+
- "!src/backend/**/*.md"
2028
env:
2129
AZURE_WEBAPP_NAME: app-taskagent-prod
2230
AZURE_WEBAPP_PACKAGE_PATH: src/backend/services/TaskAgent/src/TaskAgent.WebApi/published
2331
CONFIGURATION: Release
2432
DOTNET_CORE_VERSION: 10.0.x
2533
WORKING_DIRECTORY: src/backend/services/TaskAgent/src/TaskAgent.WebApi
34+
TESTS_DIRECTORY: src/backend/services/TaskAgent/tests
2635
jobs:
36+
test:
37+
runs-on: ubuntu-latest
38+
timeout-minutes: 30
39+
name: Test
40+
steps:
41+
- uses: actions/checkout@v5
42+
43+
- name: Setup .NET SDK
44+
uses: actions/setup-dotnet@v4
45+
with:
46+
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
47+
48+
- name: Restore Test Projects
49+
run: dotnet restore "${{ env.TESTS_DIRECTORY }}"
50+
51+
- name: Build Test Projects
52+
run: dotnet build "${{ env.TESTS_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
53+
54+
- name: Run Unit Tests with Coverage
55+
run: |
56+
dotnet test "${{ env.TESTS_DIRECTORY }}/TaskAgent.Domain.UnitTests" \
57+
--configuration ${{ env.CONFIGURATION }} \
58+
--no-build \
59+
--logger "trx;LogFileName=domain-tests.trx" \
60+
--collect:"XPlat Code Coverage" \
61+
--results-directory ./TestResults/Domain
62+
63+
dotnet test "${{ env.TESTS_DIRECTORY }}/TaskAgent.Application.UnitTests" \
64+
--configuration ${{ env.CONFIGURATION }} \
65+
--no-build \
66+
--logger "trx;LogFileName=application-tests.trx" \
67+
--collect:"XPlat Code Coverage" \
68+
--results-directory ./TestResults/Application
69+
70+
- name: Run Integration Tests
71+
run: |
72+
dotnet test "${{ env.TESTS_DIRECTORY }}/TaskAgent.Infrastructure.IntegrationTests" \
73+
--configuration ${{ env.CONFIGURATION }} \
74+
--no-build \
75+
--logger "trx;LogFileName=integration-tests.trx" \
76+
--collect:"XPlat Code Coverage" \
77+
--results-directory ./TestResults/Infrastructure
78+
79+
- name: Generate Test Summary
80+
if: ${{ !cancelled() }}
81+
run: |
82+
echo "## 🧪 Backend Test Results" >> $GITHUB_STEP_SUMMARY
83+
echo "" >> $GITHUB_STEP_SUMMARY
84+
85+
# Count tests from TRX files
86+
echo "### 📊 Test Summary" >> $GITHUB_STEP_SUMMARY
87+
echo "" >> $GITHUB_STEP_SUMMARY
88+
echo "| Project | Tests | Status |" >> $GITHUB_STEP_SUMMARY
89+
echo "|---------|-------|--------|" >> $GITHUB_STEP_SUMMARY
90+
91+
# Domain Tests
92+
if [ -f "./TestResults/Domain/domain-tests.trx" ]; then
93+
DOMAIN_TOTAL=$(grep -oP 'total="\K[0-9]+' ./TestResults/Domain/domain-tests.trx | head -1 || echo "0")
94+
DOMAIN_PASSED=$(grep -oP 'passed="\K[0-9]+' ./TestResults/Domain/domain-tests.trx | head -1 || echo "0")
95+
echo "| Domain.UnitTests | $DOMAIN_PASSED/$DOMAIN_TOTAL | ✅ |" >> $GITHUB_STEP_SUMMARY
96+
else
97+
echo "| Domain.UnitTests | - | ⚠️ |" >> $GITHUB_STEP_SUMMARY
98+
fi
99+
100+
# Application Tests
101+
if [ -f "./TestResults/Application/application-tests.trx" ]; then
102+
APP_TOTAL=$(grep -oP 'total="\K[0-9]+' ./TestResults/Application/application-tests.trx | head -1 || echo "0")
103+
APP_PASSED=$(grep -oP 'passed="\K[0-9]+' ./TestResults/Application/application-tests.trx | head -1 || echo "0")
104+
echo "| Application.UnitTests | $APP_PASSED/$APP_TOTAL | ✅ |" >> $GITHUB_STEP_SUMMARY
105+
else
106+
echo "| Application.UnitTests | - | ⚠️ |" >> $GITHUB_STEP_SUMMARY
107+
fi
108+
109+
# Infrastructure Tests
110+
if [ -f "./TestResults/Infrastructure/integration-tests.trx" ]; then
111+
INFRA_TOTAL=$(grep -oP 'total="\K[0-9]+' ./TestResults/Infrastructure/integration-tests.trx | head -1 || echo "0")
112+
INFRA_PASSED=$(grep -oP 'passed="\K[0-9]+' ./TestResults/Infrastructure/integration-tests.trx | head -1 || echo "0")
113+
echo "| Infrastructure.IntegrationTests | $INFRA_PASSED/$INFRA_TOTAL | ✅ |" >> $GITHUB_STEP_SUMMARY
114+
else
115+
echo "| Infrastructure.IntegrationTests | - | ⚠️ |" >> $GITHUB_STEP_SUMMARY
116+
fi
117+
118+
echo "" >> $GITHUB_STEP_SUMMARY
119+
echo "📥 **Download Reports:**" >> $GITHUB_STEP_SUMMARY
120+
echo "- \`backend-test-results\` - TRX test results" >> $GITHUB_STEP_SUMMARY
121+
echo "- \`backend-coverage\` - Code coverage reports" >> $GITHUB_STEP_SUMMARY
122+
echo "" >> $GITHUB_STEP_SUMMARY
123+
124+
- name: Upload Test Results
125+
uses: actions/upload-artifact@v4
126+
if: ${{ !cancelled() }}
127+
with:
128+
name: backend-test-results
129+
path: ./TestResults/**/**.trx
130+
retention-days: 30
131+
132+
- name: Upload Coverage Reports
133+
uses: actions/upload-artifact@v4
134+
if: ${{ !cancelled() }}
135+
with:
136+
name: backend-coverage
137+
path: ./TestResults/**/coverage.cobertura.xml
138+
retention-days: 30
139+
27140
build:
28141
runs-on: ubuntu-latest
142+
needs: test
143+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
144+
name: Build
29145
steps:
30-
- uses: actions/checkout@v4
146+
- uses: actions/checkout@v5
147+
31148
- name: Setup .NET SDK
32149
uses: actions/setup-dotnet@v4
33150
with:
34151
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
152+
35153
- name: Restore
36154
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
155+
37156
- name: Build
38157
run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
39-
- name: Test
40-
run: dotnet test "${{ env.WORKING_DIRECTORY }}" --no-build
158+
41159
- name: Publish
42160
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}"
161+
43162
- name: Publish Artifacts
44163
uses: actions/upload-artifact@v4
45164
with:
46165
name: webapp
47166
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
167+
48168
deploy:
49169
runs-on: ubuntu-latest
50170
needs: build
171+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
172+
name: Deploy
51173
steps:
52174
- name: Download artifact from build job
53-
uses: actions/download-artifact@v4
175+
uses: actions/download-artifact@v5
54176
with:
55177
name: webapp
56178
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
179+
57180
- name: Azure Login
58181
uses: azure/login@v2
59182
with:

0 commit comments

Comments
 (0)