Skip to content

Commit ccc4d06

Browse files
authored
Update GitHub files for C#/Unity SDK (#2952)
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent c43d8fe commit ccc4d06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+329
-222
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -113,62 +113,6 @@ jobs:
113113
working-directory: crates/bindings-csharp
114114
run: dotnet test -warnaserror
115115

116-
sdk_test:
117-
name: SDK Tests
118-
runs-on: spacetimedb-runner
119-
steps:
120-
- name: Find Git ref
121-
env:
122-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123-
run: |
124-
PR_NUMBER="${{ github.event.inputs.pr_number || null }}"
125-
if test -n "${PR_NUMBER}"; then
126-
GIT_REF="$( gh pr view --repo clockworklabs/SpacetimeDB $PR_NUMBER --json headRefName --jq .headRefName )"
127-
else
128-
GIT_REF="${{ github.ref }}"
129-
fi
130-
echo "GIT_REF=${GIT_REF}" >>"$GITHUB_ENV"
131-
132-
- name: Checkout sources
133-
uses: actions/checkout@v4
134-
with:
135-
ref: ${{ env.GIT_REF }}
136-
137-
- uses: dsherret/rust-toolchain-file@v1
138-
139-
- uses: actions/setup-dotnet@v3
140-
with:
141-
global-json-file: modules/global.json
142-
143-
- name: Create /stdb dir
144-
run: |
145-
sudo mkdir /stdb
146-
sudo chmod 777 /stdb
147-
148-
- name: Checkout C# SDK
149-
uses: actions/checkout@v4
150-
with:
151-
repository: clockworklabs/spacetimedb-csharp-sdk
152-
ref: master
153-
path: spacetimedb-csharp-sdk
154-
155-
- name: Setup NuGet override for C# SDK
156-
working-directory: spacetimedb-csharp-sdk
157-
run: |
158-
dotnet pack ../crates/bindings-csharp/BSATN.Runtime
159-
# The SDK package overrides the following crate for use in their tests.
160-
# Even though it doesn't actually depend on it, we still need to pack it
161-
# so dotnet doesn't complain.
162-
dotnet pack ../crates/bindings-csharp/Runtime
163-
./tools~/write-nuget-config.sh ..
164-
165-
# clear package caches, so we get fresh ones even if version numbers haven't changed
166-
dotnet nuget locals all --clear
167-
168-
- name: Run C# SDK tests
169-
working-directory: spacetimedb-csharp-sdk
170-
run: dotnet test
171-
172116
lints:
173117
name: Lints
174118
runs-on: spacetimedb-runner

sdks/csharp/.github/workflows/test.yml renamed to .github/workflows/csharp-test.yml

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Test Suite
1+
name: C#/Unity - Test Suite
22

33
on:
44
push:
55
branches:
6-
- staging
6+
- master
77
pull_request:
88

99
jobs:
@@ -12,88 +12,52 @@ jobs:
1212
steps:
1313
- name: Checkout repository
1414
uses: actions/checkout@v4
15-
with:
16-
submodules: true
17-
18-
# Grab the SpacetimeDB branch name from the PR description. If it's not found, master will be used instead.
19-
# We'll use this branch name for any integration tests with SpacetimeDB.
20-
21-
- name: Extract SpacetimeDB branch name or PR link from PR description
22-
id: extract-branch
23-
if: github.event_name == 'pull_request'
24-
env:
25-
description: ${{ github.event.pull_request.body }}
26-
run: |
27-
# Check if description contains a branch name or a PR link
28-
branch_or_pr=$(echo "$description" | grep -oP '(?<=SpacetimeDB branch name:\s).+')
29-
echo "Branch or PR found: $branch_or_pr"
30-
31-
if [[ -z "$branch_or_pr" ]]; then
32-
branch="master"
33-
elif [[ "$branch_or_pr" =~ ^https://github.com/.*/pull/[0-9]+$ ]]; then
34-
# If it's a PR link, extract the branch name from the PR
35-
pr_number=$(echo "$branch_or_pr" | grep -oP '[0-9]+$')
36-
branch=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
37-
https://api.github.com/repos/clockworklabs/SpacetimeDB/pulls/$pr_number | jq -r '.head.ref')
38-
else
39-
# It's already a branch name
40-
branch="$branch_or_pr"
41-
fi
42-
43-
echo "branch=$branch" >> $GITHUB_OUTPUT
44-
echo "Final branch name: $branch"
45-
46-
- name: Checkout SpacetimeDB
47-
uses: actions/checkout@v4
48-
id: checkout-stdb
49-
with:
50-
repository: clockworklabs/SpacetimeDB
51-
ref: ${{ steps.extract-branch.outputs.branch }}
52-
path: SpacetimeDB~
5315

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

5618
- name: Setup dotnet
5719
uses: actions/setup-dotnet@v3
5820
with:
59-
global-json-file: SpacetimeDB~/modules/global.json
21+
global-json-file: modules/global.json
6022

6123
- name: Override NuGet packages
6224
run: |
63-
dotnet pack SpacetimeDB~/crates/bindings-csharp/BSATN.Runtime
64-
dotnet pack SpacetimeDB~/crates/bindings-csharp/Runtime
25+
dotnet pack crates/bindings-csharp/BSATN.Runtime
26+
dotnet pack crates/bindings-csharp/Runtime
6527
6628
# Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository
6729
# to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if
6830
# available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages.
6931
# This means that (if version numbers match) we will test the local versions of the C# packages, even
7032
# if they're not pushed to NuGet.
7133
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file.
72-
./tools~/write-nuget-config.sh SpacetimeDB~
34+
cd sdks/csharp
35+
./tools~/write-nuget-config.sh ../..
7336
7437
- name: Run .NET tests
38+
working-directory: sdks/csharp
7539
run: dotnet test -warnaserror
7640

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

8045
# Now, setup the Unity tests.
8146

8247
- name: Patch spacetimedb dependency in Cargo.toml
83-
working-directory: unity-tests~/server-rust
48+
working-directory: demo/Blackholio/server-rust
8449
run: |
85-
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../SpacetimeDB~/crates/bindings\" \}|" Cargo.toml
50+
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../../crates/bindings\" \}|" Cargo.toml
8651
cat Cargo.toml
8752
8853
- name: Install Rust toolchain
8954
uses: dtolnay/rust-toolchain@stable
90-
9155

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

11579
- name: Generate client bindings
116-
working-directory: unity-tests~/server-rust
80+
working-directory: demo/Blackholio/server-rust
11781
run: bash ./generate.sh -y
11882

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

@@ -136,33 +105,34 @@ jobs:
136105
disown
137106
138107
- name: Run regression tests
139-
run: bash tools~/run-regression-tests.sh SpacetimeDB~
108+
run: bash sdks/csharp/tools~/run-regression-tests.sh .
140109

141110
- name: Publish unity-tests module to SpacetimeDB
142-
working-directory: unity-tests~/server-rust
111+
working-directory: demo/Blackholio/server-rust
143112
run: |
144113
spacetime logout && spacetime login --server-issued-login local
145114
bash ./publish.sh
146115
147116
- name: Patch com.clockworklabs.spacetimedbsdk dependency in manifest.json
148-
working-directory: unity-tests~/client-unity/Packages
117+
working-directory: demo/Blackholio/client-unity/Packages
149118
run: |
150119
# Replace the com.clockworklabs.spacetimedbsdk dependency with the current branch.
151-
# TODO: find out why pointing to a local directory doesn't work - is it because Unity CI action uses Docker?
152-
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk.git#${{ github.head_ref }}"' manifest.json
120+
# 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.
121+
# codegen does not work properly).
122+
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "https://github.com/clockworklabs/SpacetimeDB.git?path=sdks/csharp#${{ github.head_ref }}"' manifest.json
153123
cat manifest.json
154124
155125
- uses: actions/cache@v3
156126
with:
157-
path: unity-tests~/client-unity/Library
127+
path: demo/Blackholio/client-unity/Library
158128
key: Unity-${{ github.head_ref }}
159129
restore-keys: Unity-
160130

161131
- name: Run Unity tests
162132
uses: game-ci/unity-test-runner@v4
163133
with:
164134
unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag
165-
projectPath: unity-tests~/client-unity # Path to the Unity project subdirectory
135+
projectPath: demo/Blackholio/client-unity # Path to the Unity project subdirectory
166136
githubToken: ${{ secrets.GITHUB_TOKEN }}
167137
testMode: playmode
168138
useHostNetwork: true

demo/Blackholio/client-unity/Assets/Scripts/autogen/Reducers/CircleDecay.g.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
22
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
33

4+
// This was generated using spacetimedb cli version 1.2.0 (commit ).
5+
46
#nullable enable
57

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

2325
public bool InvokeCircleDecay(ReducerEventContext ctx, Reducer.CircleDecay args)
2426
{
25-
if (OnCircleDecay == null) return false;
27+
if (OnCircleDecay == null)
28+
{
29+
if (InternalOnUnhandledReducerError != null)
30+
{
31+
switch (ctx.Event.Status)
32+
{
33+
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
34+
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
35+
}
36+
}
37+
return false;
38+
}
2639
OnCircleDecay(
2740
ctx,
2841
args.Timer
@@ -37,7 +50,7 @@ public abstract partial class Reducer
3750
[DataContract]
3851
public sealed partial class CircleDecay : Reducer, IReducerArgs
3952
{
40-
[DataMember(Name = "timer")]
53+
[DataMember(Name = "_timer")]
4154
public CircleDecayTimer Timer;
4255

4356
public CircleDecay(CircleDecayTimer Timer)
@@ -50,7 +63,7 @@ public CircleDecay()
5063
this.Timer = new();
5164
}
5265

53-
string IReducerArgs.ReducerName => "CircleDecay";
66+
string IReducerArgs.ReducerName => "circle_decay";
5467
}
5568
}
5669

demo/Blackholio/client-unity/Assets/Scripts/autogen/Reducers/CircleRecombine.g.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
22
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
33

4+
// This was generated using spacetimedb cli version 1.2.0 (commit ).
5+
46
#nullable enable
57

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

2325
public bool InvokeCircleRecombine(ReducerEventContext ctx, Reducer.CircleRecombine args)
2426
{
25-
if (OnCircleRecombine == null) return false;
27+
if (OnCircleRecombine == null)
28+
{
29+
if (InternalOnUnhandledReducerError != null)
30+
{
31+
switch (ctx.Event.Status)
32+
{
33+
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
34+
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
35+
}
36+
}
37+
return false;
38+
}
2639
OnCircleRecombine(
2740
ctx,
2841
args.Timer
@@ -50,7 +63,7 @@ public CircleRecombine()
5063
this.Timer = new();
5164
}
5265

53-
string IReducerArgs.ReducerName => "CircleRecombine";
66+
string IReducerArgs.ReducerName => "circle_recombine";
5467
}
5568
}
5669

demo/Blackholio/client-unity/Assets/Scripts/autogen/Reducers/Connect.g.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
22
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
33

4+
// This was generated using spacetimedb cli version 1.2.0 (commit ).
5+
46
#nullable enable
57

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

1820
public bool InvokeConnect(ReducerEventContext ctx, Reducer.Connect args)
1921
{
20-
if (OnConnect == null) return false;
22+
if (OnConnect == null)
23+
{
24+
if (InternalOnUnhandledReducerError != null)
25+
{
26+
switch (ctx.Event.Status)
27+
{
28+
case Status.Failed(var reason): InternalOnUnhandledReducerError(ctx, new Exception(reason)); break;
29+
case Status.OutOfEnergy(var _): InternalOnUnhandledReducerError(ctx, new Exception("out of energy")); break;
30+
}
31+
}
32+
return false;
33+
}
2134
OnConnect(
2235
ctx
2336
);
@@ -31,7 +44,7 @@ public abstract partial class Reducer
3144
[DataContract]
3245
public sealed partial class Connect : Reducer, IReducerArgs
3346
{
34-
string IReducerArgs.ReducerName => "Connect";
47+
string IReducerArgs.ReducerName => "connect";
3548
}
3649
}
3750
}

0 commit comments

Comments
 (0)