Skip to content

Update GitHub files for C#/Unity SDK #2952

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

Merged
merged 26 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
10c7997
[bfops/csharp-ci]: Update GitHub files for C#/Unity import
bfops Jul 17, 2025
0703cdd
[bfops/csharp-ci]: fix gitmodules?
bfops Jul 17, 2025
4dd6927
[bfops/csharp-ci]: try to use local Blackholio
bfops Jul 17, 2025
a8b2f64
[bfops/csharp-ci]: Merge remote-tracking branch 'origin/bfops/import-…
bfops Jul 17, 2025
6db99ef
[bfops/csharp-ci]: try to fix workspace error
bfops Jul 17, 2025
2459de8
[bfops/csharp-ci]: fix the git diff of Blackholio
bfops Jul 17, 2025
5adaaa0
[bfops/csharp-ci]: fix generated whitespace
bfops Jul 17, 2025
ddb50c0
[bfops/csharp-ci]: fix dangling meta file check
bfops Jul 17, 2025
18d5768
[bfops/csharp-ci]: cleanups
bfops Jul 17, 2025
c82412b
[bfops/csharp-ci]: comment
bfops Jul 17, 2025
254384d
[bfops/csharp-ci]: maybe fix path dependency
bfops Jul 17, 2025
30f6481
[bfops/csharp-ci]: I think fix
bfops Jul 17, 2025
5a63731
[bfops/csharp-ci]: Merge remote-tracking branch 'origin/bfops/import-…
bfops Jul 19, 2025
a65b209
[bfops/csharp-ci]: try adding a dotnet pack?
bfops Jul 19, 2025
b7763fd
[bfops/csharp-ci]: maybe fix?
bfops Jul 19, 2025
b19f09d
[bfops/csharp-ci]: add debug info
bfops Jul 19, 2025
69be039
[bfops/csharp-ci]: debugging changes
bfops Jul 19, 2025
7f24d3c
[bfops/csharp-ci]: more debug info
bfops Jul 19, 2025
7927b64
[bfops/csharp-ci]: more debug info
bfops Jul 19, 2025
2ffd78d
[bfops/csharp-ci]: don't dotnet restore
bfops Jul 19, 2025
b24234b
[bfops/csharp-ci]: use remote repo path again
bfops Jul 19, 2025
87b4643
[bfops/csharp-ci]: empty
bfops Jul 19, 2025
f884cc3
[bfops/csharp-ci]: undo debugging changes
bfops Jul 19, 2025
10543eb
[bfops/csharp-ci]: use ref again
bfops Jul 19, 2025
ec37c6d
[bfops/csharp-ci]: update comment
bfops Jul 19, 2025
7e35126
[bfops/csharp-ci]: fix whitespace
bfops Jul 19, 2025
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
56 changes: 0 additions & 56 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,62 +113,6 @@ jobs:
working-directory: crates/bindings-csharp
run: dotnet test -warnaserror

sdk_test:
name: SDK Tests
runs-on: spacetimedb-runner
steps:
- name: Find Git ref
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ github.event.inputs.pr_number || null }}"
if test -n "${PR_NUMBER}"; then
GIT_REF="$( gh pr view --repo clockworklabs/SpacetimeDB $PR_NUMBER --json headRefName --jq .headRefName )"
else
GIT_REF="${{ github.ref }}"
fi
echo "GIT_REF=${GIT_REF}" >>"$GITHUB_ENV"

- name: Checkout sources
uses: actions/checkout@v4
with:
ref: ${{ env.GIT_REF }}

- uses: dsherret/rust-toolchain-file@v1

- uses: actions/setup-dotnet@v3
with:
global-json-file: modules/global.json

- name: Create /stdb dir
run: |
sudo mkdir /stdb
sudo chmod 777 /stdb

- name: Checkout C# SDK
uses: actions/checkout@v4
with:
repository: clockworklabs/spacetimedb-csharp-sdk
ref: master
path: spacetimedb-csharp-sdk

- name: Setup NuGet override for C# SDK
working-directory: spacetimedb-csharp-sdk
run: |
dotnet pack ../crates/bindings-csharp/BSATN.Runtime
# The SDK package overrides the following crate for use in their tests.
# Even though it doesn't actually depend on it, we still need to pack it
# so dotnet doesn't complain.
dotnet pack ../crates/bindings-csharp/Runtime
./tools~/write-nuget-config.sh ..

# clear package caches, so we get fresh ones even if version numbers haven't changed
dotnet nuget locals all --clear

- name: Run C# SDK tests
working-directory: spacetimedb-csharp-sdk
run: dotnet test

lints:
name: Lints
runs-on: spacetimedb-runner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Test Suite
name: C#/Unity - Test Suite

on:
push:
branches:
- staging
- master
pull_request:

jobs:
Expand All @@ -12,88 +12,52 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

# Grab the SpacetimeDB branch name from the PR description. If it's not found, master will be used instead.
# We'll use this branch name for any integration tests with SpacetimeDB.

- name: Extract SpacetimeDB branch name or PR link from PR description
id: extract-branch
if: github.event_name == 'pull_request'
env:
description: ${{ github.event.pull_request.body }}
run: |
# Check if description contains a branch name or a PR link
branch_or_pr=$(echo "$description" | grep -oP '(?<=SpacetimeDB branch name:\s).+')
echo "Branch or PR found: $branch_or_pr"

if [[ -z "$branch_or_pr" ]]; then
branch="master"
elif [[ "$branch_or_pr" =~ ^https://github.com/.*/pull/[0-9]+$ ]]; then
# If it's a PR link, extract the branch name from the PR
pr_number=$(echo "$branch_or_pr" | grep -oP '[0-9]+$')
branch=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/clockworklabs/SpacetimeDB/pulls/$pr_number | jq -r '.head.ref')
else
# It's already a branch name
branch="$branch_or_pr"
fi

echo "branch=$branch" >> $GITHUB_OUTPUT
echo "Final branch name: $branch"

- name: Checkout SpacetimeDB
uses: actions/checkout@v4
id: checkout-stdb
with:
repository: clockworklabs/SpacetimeDB
ref: ${{ steps.extract-branch.outputs.branch }}
path: SpacetimeDB~

# Run cheap .NET tests first. If those fail, no need to run expensive Unity tests.

- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
global-json-file: SpacetimeDB~/modules/global.json
global-json-file: modules/global.json

- name: Override NuGet packages
run: |
dotnet pack SpacetimeDB~/crates/bindings-csharp/BSATN.Runtime
dotnet pack SpacetimeDB~/crates/bindings-csharp/Runtime
dotnet pack crates/bindings-csharp/BSATN.Runtime
dotnet pack crates/bindings-csharp/Runtime

# Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository
# to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if
# available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages.
# This means that (if version numbers match) we will test the local versions of the C# packages, even
# if they're not pushed to NuGet.
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file.
./tools~/write-nuget-config.sh SpacetimeDB~
cd sdks/csharp
./tools~/write-nuget-config.sh ../..

- name: Run .NET tests
working-directory: sdks/csharp
run: dotnet test -warnaserror

- name: Verify C# formatting
working-directory: sdks/csharp
run: dotnet format --no-restore --verify-no-changes SpacetimeDB.ClientSDK.sln

# Now, setup the Unity tests.

- name: Patch spacetimedb dependency in Cargo.toml
working-directory: unity-tests~/server-rust
working-directory: demo/Blackholio/server-rust
run: |
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../SpacetimeDB~/crates/bindings\" \}|" Cargo.toml
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../../crates/bindings\" \}|" Cargo.toml
cat Cargo.toml

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable


- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
id: cache-rust-deps
with:
workspaces: unity-tests~/server-rust
workspaces: demo/Blackholio/server-rust
key: ${{ steps.checkout-stdb.outputs.commit }}
# Cache Rust deps even if unit tests have failed.
cache-on-failure: true
Expand All @@ -104,21 +68,25 @@ jobs:
# Rebuild only if we didn't get a precise cache hit.
if: steps.cache-rust-deps.outputs.cache-hit == 'false'
run: |
cargo install --force --path SpacetimeDB~/crates/cli --locked --message-format=short
cargo install --force --path SpacetimeDB~/crates/standalone --locked --message-format=short
cargo install --force --path crates/cli --locked --message-format=short
cargo install --force --path crates/standalone --locked --message-format=short
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
ln -sf $HOME/.cargo/bin/spacetimedb-cli $HOME/.cargo/bin/spacetime
env:
# Share the target directory with our local project to avoid rebuilding same SpacetimeDB crates twice.
CARGO_TARGET_DIR: unity-tests~/server-rust/target
CARGO_TARGET_DIR: demo/Blackholio/server-rust/target

- name: Generate client bindings
working-directory: unity-tests~/server-rust
working-directory: demo/Blackholio/server-rust
run: bash ./generate.sh -y

- name: Check for changes
run: |
git diff --exit-code unity-tests~/client-unity/Assets/Scripts/autogen || {
# This was copied from tools/check-diff.sh.
# It's required because `spacetime generate` creates lines with the SpacetimeDB commit
# version, which would make this `git diff` check very brittle if included.
PATTERN='^// This was generated using spacetimedb cli version.*'
git diff --exit-code --ignore-matching-lines="$PATTERN" -- demo/Blackholio/client-unity/Assets/Scripts/autogen || {
echo "Error: Bindings are dirty. Please generate bindings again and commit them to this branch."
exit 1
}
Expand All @@ -127,6 +95,7 @@ jobs:
uses: DeNA/unity-meta-check@v3
with:
enable_pr_comment: ${{ github.event_name == 'pull_request' }}
target_path: sdks/csharp
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

Expand All @@ -136,33 +105,34 @@ jobs:
disown

- name: Run regression tests
run: bash tools~/run-regression-tests.sh SpacetimeDB~
run: bash sdks/csharp/tools~/run-regression-tests.sh .

- name: Publish unity-tests module to SpacetimeDB
working-directory: unity-tests~/server-rust
working-directory: demo/Blackholio/server-rust
run: |
spacetime logout && spacetime login --server-issued-login local
bash ./publish.sh

- name: Patch com.clockworklabs.spacetimedbsdk dependency in manifest.json
working-directory: unity-tests~/client-unity/Packages
working-directory: demo/Blackholio/client-unity/Packages
run: |
# Replace the com.clockworklabs.spacetimedbsdk dependency with the current branch.
# TODO: find out why pointing to a local directory doesn't work - is it because Unity CI action uses Docker?
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk.git#${{ github.head_ref }}"' manifest.json
# Note: Pointing to a local directory does not work, because our earlier steps nuke our meta files, which then causes Unity to not properly respect the DLLs (e.g.
# codegen does not work properly).
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "https://github.com/clockworklabs/SpacetimeDB.git?path=sdks/csharp#${{ github.head_ref }}"' manifest.json
cat manifest.json

- uses: actions/cache@v3
with:
path: unity-tests~/client-unity/Library
path: demo/Blackholio/client-unity/Library
key: Unity-${{ github.head_ref }}
restore-keys: Unity-

- name: Run Unity tests
uses: game-ci/unity-test-runner@v4
with:
unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag
projectPath: unity-tests~/client-unity # Path to the Unity project subdirectory
projectPath: demo/Blackholio/client-unity # Path to the Unity project subdirectory
githubToken: ${{ secrets.GITHUB_TOKEN }}
testMode: playmode
useHostNetwork: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.

// This was generated using spacetimedb cli version 1.2.0 (commit ).

#nullable enable

using System;
Expand All @@ -22,7 +24,18 @@ public void CircleDecay(CircleDecayTimer timer)

public bool InvokeCircleDecay(ReducerEventContext ctx, Reducer.CircleDecay args)
{
if (OnCircleDecay == null) return false;
if (OnCircleDecay == null)
{
if (InternalOnUnhandledReducerError != null)
{
switch (ctx.Event.Status)
{
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
}
}
return false;
}
OnCircleDecay(
ctx,
args.Timer
Expand All @@ -37,7 +50,7 @@ public abstract partial class Reducer
[DataContract]
public sealed partial class CircleDecay : Reducer, IReducerArgs
{
[DataMember(Name = "timer")]
[DataMember(Name = "_timer")]
public CircleDecayTimer Timer;

public CircleDecay(CircleDecayTimer Timer)
Expand All @@ -50,7 +63,7 @@ public CircleDecay()
this.Timer = new();
}

string IReducerArgs.ReducerName => "CircleDecay";
string IReducerArgs.ReducerName => "circle_decay";
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.

// This was generated using spacetimedb cli version 1.2.0 (commit ).

#nullable enable

using System;
Expand All @@ -22,7 +24,18 @@ public void CircleRecombine(CircleRecombineTimer timer)

public bool InvokeCircleRecombine(ReducerEventContext ctx, Reducer.CircleRecombine args)
{
if (OnCircleRecombine == null) return false;
if (OnCircleRecombine == null)
{
if (InternalOnUnhandledReducerError != null)
{
switch (ctx.Event.Status)
{
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
}
}
return false;
}
OnCircleRecombine(
ctx,
args.Timer
Expand Down Expand Up @@ -50,7 +63,7 @@ public CircleRecombine()
this.Timer = new();
}

string IReducerArgs.ReducerName => "CircleRecombine";
string IReducerArgs.ReducerName => "circle_recombine";
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.

// This was generated using spacetimedb cli version 1.2.0 (commit ).

#nullable enable

using System;
Expand All @@ -17,7 +19,18 @@ public sealed partial class RemoteReducers : RemoteBase

public bool InvokeConnect(ReducerEventContext ctx, Reducer.Connect args)
{
if (OnConnect == null) return false;
if (OnConnect == null)
{
if (InternalOnUnhandledReducerError != null)
{
switch (ctx.Event.Status)
{
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
}
}
return false;
}
OnConnect(
ctx
);
Expand All @@ -31,7 +44,7 @@ public abstract partial class Reducer
[DataContract]
public sealed partial class Connect : Reducer, IReducerArgs
{
string IReducerArgs.ReducerName => "Connect";
string IReducerArgs.ReducerName => "connect";
}
}
}
Loading
Loading