11name : Build, Test, and Package NetCord.Natives
22
33on :
4- workflow_dispatch : {}
4+ workflow_dispatch :
55 push :
66 paths :
77 - ' NetCord.Natives/**'
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
0 commit comments