-
Notifications
You must be signed in to change notification settings - Fork 1
296 lines (257 loc) · 10.8 KB
/
cli-packages.yml
File metadata and controls
296 lines (257 loc) · 10.8 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
name: CLI NuGet Packages
on:
push:
tags-ignore:
- 'v*'
pull_request:
workflow_dispatch:
inputs:
dry-run:
description: Build and package only; skip publish/release actions.
required: false
default: true
type: boolean
permissions:
contents: read
env:
DOTNET_NOLOGO: true
CARGO_TERM_COLOR: always
jobs:
rust-cli:
name: Rust CLI (${{ matrix.rid }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- rid: linux-x64
os: ubuntu-latest
rust-target: x86_64-unknown-linux-gnu
- rid: linux-arm64
os: ubuntu-latest
rust-target: aarch64-unknown-linux-gnu
- rid: win-x64
os: windows-latest
rust-target: x86_64-pc-windows-msvc
- rid: win-arm64
os: windows-latest
rust-target: aarch64-pc-windows-msvc
- rid: osx-x64
os: macos-14
rust-target: x86_64-apple-darwin
- rid: osx-arm64
os: macos-14
rust-target: aarch64-apple-darwin
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Rust toolchain
shell: pwsh
run: |
rustup toolchain install stable --profile minimal --target "${{ matrix.rust-target }}"
rustup default stable
- name: Install Linux ARM64 linker
if: matrix.rid == 'linux-arm64'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Configure static MSVC runtime
if: contains(matrix.rust-target, 'windows-msvc')
shell: pwsh
run: |
"RUSTFLAGS=-C target-feature=+crt-static" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Build and stage Rust CLI
shell: pwsh
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
run: |
pwsh -NoLogo -NoProfile -File (Resolve-Path 'scripts\Build-CliNativeNuGetPackages.ps1') `
-Package Rust `
-RustRuntimeIdentifiers '${{ matrix.rid }}' `
-NoPack `
-Clean
- name: Upload Rust CLI artifact
uses: actions/upload-artifact@v7
with:
name: rust-cli-${{ matrix.rid }}
path: artifacts/cli/rust/${{ matrix.rid }}/*
if-no-files-found: error
dotnet-cli:
name: .NET NativeAOT CLI (${{ matrix.rid }})
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
rid:
- win-x64
- win-arm64
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Build and stage .NET NativeAOT CLI
shell: pwsh
run: |
pwsh -NoLogo -NoProfile -File (Resolve-Path 'scripts\Build-CliNativeNuGetPackages.ps1') `
-Package DotNet `
-DotNetRuntimeIdentifiers '${{ matrix.rid }}' `
-NoPack `
-Clean
- name: Upload .NET CLI artifact
uses: actions/upload-artifact@v7
with:
name: dotnet-cli-${{ matrix.rid }}
path: artifacts/cli/dotnet-nativeaot/${{ matrix.rid }}/*
if-no-files-found: error
package:
name: Pack and smoke test
runs-on: ubuntu-latest
needs:
- rust-cli
- dotnet-cli
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Download CLI artifacts
uses: actions/download-artifact@v8
with:
path: artifacts/download
- name: Arrange staged artifacts
shell: pwsh
run: |
$Mappings = @{
'rust-cli-linux-x64' = 'artifacts/cli/rust/linux-x64'
'rust-cli-linux-arm64' = 'artifacts/cli/rust/linux-arm64'
'rust-cli-win-x64' = 'artifacts/cli/rust/win-x64'
'rust-cli-win-arm64' = 'artifacts/cli/rust/win-arm64'
'rust-cli-osx-x64' = 'artifacts/cli/rust/osx-x64'
'rust-cli-osx-arm64' = 'artifacts/cli/rust/osx-arm64'
'dotnet-cli-win-x64' = 'artifacts/cli/dotnet-nativeaot/win-x64'
'dotnet-cli-win-arm64' = 'artifacts/cli/dotnet-nativeaot/win-arm64'
}
foreach ($mapping in $Mappings.GetEnumerator()) {
$source = Join-Path 'artifacts/download' $mapping.Key
if (-not (Test-Path -Path $source)) {
throw "Downloaded artifact directory not found: $source"
}
New-Item -Path $mapping.Value -ItemType Directory -Force | Out-Null
Copy-Item -Path (Join-Path $source '*') -Destination $mapping.Value -Recurse -Force
}
- name: Pack CLI NuGet packages
shell: pwsh
run: |
pwsh -NoLogo -NoProfile -File (Resolve-Path 'scripts\Build-CliNativeNuGetPackages.ps1') -NoBuild -Clean:$false
- name: Smoke test PackageReference copy targets
shell: pwsh
run: |
$packageSource = (Resolve-Path 'artifacts/cli-nuget').Path
$smokeRoot = Join-Path $env:RUNNER_TEMP 'pinget-cli-package-smoke'
$env:NUGET_PACKAGES = Join-Path $env:RUNNER_TEMP 'pinget-cli-package-smoke-nuget-cache'
New-Item -Path $smokeRoot -ItemType Directory -Force | Out-Null
New-Item -Path $env:NUGET_PACKAGES -ItemType Directory -Force | Out-Null
$rustPackage = Get-ChildItem -Path $packageSource -Filter 'Devolutions.Pinget.Cli.Rust.*.nupkg' | Select-Object -First 1
$dotNetPackage = Get-ChildItem -Path $packageSource -Filter 'Devolutions.Pinget.Cli.DotNet.*.nupkg' | Select-Object -First 1
if (($null -eq $rustPackage) -or ($null -eq $dotNetPackage)) {
throw 'Smoke test packages were not found.'
}
$rustVersion = $rustPackage.BaseName.Substring('Devolutions.Pinget.Cli.Rust.'.Length)
$dotNetVersion = $dotNetPackage.BaseName.Substring('Devolutions.Pinget.Cli.DotNet.'.Length)
dotnet new console --framework net10.0 --output $smokeRoot
if ($LASTEXITCODE -ne 0) { throw 'Smoke project creation failed.' }
$projectPath = Join-Path $smokeRoot 'pinget-cli-package-smoke.csproj'
$project = Get-Content -Path $projectPath -Raw
$project = $project -replace '</Project>', @"
<PropertyGroup>
<DevolutionsPingetRustCliWindowsOutputName>pinget-rust.exe</DevolutionsPingetRustCliWindowsOutputName>
<DevolutionsPingetDotNetCliWindowsOutputName>pinget-dotnet.exe</DevolutionsPingetDotNetCliWindowsOutputName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Devolutions.Pinget.Cli.Rust" Version="$rustVersion" />
<PackageReference Include="Devolutions.Pinget.Cli.DotNet" Version="$dotNetVersion" />
</ItemGroup>
</Project>
"@
Set-Content -Path $projectPath -Value $project -Encoding utf8
$nugetConfig = Join-Path $smokeRoot 'NuGet.Config'
@"
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="local" value="$packageSource" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
"@ | Set-Content -Path $nugetConfig -Encoding utf8
dotnet build $projectPath --configfile $nugetConfig
if ($LASTEXITCODE -ne 0) { throw 'Smoke project build failed.' }
$expectedFiles = @(
'bin/Debug/net10.0/runtimes/win-x64/native/pinget.exe',
'bin/Debug/net10.0/runtimes/win-x64/native/pinget-rust.exe',
'bin/Debug/net10.0/runtimes/win-x64/native/pinget-dotnet.exe',
'bin/Debug/net10.0/runtimes/win-x64/native/e_sqlite3.dll',
'bin/Debug/net10.0/runtimes/linux-x64/native/pinget'
)
foreach ($relativePath in $expectedFiles) {
$path = Join-Path $smokeRoot $relativePath
if (-not (Test-Path -Path $path -PathType Leaf)) {
throw "Expected smoke output file was not found: $path"
}
}
- name: Smoke test dotnet tool package
shell: pwsh
run: |
$packageSource = (Resolve-Path 'artifacts/cli-nuget').Path
$toolPackage = Get-ChildItem -Path $packageSource -Filter 'Devolutions.Pinget.Tool.*.nupkg' | Select-Object -First 1
if ($null -eq $toolPackage) {
throw 'Devolutions.Pinget.Tool package was not found.'
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [System.IO.Compression.ZipFile]::OpenRead($toolPackage.FullName)
try {
$entries = @($archive.Entries | ForEach-Object { $_.FullName })
$nuspecEntry = $archive.Entries | Where-Object { $_.FullName -match '\.nuspec$' } | Select-Object -First 1
if ($null -eq $nuspecEntry) {
throw "Unable to find nuspec entry in $($toolPackage.Name)."
}
$reader = [System.IO.StreamReader]::new($nuspecEntry.Open())
try {
$nuspec = $reader.ReadToEnd()
}
finally {
$reader.Dispose()
}
if ($nuspec -notmatch '<packageType name="DotnetTool"') {
throw "Expected DotnetTool package type in $($toolPackage.Name)."
}
$ridSpecificEntries = @($entries | Where-Object { $_ -match '^runtimes/' -or $_ -match '^tools/[^/]+/(win|linux|osx)-' })
if ($ridSpecificEntries.Count -gt 0) {
throw "Framework-dependent tool package contains RID-specific entries: $($ridSpecificEntries -join ', ')"
}
}
finally {
$archive.Dispose()
}
$toolVersion = $toolPackage.BaseName.Substring('Devolutions.Pinget.Tool.'.Length)
$toolPath = Join-Path $env:RUNNER_TEMP 'pinget-dotnet-tool'
Remove-Item -Path $toolPath -Recurse -Force -ErrorAction SilentlyContinue
New-Item -Path $toolPath -ItemType Directory -Force | Out-Null
dotnet tool install --tool-path $toolPath Devolutions.Pinget.Tool --add-source $packageSource --version $toolVersion
if ($LASTEXITCODE -ne 0) { throw 'dotnet tool install failed.' }
$toolCommand = Join-Path $toolPath 'pinget'
& $toolCommand --help
if ($LASTEXITCODE -ne 0) { throw 'dotnet tool smoke test failed.' }
- name: Upload CLI NuGet packages
uses: actions/upload-artifact@v7
with:
name: cli-nuget
path: artifacts/cli-nuget/*.nupkg
if-no-files-found: error