Skip to content

Commit

Permalink
Circle game testsuite - we should consider adding more game examples in
Browse files Browse the repository at this point in the history
the future

Add testing section to PR description (#164)

v  Below is a render of what the new PR description looks like

*Describe what has been changed, any new features or bug fixes*

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*

*List any PRs here that are required for this SDK change to work*

*Write instructions for a test that you performed for this PR*

- [ ] Describe a test for this PR that you have completed

Working on a more ergonomic CI workflow

Workflow runs on staging

Small bug fix

Test again

speedup

Use public bindings

Use serial instead of license

Updated default branch to be master

Disable all but one test because we don't support reconnections right
now

Small update

Fixes

Testsuite uses local reference to SDK

Added comma

debugging

One more debug

Small changes

small sed fix

Small fix - newline character was messing up branch name

Added debug

Updated how branch name is populated

We'll give this a try to make the C# SDK happy

C# tests building!

Updated README

Small fix

Move unity-tests to unity-tests~

Use relative path reference

Use relative path reference

Small update to the workflow

Updated README for new functionality
  • Loading branch information
John Detter committed Oct 22, 2024
1 parent a06a580 commit 547187e
Show file tree
Hide file tree
Showing 9 changed files with 501 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@

## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*

## Testsuite
*If you would like to run against a specific SpacetimeDB branch in the testsuite, specify that here. This can be a branch name or a link to a PR.*

SpacetimeDB branch name: master

## Testing
*Write instructions for a test that you performed for this PR*

- [ ] Describe a test for this PR that you have completed
119 changes: 119 additions & 0 deletions .github/workflows/unity-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Unity Test Suite

on:
push:
branches:
- staging
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

# Grab the branch name from the PR description. If it's not found, master will be used instead.
- name: Extract SpacetimeDB branch name or PR link from PR description
id: extract-branch
if: github.event_name == 'pull_request'
run: |
description=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
${{ github.event.pull_request.url }} | jq -r '.body')
# Check if description contains a branch name or a PR link
branch_or_pr=$(echo "$description" | grep -oP '(?<=SpacetimeDB branch name:\s).+')
echo "Branch or PR found: $branch_or_pr"
if [[ -z "$branch_or_pr" ]]; then
branch="master"
elif [[ "$branch_or_pr" =~ ^https://github.com/.*/pull/[0-9]+$ ]]; then
# If it's a PR link, extract the branch name from the PR
pr_number=$(echo "$branch_or_pr" | grep -oP '[0-9]+$')
branch=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/clockworklabs/SpacetimeDB/pulls/$pr_number | jq -r '.head.ref')
else
# It's already a branch name
branch="$branch_or_pr"
fi
echo "branch=$branch" >> $GITHUB_OUTPUT
echo "Final branch name: $branch"
- name: Replace com.clockworklabs.spacetimedbsdk in manifest.json
run: |
# Get the branch name from the environment variable
branch_name="${{ github.head_ref }}"
# Replace any reference to com.clockworklabs.spacetimedbsdk with the correct GitHub URL using the current branch
sed -i "s|\"com.clockworklabs.spacetimedbsdk\":.*|\"com.clockworklabs.spacetimedbsdk\": \"https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk.git#$branch_name\",|" unity-tests~/client/Packages/manifest.json
cat unity-tests~/client/Packages/manifest.json
- name: Install Rust toolchain
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env
rustup install stable
rustup default stable
- name: Install SpacetimeDB CLI from specific branch
run: |
cd unity-tests~
git clone https://github.com/clockworklabs/SpacetimeDB.git
cd SpacetimeDB
# Sanitize the branch name by trimming any newlines or spaces
branch_name=$(echo "${{ steps.extract-branch.outputs.branch }}" | tr -d '[:space:]')
# If the branch name is not found, default to master
if [ -z "$branch_name" ]; then
branch_name="master"
fi
git checkout "$branch_name"
echo "Checked out branch: $branch_name"
cargo build --release -p spacetimedb-cli
sudo mv target/release/spacetime /usr/bin/spacetime
- name: Generate client bindings
run: |
cd unity-tests~/server
bash ./generate.sh -y
- name: Start SpacetimeDB
run: |
spacetime start &
disown
- uses: actions/cache@v3
with:
path: |
unity-tests~/server/target
~/.cargo
key: server-target-SpacetimeDBUnityTestsuite-Linux-x86-${{ runner.os }}-${{ hashFiles('unity-tests~/server/Cargo.lock') }}
restore-keys: |
server-target-SpacetimeDBUnityTestsuite-Linux-x86-${{ runner.os }}-
server-target-SpacetimeDBUnityTestsuite-
- name: Publish module to SpacetimeDB
run: |
cd unity-tests~/server
bash ./publish.sh
- uses: actions/cache@v3
with:
path: unity-tests~/client/Library
key: Library-SpacetimeDBUnityTestsuite-Linux-x86
restore-keys: |
Library-SpacetimeDBUnityTestsuite-
Library-
- name: Set up Unity
uses: game-ci/unity-test-runner@v4
with:
unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag
projectPath: unity-tests~/client # Path to the Unity project subdirectory
githubToken: ${{ secrets.GITHUB_TOKEN }}
testMode: playmode
useHostNetwork: true
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ obj~
# This is used for local paths to SpacetimeDB packages.
/nuget.config
/nuget.config.meta

# JetBrains
.idea/
35 changes: 35 additions & 0 deletions unity-tests~/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Unity Testsuite

This testsuite is designed to test the SDK against a real Unity project. This project was initially branched off of the [SpacetimeDBCircleGame](https://github.com/clockworklabs/SpacetimeDBCircleGame)

### Running Locally

1. clone this repository
2. Open UnityHub
3. Make sure you have a valid Unity license
4. Add -> `com.clockworklabs.spacetimedbsdk/unity-tests/client`
5. Open the project called `client` at the top of your project list

Now, while that's loading you can get SpacetimeDB setup. The easiest thing to do will be this:
```
# cd into your unity-tests directory
cd com.clockworklabs.spacetimedbsdk/unity-tests
# clone a new instance of SpacetimeDB within this directory
git clone ssh://git@github.com/clockworklabs/SpacetimeDB
cd SpacetimeDB
git checkout a-branch-I-want-to-test-against
# You probably want to install this version of the CLI for generation + publishing
cargo install --path ./crates/cli
# start spacetimedb, Boppy recommends starting this in a separate terminal window
spacetime start &
# generate bindings
bash server/generate.sh
# publish module
bash server/publish.sh
```

After you've done this you can open `Window -> General -> Test Runner` which will open the test runner interface. If you look in `Play Mode Tests` you should see some tests you can run. You can run tests individually, run selected tests or run all tests.

*NOTE: The Unity project that you open is called "client" and it has a local reference to the unity package so if you make changes to the unity package code it will update automatically in the editor.*
8 changes: 8 additions & 0 deletions unity-tests~/client/Assets/PlayModeTests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 547187e

Please sign in to comment.