-
Notifications
You must be signed in to change notification settings - Fork 0
242 lines (212 loc) · 8.39 KB
/
Copy pathci.yml
File metadata and controls
242 lines (212 loc) · 8.39 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: CI
on:
push:
branches:
- main
- develop
- feature/**
- release/**
- hotfix/**
tags:
- '*'
pull_request:
branches:
- main
- develop
workflow_dispatch:
inputs:
publish:
description: Pack and publish when the ref is main, release/*, or hotfix/*.
required: true
type: boolean
default: false
dry_run:
description: Pack and verify, but do not push to NuGet (dry run).
required: true
type: boolean
default: true
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DOTNET_VERSION: 10.0.x
SOLUTION: Mammoth.LiteMapper.sln
PACKAGE_OUTPUT: artifacts/packages
jobs:
build-and-test:
name: Build & Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Cache NuGet packages
uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/Directory.Build.props', '**/Directory.Packages.props', 'dotnet-tools.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install Native AOT prerequisites
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev
- name: Restore dotnet tools
run: dotnet tool restore
- name: Determine version
id: gitversion
shell: pwsh
run: |
$version = dotnet gitversion /output json | ConvertFrom-Json
"semver=$($version.SemVer)" >> $env:GITHUB_OUTPUT
"assembly_semver=$($version.AssemblySemVer)" >> $env:GITHUB_OUTPUT
"assembly_file_semver=$($version.AssemblySemFileVer)" >> $env:GITHUB_OUTPUT
"informational_version=$($version.InformationalVersion)" >> $env:GITHUB_OUTPUT
"GitVersion SemVer: $($version.SemVer)"
"GitVersion InformationalVersion: $($version.InformationalVersion)"
- name: Restore
run: dotnet restore ${{ env.SOLUTION }} --verbosity minimal
- name: Build
shell: pwsh
run: |
dotnet build ${{ env.SOLUTION }} -c Release --no-restore `
-p:ContinuousIntegrationBuild=True `
-p:Version=${{ steps.gitversion.outputs.semver }} `
-p:AssemblyVersion=${{ steps.gitversion.outputs.assembly_semver }} `
-p:FileVersion=${{ steps.gitversion.outputs.assembly_file_semver }} `
-p:InformationalVersion=${{ steps.gitversion.outputs.informational_version }}
- name: Test (linux)
if: runner.os == 'Linux'
run: dotnet test ${{ env.SOLUTION }} -c Release --no-build
env:
LITEMAPPER_REQUIRE_NATIVE_AOT: '1'
- name: Test (windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$installPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if (-not $installPath) {
throw "Visual Studio C++ toolchain was not found."
}
$vsDevCmd = Join-Path $installPath "Common7\Tools\VsDevCmd.bat"
cmd /s /c "call `"$vsDevCmd`" -arch=x64 -host_arch=x64 && dotnet test ${{ env.SOLUTION }} -c Release --no-build"
env:
LITEMAPPER_REQUIRE_NATIVE_AOT: '1'
- name: Validate solution paths
shell: pwsh
run: |
dotnet sln Mammoth.LiteMapper.sln list
dotnet sln Mammoth.LiteMapper.slnx list
publish:
name: Pack & Publish
needs: build-and-test
runs-on: windows-latest
if: >
github.event_name != 'pull_request' &&
(
(
github.event_name != 'workflow_dispatch' &&
(
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release/') ||
startsWith(github.ref, 'refs/heads/hotfix/')
)
) ||
(
github.event_name == 'workflow_dispatch' &&
inputs.publish == true &&
(
inputs.dry_run == true ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release/') ||
startsWith(github.ref, 'refs/heads/hotfix/')
)
)
)
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dotnet tools
run: dotnet tool restore
- name: Determine version
id: gitversion
shell: pwsh
run: |
$version = dotnet gitversion /output json | ConvertFrom-Json
$semver = $version.SemVer
if ([string]::IsNullOrWhiteSpace($semver)) {
throw 'GitVersion did not return a SemVer value.'
}
"semver=$semver" >> $env:GITHUB_OUTPUT
"assembly_semver=$($version.AssemblySemVer)" >> $env:GITHUB_OUTPUT
"assembly_file_semver=$($version.AssemblySemFileVer)" >> $env:GITHUB_OUTPUT
"informational_version=$($version.InformationalVersion)" >> $env:GITHUB_OUTPUT
"GitVersion SemVer: $semver"
"GitVersion InformationalVersion: $($version.InformationalVersion)"
- name: Restore
run: dotnet restore ${{ env.SOLUTION }} --verbosity minimal
- name: Pack
shell: pwsh
run: |
$projects = @(
'src/Mammoth.LiteMapper.Abstractions/Mammoth.LiteMapper.Abstractions.csproj',
'src/Mammoth.LiteMapper.Generator/Mammoth.LiteMapper.Generator.csproj',
'src/Mammoth.LiteMapper/Mammoth.LiteMapper.csproj'
)
New-Item -ItemType Directory -Force -Path '${{ env.PACKAGE_OUTPUT }}' | Out-Null
foreach ($project in $projects) {
dotnet pack $project -c Release --no-restore -o '${{ env.PACKAGE_OUTPUT }}' `
/p:PackageVersion=${{ steps.gitversion.outputs.semver }} `
/p:Version=${{ steps.gitversion.outputs.semver }} `
/p:AssemblyVersion=${{ steps.gitversion.outputs.assembly_semver }} `
/p:FileVersion=${{ steps.gitversion.outputs.assembly_file_semver }} `
/p:InformationalVersion=${{ steps.gitversion.outputs.informational_version }} `
/p:ContinuousIntegrationBuild=true
}
$packages = Get-ChildItem -Path '${{ env.PACKAGE_OUTPUT }}' -Filter "Mammoth.LiteMapper*.${{ steps.gitversion.outputs.semver }}.nupkg" |
Where-Object { $_.Name -notlike '*.symbols.nupkg' }
if ($packages.Count -ne 3) {
throw "Expected 3 NuGet packages, found $($packages.Count)."
}
$symbolPackages = Get-ChildItem -Path '${{ env.PACKAGE_OUTPUT }}' -Filter "Mammoth.LiteMapper*.${{ steps.gitversion.outputs.semver }}.snupkg"
if ($symbolPackages.Count -ne 3) {
throw "Expected 3 symbol packages, found $($symbolPackages.Count)."
}
- name: Publish
if: github.event_name != 'workflow_dispatch' || inputs.dry_run == false
shell: pwsh
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
if ([string]::IsNullOrWhiteSpace($env:NUGET_API_KEY)) {
throw 'NUGET_API_KEY secret is required to publish.'
}
Get-ChildItem -Path '${{ env.PACKAGE_OUTPUT }}' -File -Recurse |
Where-Object { $_.Extension -in '.nupkg', '.snupkg' } |
ForEach-Object {
dotnet nuget push $_.FullName --source https://api.nuget.org/v3/index.json --api-key $env:NUGET_API_KEY --skip-duplicate
}
- name: Dry run summary
if: github.event_name == 'workflow_dispatch' && inputs.dry_run == true
shell: pwsh
run: |
Get-ChildItem -Path '${{ env.PACKAGE_OUTPUT }}' -File -Recurse |
Where-Object { $_.Extension -in '.nupkg', '.snupkg' } |
ForEach-Object { "Dry run: would publish $($_.FullName)" }