-
Notifications
You must be signed in to change notification settings - Fork 1
145 lines (123 loc) · 5.26 KB
/
ci-cd.yml
File metadata and controls
145 lines (123 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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