|
| 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