diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index e69c99e..f96c320 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,14 +1,19 @@ name: .NET on: + workflow_dispatch: pull_request: branches: - 'main' - 'develop' + - 'release/**' + - 'hotfix/**' push: branches: - 'main' - 'develop' + - 'release/**' + - 'hotfix/**' permissions: contents: read @@ -17,6 +22,7 @@ env: BUILD_CONFIGURATION: "Release" SOLUTION_PATH: source/AAS.TwinEngine.DataEngine.sln TEST_PROJECT: source/AAS.TwinEngine.DataEngine.UnitTests/AAS.TwinEngine.DataEngine.UnitTests.csproj + MODULE_TEST_PROJECT: source/AAS.TwinEngine.DataEngine.ModuleTests/AAS.TwinEngine.DataEngine.ModuleTests.csproj jobs: @@ -25,6 +31,7 @@ jobs: runs-on: ubuntu-latest permissions: + contents: read checks: write pull-requests: write @@ -44,12 +51,91 @@ jobs: run: dotnet build ${{ env.SOLUTION_PATH }} --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore - name: Run Unit Tests - run: dotnet test ${{ env.TEST_PROJECT }} --configuration Release --no-build --logger "trx;LogFileName=test_results.trx" + run: dotnet test ${{ env.TEST_PROJECT }} --configuration Release --no-build --logger "trx;LogFileName=unit_test_results.trx" --collect:"XPlat Code Coverage" --settings source/coverlet.runsettings + + # - name: Run Module Tests + # run: dotnet test ${{ env.MODULE_TEST_PROJECT }} --configuration Release --no-build --logger "trx;LogFileName=module_test_results.trx" --collect:"XPlat Code Coverage" --settings source/coverlet.runsettings - # https://github.com/dorny/test-reporter - name: Publish Test Results uses: dorny/test-reporter@fe45e9537387dac839af0d33ba56eed8e24189e8 # v2.3.0 + id: test-results + if: github.event.pull_request.head.repo.fork == false with: - name: Unit Tests - path: "**/test_results.trx" + name: Test Results (Unit & Module) + path: "**/*_test_results.trx" reporter: dotnet-trx + + - name: Combine Reports (Test Results) + if: github.event.pull_request.head.repo.fork == false + run: | + echo "# Test & Coverage Report" > results.md + echo "" >> results.md + echo "## Test Results Summary" >> results.md + echo "" >> results.md + echo "| Metric | Count |" >> results.md + echo "|--------|-------|" >> results.md + echo "| ✅ Passed | ${{ steps.test-results.outputs.passed }} |" >> results.md + echo "| ❌ Failed | ${{ steps.test-results.outputs.failed }} |" >> results.md + echo "| ⏭️ Skipped | ${{ steps.test-results.outputs.skipped }} |" >> results.md + echo "" >> results.md + echo "[View Detailed Test Results](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> results.md + echo "" >> results.md + echo "---" >> results.md + echo "" >> results.md + + - name: Code Coverage Report - Unit Tests + if: github.event.pull_request.head.repo.fork == false + uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0 + with: + filename: "source/AAS.TwinEngine.DataEngine.UnitTests/TestResults/*/coverage.cobertura.xml" + badge: false + fail_below_min: true + format: markdown + hide_branch_rate: false + hide_complexity: false + indicators: true + output: both + thresholds: "80 80" + + - name: Combine Reports (Unit Test Coverage Results) + if: github.event.pull_request.head.repo.fork == false + run: | + echo "## Code Coverage" >> results.md + echo "" >> results.md + echo "### Unit Tests Coverage" >> results.md + cat code-coverage-results.md >> results.md + echo "" >> results.md + + - name: Code Coverage Report - Module Tests + if: github.event.pull_request.head.repo.fork == false + uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0 + with: + filename: "source/AAS.TwinEngine.DataEngine.ModuleTests/TestResults/*/coverage.cobertura.xml" + badge: false + fail_below_min: false + format: markdown + hide_branch_rate: false + hide_complexity: false + indicators: true + output: both + + - name: Combine Reports (Module Test Coverage Results) + if: github.event.pull_request.head.repo.fork == false + run: | + echo "### Module Tests Coverage" >> results.md + cat code-coverage-results.md >> results.md + + + - name: Add PR Comment + if: github.event.pull_request.head.repo.fork == false + uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0 + with: + recreate: true + path: results.md + + - name: Upload TRX as artifact (Fork PR fallback) + if: github.event.pull_request.head.repo.fork == true + uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + with: + name: test-results + path: "**/*_test_results.trx" \ No newline at end of file