|
| 1 | +name: Test Suite |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - staging |
| 7 | + pull_request: |
| 8 | + |
| 9 | +jobs: |
| 10 | + unity-testsuite: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + 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~ |
| 53 | + |
| 54 | + # Run cheap .NET tests first. If those fail, no need to run expensive Unity tests. |
| 55 | + |
| 56 | + - name: Setup dotnet |
| 57 | + uses: actions/setup-dotnet@v3 |
| 58 | + with: |
| 59 | + global-json-file: SpacetimeDB~/modules/global.json |
| 60 | + |
| 61 | + - name: Override NuGet packages |
| 62 | + run: | |
| 63 | + dotnet pack SpacetimeDB~/crates/bindings-csharp/BSATN.Runtime |
| 64 | + dotnet pack SpacetimeDB~/crates/bindings-csharp/Runtime |
| 65 | +
|
| 66 | + # Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository |
| 67 | + # to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if |
| 68 | + # available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages. |
| 69 | + # This means that (if version numbers match) we will test the local versions of the C# packages, even |
| 70 | + # if they're not pushed to NuGet. |
| 71 | + # 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~ |
| 73 | +
|
| 74 | + - name: Run .NET tests |
| 75 | + run: dotnet test -warnaserror |
| 76 | + |
| 77 | + - name: Verify C# formatting |
| 78 | + run: dotnet format --no-restore --verify-no-changes SpacetimeDB.ClientSDK.sln |
| 79 | + |
| 80 | + # Now, setup the Unity tests. |
| 81 | + |
| 82 | + - name: Patch spacetimedb dependency in Cargo.toml |
| 83 | + working-directory: unity-tests~/server-rust |
| 84 | + run: | |
| 85 | + sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../SpacetimeDB~/crates/bindings\" \}|" Cargo.toml |
| 86 | + cat Cargo.toml |
| 87 | +
|
| 88 | + - name: Install Rust toolchain |
| 89 | + uses: dtolnay/rust-toolchain@stable |
| 90 | + |
| 91 | + |
| 92 | + - name: Cache Rust dependencies |
| 93 | + uses: Swatinem/rust-cache@v2 |
| 94 | + id: cache-rust-deps |
| 95 | + with: |
| 96 | + workspaces: unity-tests~/server-rust |
| 97 | + key: ${{ steps.checkout-stdb.outputs.commit }} |
| 98 | + # Cache Rust deps even if unit tests have failed. |
| 99 | + cache-on-failure: true |
| 100 | + # Cache the CLI as well. |
| 101 | + cache-all-crates: true |
| 102 | + |
| 103 | + - name: Install SpacetimeDB CLI from the local checkout |
| 104 | + # Rebuild only if we didn't get a precise cache hit. |
| 105 | + if: steps.cache-rust-deps.outputs.cache-hit == 'false' |
| 106 | + 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 |
| 109 | + # Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules). |
| 110 | + ln -sf $HOME/.cargo/bin/spacetimedb-cli $HOME/.cargo/bin/spacetime |
| 111 | + env: |
| 112 | + # Share the target directory with our local project to avoid rebuilding same SpacetimeDB crates twice. |
| 113 | + CARGO_TARGET_DIR: unity-tests~/server-rust/target |
| 114 | + |
| 115 | + - name: Generate client bindings |
| 116 | + working-directory: unity-tests~/server-rust |
| 117 | + run: bash ./generate.sh -y |
| 118 | + |
| 119 | + - name: Check for changes |
| 120 | + run: | |
| 121 | + git diff --exit-code unity-tests~/client-unity/Assets/Scripts/autogen || { |
| 122 | + echo "Error: Bindings are dirty. Please generate bindings again and commit them to this branch." |
| 123 | + exit 1 |
| 124 | + } |
| 125 | +
|
| 126 | + - name: Check Unity meta files |
| 127 | + uses: DeNA/unity-meta-check@v3 |
| 128 | + with: |
| 129 | + enable_pr_comment: ${{ github.event_name == 'pull_request' }} |
| 130 | + env: |
| 131 | + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 132 | + |
| 133 | + - name: Start SpacetimeDB |
| 134 | + run: | |
| 135 | + spacetime start & |
| 136 | + disown |
| 137 | +
|
| 138 | + - name: Run regression tests |
| 139 | + run: bash tools~/run-regression-tests.sh SpacetimeDB~ |
| 140 | + |
| 141 | + - name: Publish unity-tests module to SpacetimeDB |
| 142 | + working-directory: unity-tests~/server-rust |
| 143 | + run: | |
| 144 | + spacetime logout && spacetime login --server-issued-login local |
| 145 | + bash ./publish.sh |
| 146 | +
|
| 147 | + - name: Patch com.clockworklabs.spacetimedbsdk dependency in manifest.json |
| 148 | + working-directory: unity-tests~/client-unity/Packages |
| 149 | + run: | |
| 150 | + # 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 |
| 153 | + cat manifest.json |
| 154 | +
|
| 155 | + - uses: actions/cache@v3 |
| 156 | + with: |
| 157 | + path: unity-tests~/client-unity/Library |
| 158 | + key: Unity-${{ github.head_ref }} |
| 159 | + restore-keys: Unity- |
| 160 | + |
| 161 | + - name: Run Unity tests |
| 162 | + uses: game-ci/unity-test-runner@v4 |
| 163 | + with: |
| 164 | + unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag |
| 165 | + projectPath: unity-tests~/client-unity # Path to the Unity project subdirectory |
| 166 | + githubToken: ${{ secrets.GITHUB_TOKEN }} |
| 167 | + testMode: playmode |
| 168 | + useHostNetwork: true |
| 169 | + env: |
| 170 | + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} |
| 171 | + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} |
| 172 | + UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} |
0 commit comments