-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (204 loc) · 7.68 KB
/
ci.yml
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: CI/CD
on:
workflow_dispatch:
inputs:
os:
description: 'Matrix or single OS'
type: choice
default: 'matrix'
options:
- matrix
- windows-latest
- ubuntu-latest
- macos-latest
fail-fast:
description: 'Fail fast'
type: boolean
skip-tests:
description: 'Skip tests'
type: boolean
deploy:
description: 'Deploy packages'
type: boolean
release:
description: 'Create GitHub release'
type: boolean
push:
branches: master
pull_request:
branches: master
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: pwsh
env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
Prepare:
runs-on: ubuntu-latest
steps:
- name: Prepare Build matrix
id: prep
run: |
$os = "[""windows-latest"", ""ubuntu-latest"", ""macos-latest""]"
if ($${{ github.event.inputs.os != 'matrix' && github.event.inputs.os != '' }}) {
$os = "[""${{ github.event.inputs.os }}""]"
}
echo "os=$os" >>$env:GITHUB_OUTPUT
outputs:
matrix_os: ${{ steps.prep.outputs.os }}
Build:
needs: Prepare
outputs:
deploy: ${{ steps.set_output.outputs.deploy }}
release: ${{ steps.set_output.outputs.release }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ${{ fromJSON(needs.Prepare.outputs.matrix_os) }}
fail-fast: ${{ github.event.inputs.fail-fast == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
show-progress: false
fetch-depth: 0
- name: Setup dotnet (pinned)
uses: actions/setup-dotnet@v4
with:
global-json-file: ./global.json
- name: Build
env:
MSBuildDebugEngine: 1 # Auto-creates binlogs in ./MSBuild_Logs
# Fix incomplete binlogs in MSBuild <=17.3.x. See https://github.com/mawosoft/Mawosoft.Extensions.BenchmarkDotNet/issues/146
MSBUILDLOGTASKINPUTS: 1
MSBUILDTARGETOUTPUTLOGGING: true
MSBUILDLOGIMPORTS: 1
run: |
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
dotnet restore
# Parallel builds causing trouble here
dotnet build ./src/Mawosoft.Extensions.BenchmarkDotNet/Mawosoft.Extensions.BenchmarkDotNet.csproj -c Debug --no-restore
dotnet build ./src/Mawosoft.Extensions.BenchmarkDotNet/Mawosoft.Extensions.BenchmarkDotNet.csproj -c Release --no-restore
dotnet build -c Debug --no-restore
dotnet build -c Release --no-restore
dotnet pack ./src/Mawosoft.Extensions.BenchmarkDotNet/Mawosoft.Extensions.BenchmarkDotNet.csproj -c Release --no-build -o ./Packages
- name: Upload Binlogs
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-Binlogs
path: '**/MSBuild_Logs/*'
- name: Upload Packages
if: ${{ matrix.os == 'ubuntu-latest' || strategy.job-total == 1 }}
uses: actions/upload-artifact@v4
with:
name: Packages
path: ./Packages/
- name: Upload Docs Website
if: ${{ matrix.os == 'ubuntu-latest' || strategy.job-total == 1 }}
uses: actions/upload-artifact@v4
with:
name: DocsWebsite
path: ./docs/_site/
- name: Set Deployment and Release Outputs
id: set_output
if: ${{ (matrix.os == 'ubuntu-latest' || strategy.job-total == 1) && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
run: |
[string] $semver = '^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
$docElement = (select-xml -Path ./Directory.Build.props -XPath "/*").Node
$version = (select-xml -Xml $docElement -XPath "//ns:Version" -Namespace @{ ns = $docElement.NamespaceURI }).Node.InnerText
if ($version -cnotmatch $semver)
{
throw "Invalid Version property."
}
# TODO We might allow tags starting with 'rc' or 'pre' to be published to Nuget.
if ($Matches.prerelease) {
$deploy = "Azure"
$release = ""
}
else {
$deploy = "Nuget"
$release = "v$version"
}
Write-Host "Version: $version, Deploy: $deploy, Release: $release"
echo "deploy=$deploy" >>$env:GITHUB_OUTPUT
echo "release=$release" >>$env:GITHUB_OUTPUT
- name: Test
id: test
if: ${{ github.event.inputs.skip-tests != 'true' }}
run: |
$tfms = @("net8.0")
if ($IsWindows) { $tfms += "net462" }
./build/invokeDotnetTest.ps1 -p ./tests/Mawosoft.Extensions.BenchmarkDotNet.Tests/StableBDN/Mawosoft.Extensions.BenchmarkDotNet.Tests.StableBDN.csproj, ./tests/Mawosoft.Extensions.BenchmarkDotNet.Tests/NightlyBDN/Mawosoft.Extensions.BenchmarkDotNet.Tests.NightlyBDN.csproj -c Debug, Release -f $tfms -v detailed -r ./TestResults -ff:$${{ strategy.fail-fast }}
- name: Upload Test results
if: ${{ always() && steps.test.outcome != 'skipped' }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-Testresults
path: ./TestResults/
Deploy:
needs: Build
if: ${{ needs.Build.outputs.deploy != '' && github.event.inputs.deploy != 'false' }}
runs-on: ubuntu-latest
steps:
- name: Download Packages
uses: actions/download-artifact@v4
with:
name: Packages
path: ./Packages/
- name: Install Azure Credential Provider
run: Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-artifacts-credprovider.ps1) }"
- name: Deploy to Azure
env:
VSS_NUGET_EXTERNAL_FEED_ENDPOINTS: '{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/mawosoft-de/public/_packaging/public/nuget/v3/index.json", "password":"${{ secrets.AZURE_PACKAGE_PAT }}"}]}'
run: dotnet nuget push ./Packages/*.nupkg --skip-duplicate --source https://pkgs.dev.azure.com/mawosoft-de/public/_packaging/public/nuget/v3/index.json --api-key az
Publish:
needs: Build
if: ${{ needs.Build.outputs.deploy == 'Nuget' && github.event.inputs.deploy != 'false' }}
runs-on: ubuntu-latest
steps:
- name: Download Packages
uses: actions/download-artifact@v4
with:
name: Packages
path: ./Packages/
- name: Publish to Nuget
run: dotnet nuget push ./Packages/*.nupkg --skip-duplicate --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
gh-pages:
needs: Build
if: ${{ needs.Build.outputs.release != '' && github.event_name == 'push' }}
runs-on: ubuntu-latest
steps:
- name: Download Docs Website
uses: actions/download-artifact@v4
with:
name: DocsWebsite
path: ./DocsWebsite/
- name: Publish to gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./DocsWebsite/
force_orphan: true
Release:
needs: Build
if: ${{ needs.Build.outputs.release != '' && github.event.inputs.release != 'false' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
show-progress: false
fetch-depth: 1
- name: Create GitHub release
# TODO release notes
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.Build.outputs.release }}
generate_release_notes: false # false is default. Seems to draw from PRs only.