|
14 | 14 | - "src/backend/services/TaskAgent/src/**/*.cshtml" |
15 | 15 | - "src/backend/services/TaskAgent/src/**/*.css" |
16 | 16 | - "src/backend/services/TaskAgent/src/**/*.js" |
| 17 | + - "src/backend/services/TaskAgent/tests/**/*.cs" |
| 18 | + - "src/backend/services/TaskAgent/tests/**/*.csproj" |
17 | 19 | - "src/backend/TaskAgent.ServiceDefaults/**/*.cs" |
18 | 20 | - "src/backend/TaskAgent.ServiceDefaults/**/*.csproj" |
19 | 21 | - "src/backend/TaskAgentWeb.sln" |
| 22 | + pull_request: |
| 23 | + branches: |
| 24 | + - main |
| 25 | + paths: |
| 26 | + - "src/backend/**" |
| 27 | + - "!src/backend/**/*.md" |
20 | 28 | env: |
21 | 29 | AZURE_WEBAPP_NAME: app-taskagent-prod |
22 | 30 | AZURE_WEBAPP_PACKAGE_PATH: src/backend/services/TaskAgent/src/TaskAgent.WebApi/published |
23 | 31 | CONFIGURATION: Release |
24 | 32 | DOTNET_CORE_VERSION: 10.0.x |
25 | 33 | WORKING_DIRECTORY: src/backend/services/TaskAgent/src/TaskAgent.WebApi |
| 34 | + TESTS_DIRECTORY: src/backend/services/TaskAgent/tests |
26 | 35 | 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 | + |
27 | 140 | build: |
28 | 141 | runs-on: ubuntu-latest |
| 142 | + needs: test |
| 143 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 144 | + name: Build |
29 | 145 | steps: |
30 | | - - uses: actions/checkout@v4 |
| 146 | + - uses: actions/checkout@v5 |
| 147 | + |
31 | 148 | - name: Setup .NET SDK |
32 | 149 | uses: actions/setup-dotnet@v4 |
33 | 150 | with: |
34 | 151 | dotnet-version: ${{ env.DOTNET_CORE_VERSION }} |
| 152 | + |
35 | 153 | - name: Restore |
36 | 154 | run: dotnet restore "${{ env.WORKING_DIRECTORY }}" |
| 155 | + |
37 | 156 | - name: Build |
38 | 157 | run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore |
39 | | - - name: Test |
40 | | - run: dotnet test "${{ env.WORKING_DIRECTORY }}" --no-build |
| 158 | + |
41 | 159 | - name: Publish |
42 | 160 | run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}" |
| 161 | + |
43 | 162 | - name: Publish Artifacts |
44 | 163 | uses: actions/upload-artifact@v4 |
45 | 164 | with: |
46 | 165 | name: webapp |
47 | 166 | path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |
| 167 | + |
48 | 168 | deploy: |
49 | 169 | runs-on: ubuntu-latest |
50 | 170 | needs: build |
| 171 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 172 | + name: Deploy |
51 | 173 | steps: |
52 | 174 | - name: Download artifact from build job |
53 | | - uses: actions/download-artifact@v4 |
| 175 | + uses: actions/download-artifact@v5 |
54 | 176 | with: |
55 | 177 | name: webapp |
56 | 178 | path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |
| 179 | + |
57 | 180 | - name: Azure Login |
58 | 181 | uses: azure/login@v2 |
59 | 182 | with: |
|
0 commit comments