|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, dev ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, dev ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-and-test: |
| 12 | + name: Build and Test |
| 13 | + runs-on: ${{ matrix.os }} |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 17 | + dotnet-version: ['8.0.x', '9.0.x'] |
| 18 | + fail-fast: false |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Setup .NET |
| 27 | + uses: actions/setup-dotnet@v4 |
| 28 | + with: |
| 29 | + dotnet-version: ${{ matrix.dotnet-version }} |
| 30 | + |
| 31 | + - name: Restore dependencies |
| 32 | + run: dotnet restore |
| 33 | + |
| 34 | + - name: Build |
| 35 | + run: dotnet build --configuration Release --no-restore |
| 36 | + |
| 37 | + - name: Run tests |
| 38 | + run: dotnet test --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx" --collect:"XPlat Code Coverage" --results-directory ./TestResults |
| 39 | + |
| 40 | + - name: Upload test results |
| 41 | + uses: actions/upload-artifact@v4 |
| 42 | + if: always() |
| 43 | + with: |
| 44 | + name: test-results-${{ matrix.os }}-${{ matrix.dotnet-version }} |
| 45 | + path: ./TestResults/*.trx |
| 46 | + |
| 47 | + - name: Upload coverage reports |
| 48 | + uses: actions/upload-artifact@v4 |
| 49 | + if: always() |
| 50 | + with: |
| 51 | + name: coverage-${{ matrix.os }}-${{ matrix.dotnet-version }} |
| 52 | + path: ./TestResults/**/coverage.cobertura.xml |
| 53 | + |
| 54 | + code-coverage: |
| 55 | + name: Code Coverage Report |
| 56 | + runs-on: ubuntu-latest |
| 57 | + needs: build-and-test |
| 58 | + if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' |
| 59 | + |
| 60 | + steps: |
| 61 | + - name: Checkout code |
| 62 | + uses: actions/checkout@v4 |
| 63 | + |
| 64 | + - name: Download coverage reports |
| 65 | + uses: actions/download-artifact@v4 |
| 66 | + with: |
| 67 | + pattern: coverage-ubuntu-latest-9.0.x |
| 68 | + path: ./coverage |
| 69 | + |
| 70 | + - name: Code Coverage Summary |
| 71 | + uses: irongut/CodeCoverageSummary@v1.3.0 |
| 72 | + with: |
| 73 | + filename: ./coverage/**/coverage.cobertura.xml |
| 74 | + badge: true |
| 75 | + fail_below_min: false |
| 76 | + format: markdown |
| 77 | + hide_branch_rate: false |
| 78 | + hide_complexity: false |
| 79 | + indicators: true |
| 80 | + output: both |
| 81 | + thresholds: '60 80' |
| 82 | + |
| 83 | + - name: Add Coverage PR Comment |
| 84 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 85 | + if: github.event_name == 'pull_request' |
| 86 | + with: |
| 87 | + recreate: true |
| 88 | + path: code-coverage-results.md |
| 89 | + |
| 90 | + build-status: |
| 91 | + name: Build Status |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: [build-and-test] |
| 94 | + if: always() |
| 95 | + |
| 96 | + steps: |
| 97 | + - name: Check build status |
| 98 | + run: | |
| 99 | + if [ "${{ needs.build-and-test.result }}" != "success" ]; then |
| 100 | + echo "Build or tests failed!" |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + echo "All builds and tests passed successfully!" |
0 commit comments