Skip to content

Commit bd9ea55

Browse files
bfopsClockwork Labscloutiertylerjdetterdbrinkmann-citadel
authored
Import C#/Unity SDK (#2951)
Co-authored-by: Clockwork Labs <no-reply@clockworklabs.io> Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com> Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com> Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com> Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net> Co-authored-by: dbrinkmanncw <109690865+dbrinkmanncw@users.noreply.github.com> Co-authored-by: John Detter <no-reply@boppygames.gg> Co-authored-by: SteveBoytsun <100594800+SteveBoytsun@users.noreply.github.com> Co-authored-by: Steve <steve@codefics.com> Co-authored-by: Alessandro Asoni <alessandro@clockworklabs.io> Co-authored-by: Derek Brinkmann <dbrinkmann@clockworklabs.io> Co-authored-by: james gilles <jameshgilles@gmail.com> Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org> Co-authored-by: Ingvar Stepanyan <me@rreverser.com> Co-authored-by: Kurtis Mullins <github@kurtismullins.com> Co-authored-by: Jeremie Pelletier <jeremiep@gmail.com> Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com> Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com> Co-authored-by: Steve Boytsun <steve@clockwokrlabs.io> Co-authored-by: Ingvar Stepanyan <ingvar@clockworklabs.io> Co-authored-by: joshua-spacetime <josh@clockworklabs.io> Co-authored-by: Noa <coolreader18@gmail.com> Co-authored-by: rekhoff <r.ekhoff@clockworklabs.io> Co-authored-by: Daniel Kierkegaard Andersen <dax@daxode.dk> Co-authored-by: Guribo <guribovr@gmail.com> Co-authored-by: Lisandro Crespo <lisandroct@gmail.com>
2 parents 83f52ca + 9bdb3ed commit bd9ea55

File tree

197 files changed

+11962
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+11962
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Description of Changes
2+
*Describe what has been changed, any new features or bug fixes*
3+
4+
## API
5+
6+
- [ ] This is an API breaking change to the SDK
7+
8+
*If the API is breaking, please state below what will break*
9+
10+
## Requires SpacetimeDB PRs
11+
*List any PRs here that are required for this SDK change to work*
12+
13+
## Testsuite
14+
*If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.*
15+
16+
SpacetimeDB branch name: master
17+
18+
## Testing
19+
*Write instructions for a test that you performed for this PR*
20+
21+
- [ ] Describe a test for this PR that you have completed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Git tree checks
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened, synchronize]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: read
10+
11+
jobs:
12+
check_base_ref:
13+
name: Release branch restriction
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Change base to master if needed
17+
if: |
18+
github.event_name == 'pull_request' &&
19+
github.event.pull_request.base.ref == 'release/latest' &&
20+
! startsWith(github.event.pull_request.head.ref, 'release/')
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
echo 'Updating PR '"#${{ github.event.pull_request.number }}"' to use base `master`'
25+
echo 'If you do want to release your changes directly by merging into `release/latest`, your branch must start with `release/`.'
26+
27+
curl -X PATCH \
28+
-H "Authorization: Bearer $GITHUB_TOKEN" \
29+
-H "Accept: application/vnd.github+json" \
30+
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} \
31+
-d '{"base": "master"}'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Publish NuGet Package on Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Setup .NET
13+
uses: actions/setup-dotnet@v3
14+
with:
15+
dotnet-version: '8'
16+
- name: Restore dependencies
17+
run: dotnet restore
18+
- name: Build
19+
run: dotnet build --no-restore --configuration Release
20+
# - name: Test
21+
# run: dotnet test --no-build
22+
- name: Pack
23+
run: dotnet pack --no-build --output nupkgs
24+
- name: Publish
25+
run: dotnet nuget push nupkgs/*.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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 }}

sdks/csharp/.gitignore

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This .gitignore file should be placed at the root of your Unity project directory
2+
#
3+
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
4+
#
5+
/[Ll]ibrary/
6+
/[Tt]emp/
7+
/[Oo]bj/
8+
/[Bb]uild/
9+
/[Bb]uilds/
10+
/[Ll]ogs/
11+
/[Uu]ser[Ss]ettings/
12+
13+
# MemoryCaptures can get excessive in size.
14+
# They also could contain extremely sensitive data
15+
/[Mm]emoryCaptures/
16+
17+
# Recordings can get excessive in size
18+
/[Rr]ecordings/
19+
20+
# Uncomment this line if you wish to ignore the asset store tools plugin
21+
# /[Aa]ssets/AssetStoreTools*
22+
23+
# Autogenerated Jetbrains Rider plugin
24+
/[Aa]ssets/Plugins/Editor/JetBrains*
25+
26+
# Visual Studio cache directory
27+
.vs/
28+
29+
# Gradle cache directory
30+
.gradle/
31+
32+
# Autogenerated VS/MD/Consulo solution and project files
33+
ExportedObj/
34+
.consulo/
35+
*.unityproj
36+
*.suo
37+
*.tmp
38+
*.user
39+
*.userprefs
40+
*.pidb
41+
*.booproj
42+
*.svd
43+
*.pdb
44+
*.mdb
45+
*.opendb
46+
*.VC.db
47+
48+
# Unity3D generated meta files
49+
*.pidb.meta
50+
*.pdb.meta
51+
*.mdb.meta
52+
53+
# Unity3D generated file on crash reports
54+
sysinfo.txt
55+
56+
# Builds
57+
*.apk
58+
*.aab
59+
*.unitypackage
60+
*.app
61+
62+
# Crashlytics generated file
63+
crashlytics-build.properties
64+
65+
# Packed Addressables
66+
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
67+
68+
# Temporary auto-generated Android Assets
69+
/[Aa]ssets/[Ss]treamingAssets/aa.meta
70+
/[Aa]ssets/[Ss]treamingAssets/aa/*
71+
72+
bin~
73+
obj~
74+
75+
# This is used for local paths to SpacetimeDB packages.
76+
/nuget.config
77+
/nuget.config.meta
78+
.idea/

sdks/csharp/.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "SpacetimeDBCircleGame"]
2+
path = unity-tests~
3+
url = https://github.com/clockworklabs/SpacetimeDBCircleGame

sdks/csharp/DEVELOP.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Notes for maintainers
2+
3+
## `SpacetimeDB.ClientApi`
4+
5+
To regenerate this namespace, run the `tools~/gen-client-api.sh` or the
6+
`tools~/gen-client-api.bat` script.
7+
8+
## Developing against a local clone of SpacetimeDB
9+
When developing against a local clone of SpacetimeDB, you'll need to ensure that the packages here can find an up-to-date version of the BSATN.Codegen and BSATN.Runtime packages from SpacetimeDB.
10+
11+
To develop against a local clone of SpacetimeDB at `../SpacetimeDB`, run the following command:
12+
13+
```sh
14+
dotnet pack ../SpacetimeDB/crates/bindings-csharp/BSATN.Runtime && ./tools~/write-nuget-config.sh ../SpacetimeDB
15+
```
16+
17+
This will create a (`.gitignore`d) `nuget.config` file that uses the local build of the package, instead of the package on NuGet.
18+
19+
You'll need to rerun this command whenever you update `BSATN.Codegen` or `BSATN.Runtime`.

sdks/csharp/DEVELOP.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdks/csharp/Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<BaseOutputPath>bin~</BaseOutputPath>
4+
<BaseIntermediateOutputPath>obj~</BaseIntermediateOutputPath>
5+
</PropertyGroup>
6+
</Project>

sdks/csharp/Directory.Build.props.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)