|
| 1 | +name: Unit Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + pull_request: |
| 7 | + branches: [main, develop] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + test: |
| 15 | + name: Run Unit Tests |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up .NET |
| 22 | + uses: actions/setup-dotnet@v4 |
| 23 | + with: |
| 24 | + dotnet-version: '8.0.x' |
| 25 | + |
| 26 | + - name: Restore dependencies |
| 27 | + run: dotnet restore |
| 28 | + |
| 29 | + - name: Build |
| 30 | + run: dotnet build --configuration Release --no-restore |
| 31 | + |
| 32 | + - name: Run Tests |
| 33 | + run: dotnet test tests/SharpGraph.Tests/SharpGraph.Tests.csproj --configuration Release --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx" --logger "console;verbosity=detailed" |
| 34 | + |
| 35 | + - name: Generate Test Report |
| 36 | + if: always() |
| 37 | + run: | |
| 38 | + $trxFile = Get-ChildItem -Path . -Filter "test-results.trx" -Recurse | Select-Object -First 1 |
| 39 | + if ($null -ne $trxFile) { |
| 40 | + [xml]$trx = Get-Content $trxFile.FullName |
| 41 | + $passed = $trx.TestRun.ResultSummary.Counters.passed |
| 42 | + $failed = $trx.TestRun.ResultSummary.Counters.failed |
| 43 | + $total = $trx.TestRun.ResultSummary.Counters.total |
| 44 | + $duration = $trx.TestRun.Times.duration |
| 45 | + |
| 46 | + $report = @" |
| 47 | + # Unit Test Report |
| 48 | + |
| 49 | + **Run Date**: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC') |
| 50 | + **Branch**: ${{ github.ref_name }} |
| 51 | + **Commit**: ${{ github.sha }} |
| 52 | + |
| 53 | + ## Summary |
| 54 | + |
| 55 | + | Metric | Count | |
| 56 | + |--------|-------| |
| 57 | + | Total Tests | $total | |
| 58 | + | ✅ Passed | $passed | |
| 59 | + | ❌ Failed | $failed | |
| 60 | + | Duration | $duration | |
| 61 | + |
| 62 | + ## Test Categories |
| 63 | + |
| 64 | + - Lexer Tests |
| 65 | + - Filtering Tests |
| 66 | + - Storage Tests |
| 67 | + - Index Tests (BTree, Hash) |
| 68 | + - Mutation Tests |
| 69 | + - Parsing Tests |
| 70 | + |
| 71 | + ## Status |
| 72 | + |
| 73 | + $( if ($failed -eq 0) { "✅ **All tests passing**" } else { "❌ **Tests failed**" } ) |
| 74 | + |
| 75 | + --- |
| 76 | + |
| 77 | + [View Full Test Results](../actions/runs/${{ github.run_id }}) |
| 78 | + "@ |
| 79 | + |
| 80 | + $report | Out-File -FilePath "test-report.md" -Encoding UTF8 |
| 81 | + Write-Host $report |
| 82 | + } |
| 83 | +
|
| 84 | + - name: Upload Test Results |
| 85 | + uses: actions/upload-artifact@v4 |
| 86 | + if: always() |
| 87 | + with: |
| 88 | + name: test-results |
| 89 | + path: '**/test-results.trx' |
| 90 | + retention-days: 30 |
| 91 | + |
| 92 | + - name: Upload Test Report |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + if: always() |
| 95 | + with: |
| 96 | + name: test-report |
| 97 | + path: test-report.md |
| 98 | + retention-days: 30 |
0 commit comments