Skip to content

Commit ee00a64

Browse files
committed
refactor native build/test pipeline
- add reusable vcpkg setup - pack per-RID native nupkgs - streamline NativeAOT test logging - tighten native linking targets
1 parent 498226a commit ee00a64

12 files changed

Lines changed: 378 additions & 300 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Setup vcpkg
2+
description: Setup vcpkg with fallback to submodule checkout
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Resolve or checkout vcpkg
8+
shell: pwsh
9+
run: |
10+
# Ensure vcpkg cache and downloads directories exist
11+
New-Item -ItemType Directory -Path $env:VCPKG_BINARY_SOURCES.Split(',')[1] -Force | Out-Null
12+
New-Item -ItemType Directory -Path $env:VCPKG_DOWNLOADS -Force | Out-Null
13+
14+
$vcpkgRoot = $env:VCPKG_INSTALLATION_ROOT
15+
if (-not $vcpkgRoot) {
16+
$vcpkgCommand = Get-Command vcpkg -ErrorAction SilentlyContinue
17+
if ($vcpkgCommand) {
18+
$vcpkgRoot = Split-Path -Parent $vcpkgCommand.Source
19+
}
20+
}
21+
22+
if (-not $vcpkgRoot -or -not (Test-Path $vcpkgRoot)) {
23+
Write-Host "vcpkg not found in runner image, checking out from submodule..."
24+
git config --file .gitmodules --get-regexp path | while-object { $_.Split()[-1] | where-object { $_ -match 'vcpkg' } } | ForEach-Object {
25+
git submodule update --init --recursive $_
26+
}
27+
$vcpkgRoot = Join-Path $env:GITHUB_WORKSPACE "vcpkg"
28+
if (-not (Test-Path $vcpkgRoot)) {
29+
Write-Error "vcpkg submodule not found and vcpkg executable not available"
30+
exit 1
31+
}
32+
}
33+
34+
if (Test-Path $vcpkgRoot) {
35+
Write-Host "Bootstrapping vcpkg from: $vcpkgRoot"
36+
if ($IsWindows) {
37+
& "$vcpkgRoot/bootstrap-vcpkg.bat" -disableMetrics
38+
} else {
39+
& "$vcpkgRoot/bootstrap-vcpkg.sh" -disableMetrics
40+
}
41+
}
42+
43+
"VCPKG_ROOT=$vcpkgRoot" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8

.github/workflows/build-and-publish.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
- name: Download Build Artifacts
1919
uses: actions/download-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
2020
with:
21-
name: Build Artifacts
22-
path: artifacts/build
21+
name: NuGet Packages
22+
path: artifacts/pkgs
2323

2424
- name: Download Documentation Artifacts
2525
uses: actions/download-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
@@ -39,11 +39,7 @@ jobs:
3939
env:
4040
KEY: ${{ secrets.NUGET_API_KEY }}
4141
run: |
42-
dotnet nuget push artifacts/build/NetCord/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
43-
dotnet nuget push artifacts/build/NetCord.Services/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
44-
dotnet nuget push artifacts/build/Hosting/NetCord.Hosting/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
45-
dotnet nuget push artifacts/build/Hosting/NetCord.Hosting.Services/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
46-
dotnet nuget push artifacts/build/Hosting/NetCord.Hosting.AspNetCore/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
42+
dotnet nuget push artifacts/pkgs/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
4743
4844
- name: Deploy Documentation
4945
uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345
Lines changed: 59 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Build, Test, and Package NetCord.Natives
22

33
on:
4-
workflow_dispatch: {}
4+
workflow_dispatch:
55
push:
66
paths:
77
- 'NetCord.Natives/**'
@@ -17,6 +17,12 @@ jobs:
1717
CI: true
1818
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/.vcpkg-cache,readwrite
1919
VCPKG_DOWNLOADS: ${{ github.workspace }}/.vcpkg-downloads
20+
VcpkgOSTarget: ${{ matrix.vcpkg-os-target }}
21+
VcpkgPlatformTarget: ${{ matrix.vcpkg-platform-target }}
22+
Configuration: Release
23+
RuntimeIdentifier: ${{ matrix.rid }}
24+
DotnetVerbose: minimal
25+
2026
strategy:
2127
fail-fast: false
2228
matrix:
@@ -26,99 +32,78 @@ jobs:
2632
vcpkg-os-target: windows
2733
vcpkg-platform-target: x64
2834
- rid: win-arm64
29-
runs-on: windows-latest
35+
runs-on: windows-11-arm
3036
vcpkg-os-target: windows
3137
vcpkg-platform-target: arm64
3238
- rid: osx-x64
33-
runs-on: macos-latest
39+
runs-on: macos-15-intel
3440
vcpkg-os-target: osx
3541
vcpkg-platform-target: x64
3642
- rid: osx-arm64
37-
runs-on: macos-latest
43+
runs-on: macos-15
3844
vcpkg-os-target: osx
3945
vcpkg-platform-target: arm64
4046
- rid: linux-x64
4147
runs-on: ubuntu-latest
4248
vcpkg-os-target: linux
4349
vcpkg-platform-target: x64
4450
- rid: linux-arm64
45-
runs-on: ubuntu-latest
51+
runs-on: ubuntu-24.04-arm
4652
vcpkg-os-target: linux
4753
vcpkg-platform-target: arm64
4854

4955
steps:
5056
- name: Checkout
5157
uses: actions/checkout@v6.0.2
58+
with:
59+
fetch-depth: 0
5260

53-
- name: Cache vcpkg installs
54-
uses: actions/cache@v5.0.5
61+
- name: Restore vcpkg cache
62+
uses: actions/cache/restore@v5.0.5
5563
with:
5664
path: |
5765
.vcpkg-cache
5866
.vcpkg-downloads
59-
key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-
60-
${{ hashFiles(
61-
'NetCord.Natives/vcpkg.json',
62-
'NetCord.Natives/natives-ports/**'
63-
) }}
67+
key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-${{ hashFiles('NetCord.Natives/vcpkg.json', 'NetCord.Natives/natives-ports/**') }}
6468
restore-keys: |
6569
vcpkg-${{ runner.os }}-${{ matrix.rid }}-
6670
vcpkg-${{ runner.os }}-
6771
68-
- name: Resolve vcpkg from runner image
69-
shell: pwsh
70-
run: |
71-
# Ensure vcpkg cache and downloads directories exist
72-
New-Item -ItemType Directory -Path $env:VCPKG_BINARY_SOURCES.Split(',')[1] -Force | Out-Null
73-
New-Item -ItemType Directory -Path $env:VCPKG_DOWNLOADS -Force | Out-Null
74-
75-
$vcpkgRoot = $env:VCPKG_INSTALLATION_ROOT
76-
if (-not $vcpkgRoot) {
77-
$vcpkgCommand = Get-Command vcpkg -ErrorAction Stop
78-
$vcpkgRoot = Split-Path -Parent $vcpkgCommand.Source
79-
}
72+
- name: Setup vcpkg
73+
uses: ./.github/actions/setup-vcpkg
8074

81-
if (Test-Path $vcpkgRoot) {
82-
# Bootstrap vcpkg
83-
if ($IsWindows) {
84-
& "$vcpkgRoot/bootstrap-vcpkg.bat" -disableMetrics
85-
} else {
86-
& "$vcpkgRoot/bootstrap-vcpkg.sh" -disableMetrics
87-
}
88-
}
89-
90-
"VCPKG_ROOT=$vcpkgRoot" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
75+
- name: Setup .NET Core SDK
76+
uses: actions/setup-dotnet@v5.2.0
77+
with:
78+
global-json-file: global.json
9179

9280
- name: Install native build tools (macOS)
9381
if: runner.os == 'macOS'
9482
shell: bash
9583
run: |
9684
brew update
97-
brew install autoconf automake libtool pkg-config
98-
99-
- name: Install ARM64 cross-compiler (linux-arm64)
100-
if: matrix.rid == 'linux-arm64'
101-
shell: bash
102-
run: |
103-
sudo apt-get update
104-
sudo apt-get install -yq gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross
85+
brew install autoconf automake libtool
10586
10687
- name: Restore
10788
shell: pwsh
10889
run: |
109-
dotnet restore NetCord.Natives/NetCord.Natives.csproj -p:VcpkgRoot=$env:VCPKG_ROOT -p:VcpkgOSTarget=${{ matrix.vcpkg-os-target }} -p:VcpkgPlatformTarget=${{ matrix.vcpkg-platform-target }}
90+
dotnet restore Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj -v normal
11091
111-
- name: Build native outputs for ${{ matrix.rid }}
92+
- name: Build natives projects for ${{ matrix.rid }}
11293
shell: pwsh
113-
run: |
114-
dotnet build NetCord.Natives/NetCord.Natives.csproj -c Release --no-restore -p:GeneratePackageOnBuild=false -p:VcpkgRoot=$env:VCPKG_ROOT -p:VcpkgOSTarget=${{ matrix.vcpkg-os-target }} -p:VcpkgPlatformTarget=${{ matrix.vcpkg-platform-target }}
94+
run: > # Building tests will build dependencies including the native libraries
95+
dotnet build Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj --no-restore -v ${{ env.DotnetVerbose }}
96+
-p:AppendNativeAotAppProps="RuntimeIdentifier=${{ env.RuntimeIdentifier }}"
97+
-p:GeneratePackageOnBuild=false
11598
116-
- name: Test native outputs for ${{ matrix.rid }}
99+
- name: Test natives outputs for ${{ matrix.rid }}
117100
shell: pwsh
118-
run: |
119-
dotnet test NetCord.Natives.Tests/NetCord.Natives.Tests.csproj -c Release -p:VcpkgRoot=$env:VCPKG_ROOT -p:VcpkgOSTarget=${{ matrix.vcpkg-os-target }} -p:VcpkgPlatformTarget=${{ matrix.vcpkg-platform-target }} --verbosity normal
101+
run: >
102+
dotnet test Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj --no-restore --no-build -v ${{ env.DotnetVerbose }}
103+
--logger GitHubActions
120104
121105
- name: List built for ${{ matrix.rid }}
106+
if: ${{ always() }}
122107
shell: pwsh
123108
run: |
124109
$rid = '${{ matrix.rid }}'
@@ -131,98 +116,49 @@ jobs:
131116
foreach ($folder in @('bin','lib')) {
132117
$path = "NetCord.Natives/bin/$rid/$variant/$triplet/$folder"
133118
if (Test-Path $path) {
134-
Write-Host "Contents of: $path"
135-
Get-ChildItem -Path $path -Recurse -Force | Select-Object FullName, Mode, Length, LastWriteTime
119+
Get-ChildItem -Path $path -Recurse
136120
} else {
137-
Write-Host "[Info]Not found: $path"
121+
Write-Host "[Info] Not found: $path"
138122
}
139123
}
140124
}
141125
}
142126
143-
- name: Upload artifact
144-
uses: actions/upload-artifact@v7.0.1
145-
with:
146-
name: ${{ matrix.rid }}
147-
path: NetCord.Natives/bin/${{ matrix.rid }}
148-
149-
pack-natives:
150-
needs: build-natives
151-
runs-on: ubuntu-latest
152-
env:
153-
CI: true
154-
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/.vcpkg-cache,readwrite
155-
VCPKG_DOWNLOADS: ${{ github.workspace }}/.vcpkg-downloads
156-
VcpkgArtifactsRoot: ${{ github.workspace }}/artifacts
157-
158-
steps:
159-
- name: Checkout
160-
uses: actions/checkout@v6.0.2
161-
162-
- name: Download native artifacts
163-
uses: actions/download-artifact@v8.0.1
164-
with:
165-
path: artifacts
166-
merge-multiple: false
167-
168-
- name: Resolve vcpkg from runner image
169-
shell: pwsh
170-
run: |
171-
# Ensure vcpkg cache and downloads directories exist
172-
New-Item -ItemType Directory -Path $env:VCPKG_BINARY_SOURCES.Split(',')[1] -Force | Out-Null
173-
New-Item -ItemType Directory -Path $env:VCPKG_DOWNLOADS -Force | Out-Null
174-
175-
$vcpkgRoot = $env:VCPKG_INSTALLATION_ROOT
176-
if (-not $vcpkgRoot) {
177-
$vcpkgCommand = Get-Command vcpkg -ErrorAction Stop
178-
$vcpkgRoot = Split-Path -Parent $vcpkgCommand.Source
179-
}
180-
181-
if (Test-Path $vcpkgRoot) {
182-
# Bootstrap vcpkg
183-
if ($IsWindows) {
184-
& "$vcpkgRoot/bootstrap-vcpkg.bat" -disableMetrics
185-
} else {
186-
& "$vcpkgRoot/bootstrap-vcpkg.sh" -disableMetrics
187-
}
188-
}
189-
190-
"VCPKG_ROOT=$vcpkgRoot" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
191-
192-
- name: Restore (required for pack)
127+
- name: Pack NuGet Package for ${{ matrix.rid }}
193128
shell: pwsh
194-
run: |
195-
dotnet restore NetCord.Natives/NetCord.Natives.csproj -p:VcpkgRoot=$env:VCPKG_ROOT -p:VcpkgEnabled=false
129+
run: >
130+
dotnet pack NetCord.Natives/NetCord.Natives.csproj --no-restore --no-build -v ${{ env.DotnetVerbose }}
131+
-o NetCord.Natives/bin/${{ matrix.rid }}
132+
-p:CI=false
196133
197-
- name: Build cross-platform .NET (required for pack)
198-
shell: pwsh
199-
run: |
200-
dotnet build NetCord.Natives/NetCord.Natives.csproj -c Release --no-restore -p:VcpkgRoot=$env:VCPKG_ROOT -p:VcpkgEnabled=false
201-
202-
- name: Pack combined nupkg
203-
shell: pwsh
204-
run: |
205-
dotnet pack NetCord.Natives/NetCord.Natives.csproj -c Release --no-build --no-restore -p:VcpkgRoot=$env:VCPKG_ROOT -p:VcpkgArtifactsRoot=$env:VcpkgArtifactsRoot -o $env:VcpkgArtifactsRoot/package
206-
207-
- name: Upload nupkg
134+
- name: Upload NuGet Package Artifact
208135
uses: actions/upload-artifact@v7.0.1
209136
with:
210-
name: NetCord.Natives.Package
211-
path: artifacts/package/*.nupkg
137+
name: NetCord.Natives.${{ matrix.rid }}.nupkg
138+
path: NetCord.Natives/bin/${{ matrix.rid }}/*.nupkg
139+
140+
- name: Save vcpkg cache
141+
if: ${{ always() }}
142+
uses: actions/cache/save@v5.0.5
143+
with:
144+
path: |
145+
.vcpkg-cache
146+
.vcpkg-downloads
147+
key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-${{ hashFiles('NetCord.Natives/vcpkg.json', 'NetCord.Natives/natives-ports/**') }}
212148

213149
publish:
214-
needs: pack-natives
150+
needs: [build-test-natives]
215151
if: startsWith(github.ref, 'refs/tags/')
216152
runs-on: ubuntu-latest
217153
steps:
218-
- name: Download nupkg
154+
- name: Download All NuGet Package Artifacts
219155
uses: actions/download-artifact@v8.0.1
220156
with:
221-
name: NetCord.Natives.Package
222-
path: artifacts/package
157+
path: artifacts/pkgs
158+
pattern: NetCord.Natives*.nupkg
223159

224-
- name: Publish Package
160+
- name: Publish packages
225161
env:
226162
KEY: ${{ secrets.NUGET_API_KEY }}
227163
run: |
228-
dotnet nuget push artifacts/package/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
164+
dotnet nuget push artifacts/pkgs/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate

.github/workflows/build.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434

3535
- name: Restore dependencies
3636
shell: *dev-shell
37-
run: dotnet restore
37+
run: |
38+
dotnet restore NetCord.slnx
39+
dotnet restore NetCord.Natives.slnx -p:VcpkgRoot=$VCPKG_INSTALLATION_ROOT -p:VcpkgEnabled=false
3840
3941
- name: Build
4042
shell: *dev-shell
@@ -68,16 +70,16 @@ jobs:
6870
npm run test
6971
npm run build
7072
71-
- name: Upload Build Artifacts
73+
- name: Upload NuGet Package Artifacts
7274
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
7375
with:
74-
name: Build Artifacts
76+
name: NuGet Packages
7577
path: |
76-
NetCord/bin/Release
77-
NetCord.Services/bin/Release
78-
Hosting/NetCord.Hosting/bin/Release
79-
Hosting/NetCord.Hosting.Services/bin/Release
80-
Hosting/NetCord.Hosting.AspNetCore/bin/Release
78+
NetCord/bin/Release/*.nupkg
79+
NetCord.Services/bin/Release/*.nupkg
80+
Hosting/NetCord.Hosting/bin/Release/*.nupkg
81+
Hosting/NetCord.Hosting.Services/bin/Release/*.nupkg
82+
Hosting/NetCord.Hosting.AspNetCore/bin/Release/*.nupkg
8183
8284
- name: Upload Documentation Artifacts
8385
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1

0 commit comments

Comments
 (0)