Merge pull request #13 from MichaCo/MichaCo-patch-1 #90
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: CI/CD | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: | |
| - 'v[0-9]*.[0-9]*.[0-9]*' # stable: v1.0.0 | |
| - 'v[0-9]*.[0-9]*.[0-9]*-*' # pre-release: v1.0.0-beta | |
| pull_request: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| permissions: | |
| id-token: write # required for GitHub OIDC | |
| jobs: | |
| build-and-test: | |
| name: Build and Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [windows-latest, ubuntu-latest] | |
| permissions: | |
| contents: read | |
| pull-requests: write # needed for sticky-pull-request-comment | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for SourceLink | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: | | |
| 8.0.x | |
| 10.0.x | |
| # Windows: restore cross-platform + Windows-only projects (CDT.Viz targets Windows only) | |
| # CDT.Comparison.Benchmarks is excluded: its native cmake/cargo build is too slow for CI | |
| - name: Restore dependencies | |
| if: runner.os == 'Windows' | |
| run: | | |
| dotnet restore src/CDT.Core/CDT.Core.csproj | |
| dotnet restore test/CDT.Tests/CDT.Tests.csproj | |
| dotnet restore benchmark/CDT.Benchmarks/CDT.Benchmarks.csproj | |
| dotnet restore viz/CDT.Viz/CDT.Viz.csproj | |
| # Linux: restore only cross-platform projects (CDT.Viz targets Windows only) | |
| - name: Restore dependencies | |
| if: runner.os == 'Linux' | |
| run: | | |
| dotnet restore src/CDT.Core/CDT.Core.csproj | |
| dotnet restore test/CDT.Tests/CDT.Tests.csproj | |
| # Windows: build cross-platform + Windows-only projects | |
| # CDT.Comparison.Benchmarks is excluded: its native cmake/cargo build is too slow for CI | |
| - name: Build | |
| if: runner.os == 'Windows' | |
| run: | | |
| dotnet build --no-restore -c Release src/CDT.Core/CDT.Core.csproj | |
| dotnet build --no-restore -c Release test/CDT.Tests/CDT.Tests.csproj | |
| dotnet build --no-restore -c Release benchmark/CDT.Benchmarks/CDT.Benchmarks.csproj | |
| dotnet build --no-restore -c Release viz/CDT.Viz/CDT.Viz.csproj | |
| # Linux: build only cross-platform projects | |
| - name: Build | |
| if: runner.os == 'Linux' | |
| run: | | |
| dotnet build --no-restore -c Release src/CDT.Core/CDT.Core.csproj | |
| dotnet build --no-restore -c Release test/CDT.Tests/CDT.Tests.csproj | |
| # Windows: test CDT.Tests only (CDT.Comparison.Benchmarks excluded from CI build) | |
| - name: Test | |
| if: runner.os == 'Windows' | |
| run: dotnet test --no-build -c Release --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=${{ github.workspace }}/coverage/coverage.cobertura.xml test/CDT.Tests/CDT.Tests.csproj | |
| # Linux: test only CDT.Tests (CDT.Viz has no tests; benchmark is not a test project) | |
| - name: Test | |
| if: runner.os == 'Linux' | |
| run: dotnet test --no-build -c Release --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=${{ github.workspace }}/coverage/coverage.cobertura.xml test/CDT.Tests/CDT.Tests.csproj | |
| - name: Generate coverage report | |
| uses: danielpalme/ReportGenerator-GitHub-Action@5 | |
| with: | |
| reports: ${{ github.workspace }}/coverage/coverage.cobertura.xml | |
| targetdir: coveragereport | |
| reporttypes: MarkdownSummaryGithub | |
| - name: Write coverage to job summary (Windows) | |
| if: runner.os == 'Windows' | |
| run: Get-Content coveragereport/SummaryGithub.md >> $env:GITHUB_STEP_SUMMARY | |
| shell: pwsh | |
| - name: Add coverage PR comment | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| if: runner.os == 'Windows' && github.event_name == 'pull_request' | |
| with: | |
| recreate: true | |
| path: coveragereport/SummaryGithub.md | |
| - name: Write coverage to job summary (Linux) | |
| if: runner.os == 'Linux' | |
| run: cat coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY | |
| publish: | |
| name: Publish to NuGet | |
| needs: build-and-test | |
| runs-on: windows-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: read | |
| id-token: write # required for OIDC Trusted Publishing | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for SourceLink | |
| # Only CDT.Core is needed for pack; CDT.Comparison.Benchmarks is excluded | |
| - name: Restore dependencies | |
| run: dotnet restore src/CDT.Core/CDT.Core.csproj | |
| - name: Build | |
| run: dotnet build --no-restore -c Release src/CDT.Core/CDT.Core.csproj | |
| - name: Pack | |
| shell: pwsh | |
| run: | | |
| $version = "${{ github.ref_name }}" -replace '^v', '' | |
| dotnet pack src/CDT.Core/CDT.Core.csproj --no-build -c Release -o "${{ github.workspace }}\artifacts" /p:Version=$version | |
| - name: NuGet login | |
| uses: NuGet/login@v1 | |
| id: login | |
| with: | |
| user: MichaConrad | |
| - name: Push to NuGet.org | |
| run: | | |
| dotnet nuget push "${{ github.workspace }}\artifacts\*.nupkg" --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
| shell: pwsh |