Skip to content

Commit 8d1d37c

Browse files
committed
Split Unity and csharp tests into different workflows
1 parent d26f3a1 commit 8d1d37c

2 files changed

Lines changed: 143 additions & 69 deletions

File tree

.github/workflows/csharp-test.yml

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

33
on:
44
push:
@@ -20,7 +20,7 @@ jobs:
2020
--cgroupns=host
2121
# Cancel any previous testsuites running on the same PR and/or ref.
2222
concurrency:
23-
group: unity-test-${{ github.event.pull_request.number || github.ref }}
23+
group: csharp-test-${{ github.event.pull_request.number || github.ref }}
2424
cancel-in-progress: true
2525
timeout-minutes: 30
2626
env:
@@ -59,14 +59,6 @@ jobs:
5959
working-directory: sdks/csharp
6060
run: dotnet format --no-restore --verify-no-changes SpacetimeDB.ClientSDK.sln
6161

62-
# Now, setup the Unity tests.
63-
64-
- name: Patch spacetimedb dependency in Cargo.toml
65-
working-directory: demo/Blackholio/server-rust
66-
run: |
67-
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../../crates/bindings\" \}|" Cargo.toml
68-
cat Cargo.toml
69-
7062
- name: Install Rust toolchain
7163
uses: dtolnay/rust-toolchain@stable
7264

@@ -103,25 +95,6 @@ jobs:
10395
exit 1
10496
}
10597
106-
- name: Generate client bindings
107-
working-directory: demo/Blackholio/server-rust
108-
run: bash ./generate.sh -y
109-
110-
- name: Check for changes
111-
run: |
112-
tools/check-diff.sh demo/Blackholio/client-unity/Assets/Scripts/autogen || {
113-
echo 'Error: Bindings are dirty. Please run `demo/Blackholio/server-rust/generate.sh`.'
114-
exit 1
115-
}
116-
117-
- name: Check Unity meta files
118-
uses: DeNA/unity-meta-check@v3
119-
with:
120-
enable_pr_comment: ${{ github.event_name == 'pull_request' }}
121-
target_path: sdks/csharp
122-
env:
123-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
124-
12598
- name: Start SpacetimeDB
12699
run: |
127100
spacetime start &
@@ -134,43 +107,3 @@ jobs:
134107
echo 'Error: Bindings are dirty. Please run `sdks/csharp/tools~/gen-regression-tests.sh`.'
135108
exit 1
136109
}
137-
138-
- name: Publish unity-tests module to SpacetimeDB
139-
working-directory: demo/Blackholio/server-rust
140-
run: |
141-
spacetime logout && spacetime login --server-issued-login local
142-
bash ./publish.sh
143-
144-
- name: Patch com.clockworklabs.spacetimedbsdk dependency in manifest.json
145-
working-directory: demo/Blackholio/client-unity/Packages
146-
run: |
147-
# Replace the com.clockworklabs.spacetimedbsdk dependency with the current branch.
148-
# 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.
149-
# codegen does not work properly).
150-
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "https://github.com/clockworklabs/SpacetimeDB.git?path=sdks/csharp#${{ github.head_ref }}"' manifest.json
151-
cat manifest.json
152-
153-
- uses: actions/cache@v3
154-
with:
155-
path: demo/Blackholio/client-unity/Library
156-
key: Unity-${{ github.head_ref }}
157-
restore-keys: Unity-
158-
159-
# We need this to support "Docker in Docker"
160-
- name: Start Docker daemon
161-
run: /usr/local/bin/start-docker.sh
162-
- name: Run Unity tests
163-
uses: game-ci/unity-test-runner@v4
164-
with:
165-
unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag
166-
projectPath: demo/Blackholio/client-unity # Path to the Unity project subdirectory
167-
githubToken: ${{ secrets.GITHUB_TOKEN }}
168-
testMode: playmode
169-
useHostNetwork: true
170-
env:
171-
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
172-
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
173-
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
174-
# Skip if this is an external contribution.
175-
# The license secrets will be empty, so the step would fail anyway.
176-
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}

.github/workflows/unity-test.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Unity - Test Suite
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || format('sha-{0}', github.sha) }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
unity-testsuite:
15+
runs-on: spacetimedb-new-runner
16+
container:
17+
image: localhost:5000/spacetimedb-ci:latest
18+
options: >-
19+
--privileged
20+
--cgroupns=host
21+
# Cancel any previous testsuites running on the same PR and/or ref.
22+
concurrency:
23+
group: unity-test-${{ github.event.pull_request.number || github.ref }}
24+
cancel-in-progress: true
25+
timeout-minutes: 30
26+
env:
27+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
28+
steps:
29+
- name: Checkout repository
30+
id: checkout-stdb
31+
uses: actions/checkout@v4
32+
33+
# Run cheap .NET tests first. If those fail, no need to run expensive Unity tests.
34+
35+
- name: Setup dotnet
36+
uses: actions/setup-dotnet@v3
37+
with:
38+
global-json-file: global.json
39+
40+
- name: Override NuGet packages
41+
run: |
42+
dotnet pack crates/bindings-csharp/BSATN.Runtime
43+
dotnet pack crates/bindings-csharp/Runtime
44+
45+
# Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository
46+
# to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if
47+
# available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages.
48+
# This means that (if version numbers match) we will test the local versions of the C# packages, even
49+
# if they're not pushed to NuGet.
50+
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file.
51+
cd sdks/csharp
52+
./tools~/write-nuget-config.sh ../..
53+
54+
# Now, setup the Unity tests.
55+
- name: Patch spacetimedb dependency in Cargo.toml
56+
working-directory: demo/Blackholio/server-rust
57+
run: |
58+
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../../crates/bindings\" \}|" Cargo.toml
59+
cat Cargo.toml
60+
61+
- name: Install Rust toolchain
62+
uses: dtolnay/rust-toolchain@stable
63+
64+
- name: Cache Rust dependencies
65+
uses: Swatinem/rust-cache@v2
66+
with:
67+
workspaces: ${{ github.workspace }}
68+
shared-key: spacetimedb
69+
# Let the main CI job save the cache since it builds the most things
70+
save-if: false
71+
72+
- name: Install SpacetimeDB CLI from the local checkout
73+
run: |
74+
cargo install --force --path crates/cli --locked --message-format=short
75+
cargo install --force --path crates/standalone --locked --message-format=short
76+
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
77+
ln -sf $CARGO_HOME/bin/spacetimedb-cli $CARGO_HOME/bin/spacetime
78+
79+
- name: Generate client bindings
80+
working-directory: demo/Blackholio/server-rust
81+
run: bash ./generate.sh -y
82+
83+
- name: Check for changes
84+
run: |
85+
tools/check-diff.sh demo/Blackholio/client-unity/Assets/Scripts/autogen || {
86+
echo 'Error: Bindings are dirty. Please run `demo/Blackholio/server-rust/generate.sh`.'
87+
exit 1
88+
}
89+
90+
- name: Check Unity meta files
91+
uses: DeNA/unity-meta-check@v3
92+
with:
93+
enable_pr_comment: ${{ github.event_name == 'pull_request' }}
94+
target_path: sdks/csharp
95+
env:
96+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
97+
98+
- name: Start SpacetimeDB
99+
run: |
100+
spacetime start &
101+
disown
102+
103+
- name: Publish unity-tests module to SpacetimeDB
104+
working-directory: demo/Blackholio/server-rust
105+
run: |
106+
spacetime logout && spacetime login --server-issued-login local
107+
bash ./publish.sh
108+
109+
- name: Patch com.clockworklabs.spacetimedbsdk dependency in manifest.json
110+
working-directory: demo/Blackholio/client-unity/Packages
111+
run: |
112+
# Replace the com.clockworklabs.spacetimedbsdk dependency with the current branch.
113+
# 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.
114+
# codegen does not work properly).
115+
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "https://github.com/clockworklabs/SpacetimeDB.git?path=sdks/csharp#${{ github.head_ref }}"' manifest.json
116+
cat manifest.json
117+
118+
- uses: actions/cache@v3
119+
with:
120+
path: demo/Blackholio/client-unity/Library
121+
key: Unity-${{ github.head_ref }}
122+
restore-keys: Unity-
123+
124+
# We need this to support "Docker in Docker"
125+
- name: Start Docker daemon
126+
run: /usr/local/bin/start-docker.sh
127+
- name: Run Unity tests
128+
uses: game-ci/unity-test-runner@v4
129+
with:
130+
unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag
131+
projectPath: demo/Blackholio/client-unity # Path to the Unity project subdirectory
132+
githubToken: ${{ secrets.GITHUB_TOKEN }}
133+
testMode: playmode
134+
useHostNetwork: true
135+
env:
136+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
137+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
138+
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
139+
# Skip if this is an external contribution.
140+
# The license secrets will be empty, so the step would fail anyway.
141+
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}

0 commit comments

Comments
 (0)