Skip to content

Commit

Permalink
All changes on staging, but not in master
Browse files Browse the repository at this point in the history
  • Loading branch information
cloutiertyler committed Dec 14, 2024
1 parent 732dd28 commit 118265d
Show file tree
Hide file tree
Showing 94 changed files with 3,292 additions and 2,008 deletions.
11 changes: 10 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

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


## 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
22 changes: 22 additions & 0 deletions .github/workflows/check-pr-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Git tree checks

on:
pull_request:
types: [opened, edited, reopened, synchronize]
merge_group:
permissions: read-all

jobs:
check_base_ref:
name: Only release branches may merge into master
runs-on: ubuntu-latest
steps:
- id: not_based_on_master
if: |
github.event_name == 'pull_request' &&
github.event.pull_request.base.ref == 'master' &&
! startsWith(github.event.pull_request.head.ref, 'release/')
run: |
echo 'Only `release/*` branches are allowed to merge into `master`.'
echo 'Maybe your PR should be merging into `staging`?'
exit 1
16 changes: 3 additions & 13 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,9 @@ jobs:
# available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages.
# This means that (if version numbers match) we will test the local versions of the C# packages, even
# if they're not pushed to NuGet.
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file,
# and https://tldp.org/LDP/abs/html/here-docs.html for more info on this bash feature.
cat >nuget.config <<EOF
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- Local NuGet repositories -->
<add key="Local SpacetimeDB.BSATN.Runtime" value="../SpacetimeDB/crates/bindings-csharp/BSATN.Runtime/bin/Release" />
<!-- Official NuGet.org server -->
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
EOF
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file.
./tools~/write-nuget-config.sh ../SpacetimeDB
- name: Restore dependencies
working-directory: spacetimedb-csharp-sdk
run: dotnet restore
Expand Down
143 changes: 143 additions & 0 deletions .github/workflows/unity-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Unity Test Suite

on:
push:
branches:
- staging
pull_request:

jobs:
unity-testsuite:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

# 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'
env:
description: ${{ github.event.pull_request.body }}
run: |
# 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: Replace spacetimedb dependency in Cargo.toml
run: |
# Get the branch name from the environment variable
branch_name="${{ github.head_ref }}"
# Make sure we're using the correct bindings when building the module TODO
sed -i "s|spacetimedb.*=.*|spacetimedb = \{ path = \"../SpacetimeDB/crates/bindings\" \}|" unity-tests~/server/Cargo.toml
cat unity-tests~/server/Cargo.toml
- 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: Cache Cargo target directory
uses: actions/cache@v3
with:
path: unity-tests~/server/target
key: server-target-SpacetimeDBUnityTestsuite-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('unity-tests~/server/Cargo.lock') }}
restore-keys: |
server-target-SpacetimeDBUnityTestsuite-${{ runner.os }}-${{ runner.arch }}-
server-target-SpacetimeDBUnityTestsuite-
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: cargo-registry-${{ runner.os }}-${{ hashFiles('unity-tests~/server/Cargo.lock') }}
restore-keys: |
cargo-registry-${{ runner.os }}-
cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: cargo-index-${{ runner.os }}-${{ hashFiles('unity-tests~/server/Cargo.lock') }}
restore-keys: |
cargo-index-${{ runner.os }}-
cargo-index-
- 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
- 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 }}
115 changes: 115 additions & 0 deletions .github/workflows/unity-testsuite-bindings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Check Unity Testsuite Bindings

on:
push:
branches:
- staging
pull_request:

jobs:
check-testsuite-bindings:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

# 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'
env:
description: ${{ github.event.pull_request.body }}
run: |
# 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 spacetimedb dependency in Cargo.toml
run: |
# Get the branch name from the environment variable
branch_name="${{ github.head_ref }}"
# Make sure we're using the correct bindings when building the module TODO
sed -i "s|spacetimedb.*=.*|spacetimedb = \{ path = \"../SpacetimeDB/crates/bindings\" \}|" unity-tests~/server/Cargo.toml
cat unity-tests~/server/Cargo.toml
- 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: Cache Cargo target directory
uses: actions/cache@v3
with:
path: unity-tests~/server/target
key: server-target-SpacetimeDBUnityTestsuite-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('unity-tests~/server/Cargo.lock') }}
restore-keys: |
server-target-SpacetimeDBUnityTestsuite-${{ runner.os }}-${{ runner.arch }}-
server-target-SpacetimeDBUnityTestsuite-
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: cargo-registry-${{ runner.os }}-${{ hashFiles('unity-tests~/server/Cargo.lock') }}
restore-keys: |
cargo-registry-${{ runner.os }}-
cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/git
key: cargo-index-${{ runner.os }}-${{ hashFiles('unity-tests~/server/Cargo.lock') }}
restore-keys: |
cargo-index-${{ runner.os }}-
cargo-index-
- 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 unity-tests~/client/Assets/Scripts/autogen
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ obj~
# This is used for local paths to SpacetimeDB packages.
/nuget.config
/nuget.config.meta
.idea/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "SpacetimeDBCircleGame"]
path = unity-tests~
url = https://github.com/clockworklabs/SpacetimeDBCircleGame
17 changes: 3 additions & 14 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# Notes for maintainers

## `ClientApi.cs`
## `SpacetimeDB.ClientApi`

The file `ClientApi.cs` is generated by [ProtoBuf](https://protobuf.dev/)
from [the SpacetimeDB client-api-messages proto definition](https://github.com/clockworklabs/SpacetimeDB/blob/master/crates/client-api-messages/protobuf/client_api.proto).
This is not automated.
Whenever the `client_api.proto` changes, you'll have to manually re-run `protoc` to re-generate the definitions.

```sh
cd ~/clockworklabs/SpacetimeDB/crates/client-api-messages/protobuf
protoc --csharp_out=/absolute/path/to/spacetimedb-csharp-sdk/src \
./client_api.proto
```

Note that `protoc` cannot understand paths that start with `~`;
you must write the absolute path starting from `/`.
To regenerate this namespace, run the `tools~/gen-client-api.sh` or the
`tools~/gen-client-api.bat` script.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ This repository contains the [Unity](https://unity.com/) SDK for SpacetimeDB. Th

## Documentation

The Unity SDK uses the same code as the C# SDK. You can find the documentation for the C# SDK in the [C# SDK Reference](README.dotnet.md).
The Unity SDK uses the same code as the C# SDK. You can find the documentation for the C# SDK in the [C# SDK Reference](https://spacetimedb.com/docs/sdks/c-sharp)

There is also a comprehensive Unity tutorial/demo available:

- [Unity Tutorial](https://spacetimedb.com/docs/unity/part-1) Doc
- [Unity Demo](https://github.com/clockworklabs/SpacetimeDBUnityTutorial) Repo

Expand All @@ -27,9 +26,9 @@ Download the [.unitypackage release](https://github.com/clockworklabs/SpacetimeD

## Usage

### UnityNetworkManager
### SpacetimeDBNetworkManager

The Unity SDK for SpacetimeDB requires that there is a `UnityNetworkManager` component attached to a GameObject in the scene. The `UnityNetworkManager` component is responsible for connecting to SpacetimeDB and managing the connection. The `UnityNetworkManager` component is a singleton and there can only be one instance of it in the scene.
The Unity SDK for SpacetimeDB requires that there is a `SpacetimeDBNetworkManager` component attached to a GameObject in the scene. The `UnityNetworkManager` component is responsible for connecting to SpacetimeDB and managing the connection. The `UnityNetworkManager` component is a singleton and there can only be one instance of it in the scene.

### Connecting to SpacetimeDB

Expand Down
Loading

0 comments on commit 118265d

Please sign in to comment.