Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/actions/setup-vcpkg/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Setup vcpkg
description: Setup vcpkg with fallback to submodule checkout

runs:
using: composite
steps:
- name: Resolve or checkout vcpkg
shell: pwsh
run: |
# Ensure vcpkg cache and downloads directories exist
New-Item -ItemType Directory -Path $env:VCPKG_BINARY_SOURCES.Split(',')[1] -Force | Out-Null
New-Item -ItemType Directory -Path $env:VCPKG_DOWNLOADS -Force | Out-Null

$vcpkgRoot = $env:VCPKG_INSTALLATION_ROOT
if (-not $vcpkgRoot) {
$vcpkgCommand = Get-Command vcpkg -ErrorAction SilentlyContinue
if ($vcpkgCommand) {
$vcpkgRoot = Split-Path -Parent $vcpkgCommand.Source
}
}

if (-not $vcpkgRoot -or -not (Test-Path $vcpkgRoot)) {
Write-Host "vcpkg not found in runner image, checking out from submodule..."
git config --file .gitmodules --get-regexp path | while-object { $_.Split()[-1] | where-object { $_ -match 'vcpkg' } } | ForEach-Object {
git submodule update --init --recursive $_
}
$vcpkgRoot = Join-Path $env:GITHUB_WORKSPACE "vcpkg"
if (-not (Test-Path $vcpkgRoot)) {
Write-Error "vcpkg submodule not found and vcpkg executable not available"
exit 1
}
}

if (Test-Path $vcpkgRoot) {
Write-Host "Bootstrapping vcpkg from: $vcpkgRoot"
if ($IsWindows) {
& "$vcpkgRoot/bootstrap-vcpkg.bat" -disableMetrics
} else {
& "$vcpkgRoot/bootstrap-vcpkg.sh" -disableMetrics
}
}

"VCPKG_ROOT=$vcpkgRoot" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
81 changes: 18 additions & 63 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@ on:
- "[0-9]+.[0-9]+.[0-9]+-*"

jobs:
build-and-publish:
build:
uses: ./.github/workflows/build.yml

publish:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Download Build Artifacts
uses: actions/download-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: NuGet Packages
path: artifacts/pkgs

- name: Download Documentation Artifacts
uses: actions/download-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
fetch-depth: 0
filter: tree:0
name: Documentation Artifacts
path: artifacts/docs

- name: Install Nix
uses: cachix/install-nix-action@8aa03977d8d733052d78f4e008a241fd1dbf36b3 # v31.10.6
Expand All @@ -24,76 +34,21 @@ jobs:
shell: &dev-shell 'nix develop -c bash -eo pipefail {0}'
run: 'true'

- name: Restore dependencies
shell: *dev-shell
run: dotnet restore

- name: Build
shell: *dev-shell
run: dotnet build -c Release --no-restore --warnaserror

- name: Test
shell: *dev-shell
run: dotnet test -c Release --no-build --verbosity normal

- name: Pack Packages
shell: *dev-shell
run: |
dotnet pack NetCord -c Release --no-build
dotnet pack NetCord.Services -c Release --no-build
dotnet pack Hosting/NetCord.Hosting -c Release --no-build
dotnet pack Hosting/NetCord.Hosting.Services -c Release --no-build
dotnet pack Hosting/NetCord.Hosting.AspNetCore -c Release --no-build

- name: Setup docs environment
shell: &docs-shell 'nix develop .#docs -c bash -eo pipefail {0}'
run: 'true'

- name: Build Documentation
shell: *docs-shell
working-directory: Documentation
run: |
npm install
npm run lint
npm run test
npm run build

- name: Publish Packages
shell: *dev-shell
env:
KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push NetCord/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push NetCord.Services/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push Hosting/NetCord.Hosting/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push Hosting/NetCord.Hosting.Services/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push Hosting/NetCord.Hosting.AspNetCore/bin/Release/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push artifacts/pkgs/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate

- name: Deploy Documentation
uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345 # v1.0.0
uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345
with:
username: ${{ secrets.SSH_USERNAME }}
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
rm: true
source: Documentation/_site
source: artifacts/docs
strip_components: 2
target: ~/NetCord/html

- name: Upload Build Artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: Build Artifacts
path: |
NetCord/bin/Release
NetCord.Services/bin/Release
Hosting/NetCord.Hosting/bin/Release
Hosting/NetCord.Hosting.Services/bin/Release
Hosting/NetCord.Hosting.AspNetCore/bin/Release

- name: Upload Documentation Artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: Documentation Artifacts
path: Documentation/_site
164 changes: 164 additions & 0 deletions .github/workflows/build-natives.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: Build, Test, and Package NetCord.Natives

on:
workflow_dispatch:
push:
paths:
- 'NetCord.Natives/**'
- '.github/workflows/build-natives.yml'
tags:
- "[0-9]+.[0-9]+.[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+-*"

jobs:
build-test-natives:
runs-on: ${{ matrix.runs-on }}
env:
CI: true
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/.vcpkg-cache,readwrite
VCPKG_DOWNLOADS: ${{ github.workspace }}/.vcpkg-downloads
VcpkgOSTarget: ${{ matrix.vcpkg-os-target }}
VcpkgPlatformTarget: ${{ matrix.vcpkg-platform-target }}
Configuration: Release
RuntimeIdentifier: ${{ matrix.rid }}
DotnetVerbose: minimal

strategy:
fail-fast: false
matrix:
include:
- rid: win-x64
runs-on: windows-latest
vcpkg-os-target: windows
vcpkg-platform-target: x64
- rid: win-arm64
runs-on: windows-11-arm
vcpkg-os-target: windows
vcpkg-platform-target: arm64
- rid: osx-x64
runs-on: macos-15-intel
vcpkg-os-target: osx
vcpkg-platform-target: x64
- rid: osx-arm64
runs-on: macos-15
vcpkg-os-target: osx
vcpkg-platform-target: arm64
- rid: linux-x64
runs-on: ubuntu-latest
vcpkg-os-target: linux
vcpkg-platform-target: x64
- rid: linux-arm64
runs-on: ubuntu-24.04-arm
vcpkg-os-target: linux
vcpkg-platform-target: arm64

steps:
- name: Checkout
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0

- name: Restore vcpkg cache
uses: actions/cache/restore@v5.0.5
with:
path: |
.vcpkg-cache
.vcpkg-downloads
key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-${{ hashFiles('NetCord.Natives/vcpkg.json', 'NetCord.Natives/natives-ports/**') }}
restore-keys: |
vcpkg-${{ runner.os }}-${{ matrix.rid }}-
vcpkg-${{ runner.os }}-

- name: Setup vcpkg
uses: ./.github/actions/setup-vcpkg

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v5.2.0
with:
global-json-file: global.json

- name: Install native build tools (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
brew update
brew install autoconf automake libtool

- name: Restore
shell: pwsh
run: |
dotnet restore Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj -v normal

- name: Build natives projects for ${{ matrix.rid }}
shell: pwsh
run: > # Building tests will build dependencies including the native libraries
dotnet build Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj --no-restore -v ${{ env.DotnetVerbose }}
-p:AppendNativeAotAppProps="RuntimeIdentifier=${{ env.RuntimeIdentifier }}"
-p:GeneratePackageOnBuild=false

- name: Test natives outputs for ${{ matrix.rid }}
shell: pwsh
run: >
dotnet test Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj --no-restore --no-build -v ${{ env.DotnetVerbose }}
--logger GitHubActions

- name: List built for ${{ matrix.rid }}
if: ${{ always() }}
shell: pwsh
run: |
$rid = '${{ matrix.rid }}'
$tripletBase = '${{ matrix.vcpkg-platform-target }}-${{ matrix.vcpkg-os-target }}'
$suffix = if ($IsWindows) { 'static' } else { 'dynamic' }
$triplets = @("$tripletBase", "$tripletBase-$suffix")

foreach ($variant in @('natives','natives-static')) {
foreach ($triplet in @($triplets)) {
foreach ($folder in @('bin','lib')) {
$path = "NetCord.Natives/bin/$rid/$variant/$triplet/$folder"
if (Test-Path $path) {
Get-ChildItem -Path $path -Recurse
} else {
Write-Host "[Info] Not found: $path"
}
}
}
}

- name: Pack NuGet Package for ${{ matrix.rid }}
shell: pwsh
run: >
dotnet pack NetCord.Natives/NetCord.Natives.csproj --no-restore --no-build -v ${{ env.DotnetVerbose }}
-o NetCord.Natives/bin/${{ matrix.rid }}
-p:CI=false

- name: Upload NuGet Package Artifact
uses: actions/upload-artifact@v7.0.1
with:
name: NetCord.Natives.${{ matrix.rid }}.nupkg
path: NetCord.Natives/bin/${{ matrix.rid }}/*.nupkg

- name: Save vcpkg cache
if: ${{ always() }}
uses: actions/cache/save@v5.0.5
with:
path: |
.vcpkg-cache
.vcpkg-downloads
key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-${{ hashFiles('NetCord.Natives/vcpkg.json', 'NetCord.Natives/natives-ports/**') }}

publish:
needs: [build-test-natives]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Download All NuGet Package Artifacts
uses: actions/download-artifact@v8.0.1
with:
path: artifacts/pkgs
pattern: NetCord.Natives*.nupkg

- name: Publish packages
env:
KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push artifacts/pkgs/*.nupkg -k $KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
25 changes: 15 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build

on:
workflow_call:
pull_request:
branches:
- stable
Expand Down Expand Up @@ -33,15 +34,19 @@ jobs:

- name: Restore dependencies
shell: *dev-shell
run: dotnet restore
run: |
dotnet restore NetCord.slnx
dotnet restore NetCord.Natives.slnx -p:VcpkgRoot=$VCPKG_INSTALLATION_ROOT -p:VcpkgEnabled=false

- name: Build
shell: *dev-shell
run: dotnet build -c Release --no-restore --warnaserror
run: |
dotnet build NetCord.slnx -c Release --no-restore --warnaserror
dotnet build NetCord.Natives.slnx -c Release --no-restore --warnaserror -p:VcpkgRoot=$VCPKG_INSTALLATION_ROOT -p:VcpkgEnabled=false

- name: Test
shell: *dev-shell
run: dotnet test -c Release --no-build --verbosity normal
run: dotnet test NetCord.slnx -c Release --no-build --verbosity normal

- name: Pack Packages
shell: *dev-shell
Expand All @@ -65,16 +70,16 @@ jobs:
npm run test
npm run build

- name: Upload Build Artifacts
- name: Upload NuGet Package Artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: Build Artifacts
name: NuGet Packages
path: |
NetCord/bin/Release
NetCord.Services/bin/Release
Hosting/NetCord.Hosting/bin/Release
Hosting/NetCord.Hosting.Services/bin/Release
Hosting/NetCord.Hosting.AspNetCore/bin/Release
NetCord/bin/Release/*.nupkg
NetCord.Services/bin/Release/*.nupkg
Hosting/NetCord.Hosting/bin/Release/*.nupkg
Hosting/NetCord.Hosting.Services/bin/Release/*.nupkg
Hosting/NetCord.Hosting.AspNetCore/bin/Release/*.nupkg
Comment thread
ha-ves marked this conversation as resolved.
Outdated

- name: Upload Documentation Artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "NetCord.Natives/vcpkg"]
path = NetCord.Natives/vcpkg
url = https://github.com/microsoft/vcpkg.git
Loading