Fixbranch1 #216
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| global-json-file: global.json | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.nuget/packages | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Restore dependencies | |
| run: dotnet restore FolderDiffIL4DotNet.sln | |
| - name: Build | |
| run: dotnet build FolderDiffIL4DotNet.sln --configuration Release --no-restore | |
| - name: Install DocFX | |
| run: dotnet tool update --global docfx --version '2.*' | |
| - name: Generate documentation site | |
| run: | | |
| export PATH="$PATH:$HOME/.dotnet/tools" | |
| docfx metadata docfx.json | |
| docfx build docfx.json | |
| - name: Install real disassembler for E2E tests | |
| if: ${{ hashFiles('FolderDiffIL4DotNet.Tests/FolderDiffIL4DotNet.Tests.csproj') != '' }} | |
| run: | | |
| dotnet tool install --global dotnet-ildasm | |
| DOTNET_ROLL_FORWARD=Major dotnet-ildasm --version | |
| - name: Test with coverage | |
| if: ${{ hashFiles('FolderDiffIL4DotNet.Tests/FolderDiffIL4DotNet.Tests.csproj') != '' }} | |
| env: | |
| DOTNET_ROLL_FORWARD: Major | |
| run: dotnet test FolderDiffIL4DotNet.Tests/FolderDiffIL4DotNet.Tests.csproj --configuration Release --no-build --nologo --logger "trx;LogFileName=test_results.trx" --collect:"XPlat Code Coverage" --results-directory ./TestResults | |
| - name: Install ReportGenerator | |
| if: ${{ hashFiles('FolderDiffIL4DotNet.Tests/FolderDiffIL4DotNet.Tests.csproj') != '' }} | |
| run: dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.* | |
| - name: Generate coverage report | |
| if: ${{ hashFiles('FolderDiffIL4DotNet.Tests/FolderDiffIL4DotNet.Tests.csproj') != '' }} | |
| run: | | |
| export PATH="$PATH:$HOME/.dotnet/tools" | |
| reportgenerator \ | |
| -reports:"TestResults/**/coverage.cobertura.xml" \ | |
| -targetdir:"CoverageReport" \ | |
| -reporttypes:"MarkdownSummaryGithub;Cobertura;HtmlInline_AzurePipelines" | |
| if [ -f "CoverageReport/SummaryGithub.md" ]; then | |
| cat CoverageReport/SummaryGithub.md >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| - name: Enforce coverage thresholds | |
| if: ${{ hashFiles('FolderDiffIL4DotNet.Tests/FolderDiffIL4DotNet.Tests.csproj') != '' }} | |
| run: | | |
| python3 - <<'PY' | |
| import glob | |
| import sys | |
| import xml.etree.ElementTree as ET | |
| line_threshold = 73.0 | |
| branch_threshold = 71.0 | |
| matches = glob.glob("TestResults/**/coverage.cobertura.xml", recursive=True) | |
| if not matches: | |
| print("coverage.cobertura.xml was not found.", file=sys.stderr) | |
| sys.exit(1) | |
| root = ET.parse(matches[0]).getroot() | |
| line_rate = float(root.attrib["line-rate"]) * 100.0 | |
| branch_rate = float(root.attrib["branch-rate"]) * 100.0 | |
| print(f"Total line coverage : {line_rate:.2f}% (threshold {line_threshold:.2f}%)") | |
| print(f"Total branch coverage: {branch_rate:.2f}% (threshold {branch_threshold:.2f}%)") | |
| failures = [] | |
| if line_rate < line_threshold: | |
| failures.append(f"line coverage {line_rate:.2f}% < {line_threshold:.2f}%") | |
| if branch_rate < branch_threshold: | |
| failures.append(f"branch coverage {branch_rate:.2f}% < {branch_threshold:.2f}%") | |
| if failures: | |
| print("Coverage threshold check failed:", file=sys.stderr) | |
| for failure in failures: | |
| print(f" - {failure}", file=sys.stderr) | |
| sys.exit(1) | |
| PY | |
| - name: Upload test and coverage artifacts | |
| if: ${{ always() && hashFiles('FolderDiffIL4DotNet.Tests/FolderDiffIL4DotNet.Tests.csproj') != '' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: TestAndCoverage | |
| if-no-files-found: warn | |
| path: | | |
| TestResults/**/*.trx | |
| TestResults/**/coverage.cobertura.xml | |
| CoverageReport/** | |
| - name: Upload documentation artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: DocumentationSite | |
| path: _site/** | |
| - name: Publish | |
| run: dotnet publish FolderDiffIL4DotNet.csproj --configuration Release --no-build --output publish | |
| - name: Remove debugging symbols | |
| run: find publish -name '*.pdb' -delete | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: FolderDiffIL4DotNet | |
| path: publish/** | |
| test-windows: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| global-json-file: global.json | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~\AppData\Local\NuGet\packages | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget- | |
| - name: Restore dependencies | |
| run: dotnet restore FolderDiffIL4DotNet.sln | |
| - name: Build | |
| run: dotnet build FolderDiffIL4DotNet.sln --configuration Release --no-restore | |
| - name: Install real disassembler for E2E tests | |
| run: dotnet tool install --global dotnet-ildasm | |
| env: | |
| DOTNET_ROLL_FORWARD: Major | |
| - name: Test | |
| run: dotnet test FolderDiffIL4DotNet.Tests/FolderDiffIL4DotNet.Tests.csproj --configuration Release --no-build --nologo | |
| env: | |
| DOTNET_ROLL_FORWARD: Major |