Skip to content

Commit 1d34217

Browse files
jdettergithub-advanced-security[bot]bfops
authored
Split Unity and C# tests into separate jobs (#3779)
# Description of Changes <!-- Please describe your change, mention any related tickets, and so on here. --> This has 2 benefits: 1. If the Unity test fails because of a license issue then we don't have to re-run the C# tests again as part of this flow. Re-running the Unity tests will be much faster if that's the only thing the job is doing. 2. These tests will run faster because they will now run in parallel as separate CI jobs. # API and ABI breaking changes <!-- If this is an API or ABI breaking change, please apply the corresponding GitHub label. --> None # Expected complexity level and risk 1 <!-- How complicated do you think these changes are? Grade on a scale from 1 to 5, where 1 is a trivial change, and 5 is a deep-reaching and complex change. This complexity rating applies not only to the complexity apparent in the diff, but also to its interactions with existing and future code. If you answered more than a 2, explain what is complex about the PR, and what other components it interacts with in potentially concerning ways. --> # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [x] Both tests pass --------- Signed-off-by: John Detter <4099508+jdetter@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com> Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
1 parent 1630f0c commit 1d34217

File tree

2 files changed

+222
-176
lines changed

2 files changed

+222
-176
lines changed

.github/workflows/ci.yml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,225 @@ jobs:
524524
echo "It looks like the CLI docs have changed:"
525525
exit 1
526526
fi
527+
528+
unity-testsuite:
529+
permissions:
530+
contents: read
531+
checks: write
532+
runs-on: spacetimedb-new-runner
533+
container:
534+
image: localhost:5000/spacetimedb-ci:latest
535+
options: >-
536+
--privileged
537+
--cgroupns=host
538+
timeout-minutes: 30
539+
env:
540+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
541+
steps:
542+
- name: Checkout repository
543+
id: checkout-stdb
544+
uses: actions/checkout@v4
545+
546+
# Run cheap .NET tests first. If those fail, no need to run expensive Unity tests.
547+
548+
- name: Setup dotnet
549+
uses: actions/setup-dotnet@v3
550+
with:
551+
global-json-file: global.json
552+
553+
- name: Override NuGet packages
554+
run: |
555+
dotnet pack crates/bindings-csharp/BSATN.Runtime
556+
dotnet pack crates/bindings-csharp/Runtime
557+
558+
# Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository
559+
# to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if
560+
# available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages.
561+
# This means that (if version numbers match) we will test the local versions of the C# packages, even
562+
# if they're not pushed to NuGet.
563+
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file.
564+
cd sdks/csharp
565+
./tools~/write-nuget-config.sh ../..
566+
567+
# Now, setup the Unity tests.
568+
- name: Patch spacetimedb dependency in Cargo.toml
569+
working-directory: demo/Blackholio/server-rust
570+
run: |
571+
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../../crates/bindings\" \}|" Cargo.toml
572+
cat Cargo.toml
573+
574+
- name: Install Rust toolchain
575+
uses: dtolnay/rust-toolchain@stable
576+
577+
- name: Cache Rust dependencies
578+
uses: Swatinem/rust-cache@v2
579+
with:
580+
workspaces: ${{ github.workspace }}
581+
shared-key: spacetimedb
582+
# Let the main CI job save the cache since it builds the most things
583+
save-if: false
584+
585+
- name: Install SpacetimeDB CLI from the local checkout
586+
run: |
587+
cargo install --force --path crates/cli --locked --message-format=short
588+
cargo install --force --path crates/standalone --locked --message-format=short
589+
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
590+
ln -sf $CARGO_HOME/bin/spacetimedb-cli $CARGO_HOME/bin/spacetime
591+
592+
- name: Generate client bindings
593+
working-directory: demo/Blackholio/server-rust
594+
run: bash ./generate.sh -y
595+
596+
- name: Check for changes
597+
run: |
598+
tools/check-diff.sh demo/Blackholio/client-unity/Assets/Scripts/autogen || {
599+
echo 'Error: Bindings are dirty. Please run `demo/Blackholio/server-rust/generate.sh`.'
600+
exit 1
601+
}
602+
603+
- name: Check Unity meta files
604+
uses: DeNA/unity-meta-check@v3
605+
with:
606+
enable_pr_comment: ${{ github.event_name == 'pull_request' }}
607+
target_path: sdks/csharp
608+
env:
609+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
610+
611+
- name: Start SpacetimeDB
612+
run: |
613+
spacetime start &
614+
disown
615+
616+
- name: Publish unity-tests module to SpacetimeDB
617+
working-directory: demo/Blackholio/server-rust
618+
run: |
619+
spacetime logout && spacetime login --server-issued-login local
620+
bash ./publish.sh
621+
622+
- name: Patch com.clockworklabs.spacetimedbsdk dependency in manifest.json
623+
working-directory: demo/Blackholio/client-unity/Packages
624+
run: |
625+
# Replace the com.clockworklabs.spacetimedbsdk dependency with the current branch.
626+
# 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.
627+
# codegen does not work properly).
628+
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "https://github.com/clockworklabs/SpacetimeDB.git?path=sdks/csharp#${{ github.head_ref }}"' manifest.json
629+
cat manifest.json
630+
631+
- uses: actions/cache@v3
632+
with:
633+
path: demo/Blackholio/client-unity/Library
634+
key: Unity-${{ github.head_ref }}
635+
restore-keys: Unity-
636+
637+
# We need this to support "Docker in Docker"
638+
- name: Start Docker daemon
639+
run: /usr/local/bin/start-docker.sh
640+
- name: Run Unity tests
641+
uses: game-ci/unity-test-runner@v4
642+
with:
643+
unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag
644+
projectPath: demo/Blackholio/client-unity # Path to the Unity project subdirectory
645+
githubToken: ${{ secrets.GITHUB_TOKEN }}
646+
testMode: playmode
647+
useHostNetwork: true
648+
artifactsPath: ""
649+
env:
650+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
651+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
652+
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
653+
# Skip if this is an external contribution.
654+
# The license secrets will be empty, so the step would fail anyway.
655+
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
656+
657+
csharp-testsuite:
658+
runs-on: spacetimedb-new-runner
659+
container:
660+
image: localhost:5000/spacetimedb-ci:latest
661+
options: >-
662+
--privileged
663+
--cgroupns=host
664+
timeout-minutes: 30
665+
env:
666+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
667+
steps:
668+
- name: Checkout repository
669+
id: checkout-stdb
670+
uses: actions/checkout@v4
671+
672+
# Run cheap .NET tests first. If those fail, no need to run expensive Unity tests.
673+
674+
- name: Setup dotnet
675+
uses: actions/setup-dotnet@v3
676+
with:
677+
global-json-file: global.json
678+
679+
- name: Override NuGet packages
680+
run: |
681+
dotnet pack crates/bindings-csharp/BSATN.Runtime
682+
dotnet pack crates/bindings-csharp/Runtime
683+
684+
# Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository
685+
# to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if
686+
# available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages.
687+
# This means that (if version numbers match) we will test the local versions of the C# packages, even
688+
# if they're not pushed to NuGet.
689+
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file.
690+
cd sdks/csharp
691+
./tools~/write-nuget-config.sh ../..
692+
693+
- name: Run .NET tests
694+
working-directory: sdks/csharp
695+
run: dotnet test -warnaserror
696+
697+
- name: Verify C# formatting
698+
working-directory: sdks/csharp
699+
run: dotnet format --no-restore --verify-no-changes SpacetimeDB.ClientSDK.sln
700+
701+
- name: Install Rust toolchain
702+
uses: dtolnay/rust-toolchain@stable
703+
704+
- name: Cache Rust dependencies
705+
uses: Swatinem/rust-cache@v2
706+
with:
707+
workspaces: ${{ github.workspace }}
708+
shared-key: spacetimedb
709+
# Let the main CI job save the cache since it builds the most things
710+
save-if: false
711+
712+
- name: Install SpacetimeDB CLI from the local checkout
713+
run: |
714+
cargo install --force --path crates/cli --locked --message-format=short
715+
cargo install --force --path crates/standalone --locked --message-format=short
716+
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
717+
ln -sf $CARGO_HOME/bin/spacetimedb-cli $CARGO_HOME/bin/spacetime
718+
719+
- name: Check quickstart-chat bindings are up to date
720+
working-directory: sdks/csharp
721+
run: |
722+
bash tools~/gen-quickstart.sh
723+
"${GITHUB_WORKSPACE}"/tools/check-diff.sh examples~/quickstart-chat || {
724+
echo 'Error: quickstart-chat bindings have changed. Please run `sdks/csharp/tools~/gen-quickstart.sh`.'
725+
exit 1
726+
}
727+
728+
- name: Check client-api bindings are up to date
729+
working-directory: sdks/csharp
730+
run: |
731+
bash tools~/gen-client-api.sh
732+
"${GITHUB_WORKSPACE}"/tools/check-diff.sh src/SpacetimeDB/ClientApi || {
733+
echo 'Error: Client API bindings are dirty. Please run `sdks/csharp/tools~/gen-client-api.sh`.'
734+
exit 1
735+
}
736+
737+
- name: Start SpacetimeDB
738+
run: |
739+
spacetime start &
740+
disown
741+
742+
- name: Run regression tests
743+
run: |
744+
bash sdks/csharp/tools~/run-regression-tests.sh
745+
tools/check-diff.sh sdks/csharp/examples~/regression-tests || {
746+
echo 'Error: Bindings are dirty. Please run `sdks/csharp/tools~/gen-regression-tests.sh`.'
747+
exit 1
748+
}

0 commit comments

Comments
 (0)