Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update build on dotnet to use release artifacts #158

Merged
merged 22 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
146 changes: 45 additions & 101 deletions .github/workflows/publish-dotnet.yaml
Original file line number Diff line number Diff line change
@@ -1,135 +1,79 @@
---
name: .NET Publish

name: Publish .NET
on:
workflow_dispatch:
inputs:
version:
description: What version number would you like to use? The version number should be **without** a leading `v`, e.g. `5.7.1` or `6.2.4`.
required: true

jobs:
# TODO: Consider making this its own workflow to be reused by other workflows.
build-binaries:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
rid: linux-x64
output: libyggdrasilffi.so
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
rid: linux-arm64
output: libyggdrasilffi.so
- os: windows-latest
target: x86_64-pc-windows-gnu
rid: win-x64
output: yggdrasilffi.dll
- os: windows-latest
target: aarch64-pc-windows-msvc
rid: win-arm64
output: yggdrasilffi.dll
- os: macos-latest
target: x86_64-apple-darwin
rid: osx-x64
output: libyggdrasilffi.dylib
- os: macos-latest
target: aarch64-apple-darwin
rid: osx-arm64
output: libyggdrasilffi.dylib

steps:
- uses: actions/checkout@v4

- name: Install dependencies for aarch64-unknown-linux-gnu
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu

- name: Configure cargo for cross-compilation
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
mkdir -p .cargo
echo '[target.aarch64-unknown-linux-gnu]' >> .cargo/config
echo 'linker = "aarch64-linux-gnu-gcc"' >> .cargo/config

- name: Install rust
run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile default
rustup target add ${{ matrix.target }}
rustup show

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Build yggdrasilffi
run: |
cargo build -p yggdrasilffi --release --target ${{ matrix.target }}

- name: Upload yggdrasilffi binary
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.rid }}
path: target/${{ matrix.target }}/release/${{ matrix.output }}

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

steps:
- uses: actions/checkout@v4

- name: Download yggdrasilffi binaries
run: |
for rid in linux-x64 linux-arm64 win-x64 win-arm64 osx-x64 osx-arm64; do
mkdir -p dotnet-engine/runtimes/${rid}/native
echo "Downloading artifact for $rid"
if ! gh run download --name $rid --dir dotnet-engine/runtimes/${rid}/native; then
echo "Failed to download artifact for $rid, continuing..."
fi
done
env:
GH_TOKEN: ${{ github.token }}

- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'

- name: Restore dependencies
- name: Extract Yggdrasil Core Version
id: extract_ffi_version
run: |
cd dotnet-engine
dotnet restore dotnet-engine.sln
sudo apt-get install -y xmlstarlet
cd dotnet-engine/Yggdrasil.Engine
CORE_VERSION=$(xmlstarlet sel -t -v "/Project/PropertyGroup/YggdrasilCoreVersion" -n Yggdrasil.Engine.csproj)
echo "FFI Library Version: $CORE_VERSION"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dirty little cheat to pull the version property for Ygg out the raw XML, because apparently msbuild doesn't give you an option to do that from the command line #sad

echo "CORE_VERSION=$CORE_VERSION" >> $GITHUB_ENV

- name: Set version
- name: Download and Organize Binaries
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd dotnet-engine
version=${{ github.event.inputs.version }}
sed -i "s/<Version>.*<\/Version>/<Version>$version<\/Version>/" Yggdrasil.Engine/Yggdrasil.Engine.csproj
binaries=("libyggdrasilffi_aarch64.so dotnet-engine/runtimes/linux-aarch64/native libyggdrasilffi.so"
"libyggdrasilffi_arm64.so dotnet-engine/runtimes/linux-arm64/native libyggdrasilffi.so"
"libyggdrasilffi_x86_64.so dotnet-engine/runtimes/linux-x64/native libyggdrasilffi.so"
"libyggdrasilffi_arm64.dll dotnet-engine/runtimes/win-arm64/native yggdrasilffi.dll"
"libyggdrasilffi_x86_64.dll dotnet-engine/runtimes/win-x64/native yggdrasilffi.dll"
"libyggdrasilffi_arm64.dylib dotnet-engine/runtimes/osx-arm64/native libyggdrasilffi.dylib"
"libyggdrasilffi_x86_64.dylib dotnet-engine/runtimes/osx-x64/native libyggdrasilffi.dylib")

for binary in "${binaries[@]}"; do
# Split each item into source (release name) and target path
src_name=$(echo "$binary" | awk '{print $1}')
target_path=$(echo "$binary" | awk '{print $2}')
binary_name=$(echo "$binary" | awk '{print $3}')

echo "Downloading $src_name to $target_path..."

mkdir -p "$target_path"

curl -L -o "$target_path/$binary_name" \
-H "Authorization: token $GITHUB_TOKEN" \
"https://github.com/${{ github.repository }}/releases/download/unleash-yggdrasil-v${CORE_VERSION}/${src_name}"

echo "Downloaded from https://github.com/${{ github.repository }}/releases/download/unleash-yggdrasil-v${CORE_VERSION}/${src_name}"

if [ -f "$target_path/$binary_name" ]; then
echo "$src_name downloaded successfully to $target_path."
else
echo "Error: $src_name could not be downloaded to $target_path."
exit 1
fi
ls -l "$target_path"
done
echo "Downloaded binaries"

- name: Build
run: |
cd dotnet-engine
dotnet restore dotnet-engine.sln
dotnet build dotnet-engine.sln -c Release --no-restore

- name: Pack
run: |
cd dotnet-engine
dotnet pack dotnet-engine.sln -c Release --no-build --no-restore

- name: Check package size
run: |
cd dotnet-engine
ls -lh Yggdrasil.Engine/bin/Release/*nupkg

- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: yggdrasil-nuget
path: dotnet-engine/Yggdrasil.Engine/bin/Release/*nupkg

- name: Publish package
run: |
cd dotnet-engine
Expand Down
3 changes: 2 additions & 1 deletion dotnet-engine/Yggdrasil.Engine/Yggdrasil.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Unleash.Yggdrasil</PackageId>
<Version>1.0.0-beta.1</Version>
<Version>1.0.0-beta.8</Version>
<YggdrasilCoreVersion>0.14.0</YggdrasilCoreVersion>
<Company>Bricks Software AS</Company>
<Authors>Unleash</Authors>
<IncludeSymbols>True</IncludeSymbols>
Expand Down
Loading