|
| 1 | +name: Build NetCord.Natives (Linux/MacOS, Nix) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + GenerateBinLog: |
| 8 | + type: boolean |
| 9 | + default: false |
| 10 | + push: |
| 11 | + paths: |
| 12 | + - 'NetCord.Natives/**' |
| 13 | + - 'Tests/NetCord.Natives.Tests/**' |
| 14 | + - '.github/workflows/build-natives-nix.yml' |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-natives-nix: |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - rid: osx-x64 |
| 23 | + runs-on: macos-15-intel |
| 24 | + vcpkg-os-target: osx |
| 25 | + vcpkg-platform-target: x64 |
| 26 | + - rid: osx-arm64 |
| 27 | + runs-on: macos-15 |
| 28 | + vcpkg-os-target: osx |
| 29 | + vcpkg-platform-target: arm64 |
| 30 | + - rid: linux-x64 |
| 31 | + runs-on: ubuntu-latest |
| 32 | + vcpkg-os-target: linux |
| 33 | + vcpkg-platform-target: x64 |
| 34 | + - rid: linux-arm64 |
| 35 | + runs-on: ubuntu-24.04-arm |
| 36 | + vcpkg-os-target: linux |
| 37 | + vcpkg-platform-target: arm64 |
| 38 | + |
| 39 | + runs-on: ${{ matrix.runs-on }} |
| 40 | + env: |
| 41 | + CI: true |
| 42 | + VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/.vcpkg-cache,readwrite |
| 43 | + VCPKG_DOWNLOADS: ${{ github.workspace }}/.vcpkg-downloads |
| 44 | + VcpkgOSTarget: ${{ matrix.vcpkg-os-target }} |
| 45 | + VcpkgPlatformTarget: ${{ matrix.vcpkg-platform-target }} |
| 46 | + Configuration: Release |
| 47 | + RuntimeIdentifier: ${{ matrix.rid }} |
| 48 | + DotnetVerbose: minimal |
| 49 | + GenerateBinLog: ${{ github.event.inputs.GenerateBinLog || inputs.GenerateBinLog || false }} |
| 50 | + |
| 51 | + steps: |
| 52 | + - name: Checkout |
| 53 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 54 | + with: |
| 55 | + fetch-depth: 0 |
| 56 | + filter: tree:0 |
| 57 | + |
| 58 | + - name: Restore vcpkg cache |
| 59 | + uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 60 | + with: |
| 61 | + path: | |
| 62 | + .vcpkg-cache |
| 63 | + .vcpkg-downloads |
| 64 | + key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-${{ hashFiles('NetCord.Natives/vcpkg.json', 'NetCord.Natives/natives-ports/**') }} |
| 65 | + restore-keys: | |
| 66 | + vcpkg-${{ runner.os }}-${{ matrix.rid }}- |
| 67 | + vcpkg-${{ runner.os }}- |
| 68 | +
|
| 69 | + - name: Install Nix |
| 70 | + uses: cachix/install-nix-action@8aa03977d8d733052d78f4e008a241fd1dbf36b3 # v31.10.6 |
| 71 | + |
| 72 | + - name: Setup vcpkg (non-Windows, Nix) |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + cat > bootstrap-vcpkg.sh <<'EOF' |
| 76 | + #!/usr/bin/env bash |
| 77 | + set -euo pipefail |
| 78 | + mkdir -p "${VCPKG_BINARY_SOURCES#*,}" |
| 79 | + mkdir -p "${VCPKG_DOWNLOADS}" |
| 80 | + vcpkgRoot="${GITHUB_WORKSPACE}/NetCord.Natives/vcpkg" |
| 81 | + echo "Bootstrapping vcpkg from: $vcpkgRoot" |
| 82 | + "$vcpkgRoot/bootstrap-vcpkg.sh" -disableMetrics |
| 83 | + echo "VCPKG_ROOT=$vcpkgRoot" >> "$GITHUB_ENV" |
| 84 | + EOF |
| 85 | +
|
| 86 | + chmod +x bootstrap-vcpkg.sh |
| 87 | + nix-shell --run ./bootstrap-vcpkg.sh |
| 88 | + rm -f bootstrap-vcpkg.sh |
| 89 | +
|
| 90 | + - name: Setup dev shell |
| 91 | + shell: &dev-shell 'nix develop -c bash -eo pipefail {0}' |
| 92 | + run: 'true' |
| 93 | + |
| 94 | + - name: Restore |
| 95 | + shell: *dev-shell |
| 96 | + run: | |
| 97 | + dotnet restore Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj -v ${{ env.DotnetVerbose }} ${{ env.GenerateBinLog == 'true' && '-bl:restore.binlog' || '' }} |
| 98 | +
|
| 99 | + - name: Build natives projects for ${{ matrix.rid }} |
| 100 | + shell: *dev-shell |
| 101 | + run: > |
| 102 | + dotnet build Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj --no-restore -v ${{ env.DotnetVerbose }} |
| 103 | + ${{ env.GenerateBinLog == 'true' && '-bl:build.binlog' || '' }} |
| 104 | + -p:AppendNativeAotAppProps="RuntimeIdentifier=${{ env.RuntimeIdentifier }}" |
| 105 | + -p:GeneratePackageOnBuild=false -p:CI=false |
| 106 | +
|
| 107 | + - name: Test natives outputs for ${{ matrix.rid }} |
| 108 | + shell: *dev-shell |
| 109 | + run: > |
| 110 | + dotnet test Tests/NetCord.Natives.Tests/NetCord.Natives.Tests.csproj --no-restore --no-build -v ${{ env.DotnetVerbose }} |
| 111 | + ${{ env.GenerateBinLog == 'true' && '-bl:test.binlog' || '' }} |
| 112 | + --logger "console;verbosity=detailed" |
| 113 | + --logger GitHubActions |
| 114 | +
|
| 115 | + - name: Pack NuGet Package for ${{ matrix.rid }} |
| 116 | + if: ${{ always() }} |
| 117 | + shell: *dev-shell |
| 118 | + run: > |
| 119 | + dotnet pack NetCord.Natives/NetCord.Natives.csproj --no-restore --no-build -v ${{ env.DotnetVerbose }} |
| 120 | + ${{ env.GenerateBinLog == 'true' && '-bl:pack.binlog' || '' }} |
| 121 | + -o NetCord.Natives/bin/${{ matrix.rid }} |
| 122 | + -p:CI=false |
| 123 | +
|
| 124 | + - name: Upload Binary Logs |
| 125 | + if: ${{ env.GenerateBinLog == 'true' && always() }} |
| 126 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 127 | + with: |
| 128 | + name: ${{ matrix.rid }}-binlogs |
| 129 | + path: | |
| 130 | + *.binlog |
| 131 | +
|
| 132 | + - name: Upload NuGet Package Artifact |
| 133 | + if: ${{ always() }} |
| 134 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 135 | + with: |
| 136 | + name: NetCord.Natives.${{ matrix.rid }}.packages |
| 137 | + path: | |
| 138 | + NetCord.Natives/bin/${{ matrix.rid }}/*.nupkg |
| 139 | + NetCord.Natives/bin/${{ matrix.rid }}/*.snupkg |
| 140 | +
|
| 141 | + - name: Save vcpkg cache |
| 142 | + if: ${{ always() }} |
| 143 | + uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 144 | + with: |
| 145 | + path: | |
| 146 | + .vcpkg-cache |
| 147 | + .vcpkg-downloads |
| 148 | + key: vcpkg-${{ runner.os }}-${{ matrix.rid }}-${{ hashFiles('NetCord.Natives/vcpkg.json', 'NetCord.Natives/natives-ports/**') }} |
0 commit comments