-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unity Testsuite #176
Unity Testsuite #176
Changes from all commits
a5dc75d
b2c954b
d456ac8
0fceb1a
e174841
a2a915c
960256b
31f7b1a
87fa4fc
463fb52
58b1433
fc1b649
bfd5f9f
8c93641
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add this link: https://game.ci/docs/github/getting-started/ |
||
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 }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Check Unity Testsuite Bindings | ||
|
||
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: 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: Check for changes | ||
run: | | ||
git diff --exit-code | ||
continue-on-error: true | ||
|
||
- name: Fail if there are changes | ||
if: ${{ steps.check-for-changes.outcome == 'failure' }} | ||
run: | | ||
echo "Error: Bindings are dirty. Please generate bindings again and commit them to this branch." | ||
exit 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,3 +75,4 @@ obj~ | |
# This is used for local paths to SpacetimeDB packages. | ||
/nuget.config | ||
/nuget.config.meta | ||
.idea/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
unity-tests~/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.idea/ | ||
.vsconfig | ||
|
||
### macOS ### | ||
# General | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### macOS Patch ### | ||
# iCloud generated files | ||
*.icloud | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/macos | ||
|
||
# SpacetimeDB repo used for the testsuite | ||
SpacetimeDB/ |
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://[email protected]/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.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call this a ref instead