-
Notifications
You must be signed in to change notification settings - Fork 585
Import C#/Unity SDK #2951
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
Import C#/Unity SDK #2951
Changes from all commits
271e8ce
77b7c27
6c014f6
1f4f10b
e6670fe
5ac9a7e
ee03801
ddf626c
63f4550
a4727e6
8eef49f
df3742f
e518ebe
789b5b2
7f4e27d
c499710
dbd3387
ec5fa25
a82c379
2054da4
0a52df6
93cd63d
02cbdd0
ac573a0
fdca2f5
5839fd4
3d2a2a8
a9b9bfc
63f5239
c313629
5e63631
2a6e037
b1b9689
91b3e23
e806ee3
7737b98
cf9c5b0
9382710
85b8020
31dedc3
351616e
4fb1975
8a74cfd
0a46b01
bebd5db
de4ea64
76cd6ee
eee5131
a0f8c48
4990149
134834a
9b21d40
3bc803b
c7dbe35
1a95b38
e0524fa
1003db2
b08a03e
102061f
b2dbe89
819947c
9c744a3
f315960
d54c31a
b170539
061f1c3
75dc6b5
e649c49
0ca2a54
f6aa76c
383ba27
2fd9eb4
eaa8fa0
6b5b23d
ce38cd1
1bb67c5
c925af1
8ca0484
c8319eb
8db08a7
6ba3da5
125c5e7
1af7233
ed6a3aa
4819292
92f5a17
7bafc7f
53d6f9c
b648b9c
0267f02
40f6138
17ce57f
21e475b
e345452
9c01734
27120e8
7e8a6ed
06285d3
706b945
5e06506
554df35
cd5f44b
9fba156
5394c63
655c2cc
2efa162
996633b
cb59eba
e28849e
e57e589
341be7f
5670db6
2422b8c
6312c45
589d404
76d30fe
5c033a4
87a13eb
113e8dd
cfd654f
b62a464
cec6fb8
463a240
9d3336e
fa87e36
affa2af
b96f1a6
76d275f
2c95bee
1b0e843
b320e5e
434c5ff
2d20acd
072d9ea
d2143cc
c3be5b0
f376c05
1e13ab5
01a7e3f
035ee4b
cf3f37c
5ccb5f9
b2c5b41
b728e63
ac45eac
f936c98
2ad31d6
181aff3
82f4b07
3054a7f
9b7f20c
844713f
1a21af8
d8277ff
fa2baa6
a90e0f9
d6d78b3
bb6d624
006087f
11896cb
39e7ebb
2487c94
0017af7
749825a
3d530ee
62e16c6
6578f05
27be301
76194c2
aa6cb5b
82ad0a0
f4cc0b3
cefc727
fed2a9d
b4aa612
9f58828
f966144
96d52c1
498b25f
c6eded9
076d4ec
0386121
b80a2b9
083531e
b1a9f96
df1dcf2
25689c1
e21566a
60761bb
421256a
bbdb0fd
9523ba3
4d3f0a0
23c2dc0
89c019c
d4267b3
3543132
468a6f1
7d25b03
f24b0e8
47e9638
f32754b
ce7828e
0fa4cf9
20ed2dc
c99c4cb
3ed21c4
b6f8362
5ad9baa
8756058
78f5000
590e873
3dabd47
c813fb3
b46a894
8bde94a
c03b962
a198fad
5baf66b
544085c
e3b392a
e168ec6
79de507
d62d85a
4b1cce2
6c419cc
533c14b
2c7b668
07899d0
9bdb3ed
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,21 @@ | ||
## Description of Changes | ||
*Describe what has been changed, any new features or bug fixes* | ||
|
||
## API | ||
|
||
- [ ] This is an API breaking change to the SDK | ||
|
||
*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 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.* | ||
|
||
SpacetimeDB branch name: master | ||
bfops marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Testing | ||
*Write instructions for a test that you performed for this PR* | ||
|
||
- [ ] Describe a test for this PR that you have completed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Git tree checks | ||
|
||
on: | ||
pull_request: | ||
types: [opened, edited, reopened, synchronize] | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: read | ||
|
||
jobs: | ||
check_base_ref: | ||
name: Release branch restriction | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Change base to master if needed | ||
if: | | ||
github.event_name == 'pull_request' && | ||
github.event.pull_request.base.ref == 'release/latest' && | ||
! startsWith(github.event.pull_request.head.ref, 'release/') | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
echo 'Updating PR '"#${{ github.event.pull_request.number }}"' to use base `master`' | ||
echo 'If you do want to release your changes directly by merging into `release/latest`, your branch must start with `release/`.' | ||
|
||
curl -X PATCH \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} \ | ||
-d '{"base": "master"}' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Publish NuGet Package on Release | ||
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. Ok this is quite nice now that when we send out a SpacetimeDB release it will also release the nuget package for us automatically. This is a huge improvement. 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. I actually don't know that we want that - not all SpacetimeDB releases are tied to C# SDK releases (and vice-versa) 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. Yeah I guess it's not true in the general case that we always want to send out C# SDK updates for every SpacetimeDB release (especially for minor version bumps) |
||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '8' | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore --configuration Release | ||
# - name: Test | ||
# run: dotnet test --no-build | ||
- name: Pack | ||
run: dotnet pack --no-build --output nupkgs | ||
- name: Publish | ||
run: dotnet nuget push nupkgs/*.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
name: 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 SpacetimeDB branch name from the PR description. If it's not found, master will be used instead. | ||
bfops marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# We'll use this branch name for any integration tests with SpacetimeDB. | ||
|
||
- 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: Checkout SpacetimeDB | ||
uses: actions/checkout@v4 | ||
id: checkout-stdb | ||
with: | ||
repository: clockworklabs/SpacetimeDB | ||
ref: ${{ steps.extract-branch.outputs.branch }} | ||
path: SpacetimeDB~ | ||
|
||
# Run cheap .NET tests first. If those fail, no need to run expensive Unity tests. | ||
|
||
- name: Setup dotnet | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
global-json-file: SpacetimeDB~/modules/global.json | ||
|
||
- name: Override NuGet packages | ||
run: | | ||
dotnet pack SpacetimeDB~/crates/bindings-csharp/BSATN.Runtime | ||
dotnet pack SpacetimeDB~/crates/bindings-csharp/Runtime | ||
|
||
# Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository | ||
# to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if | ||
# 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. | ||
./tools~/write-nuget-config.sh SpacetimeDB~ | ||
|
||
- name: Run .NET tests | ||
run: dotnet test -warnaserror | ||
|
||
- name: Verify C# formatting | ||
run: dotnet format --no-restore --verify-no-changes SpacetimeDB.ClientSDK.sln | ||
|
||
# Now, setup the Unity tests. | ||
|
||
- name: Patch spacetimedb dependency in Cargo.toml | ||
working-directory: unity-tests~/server-rust | ||
run: | | ||
sed -i "s|spacetimedb *=.*|spacetimedb = \{ path = \"../../SpacetimeDB~/crates/bindings\" \}|" Cargo.toml | ||
cat Cargo.toml | ||
|
||
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
|
||
|
||
- name: Cache Rust dependencies | ||
uses: Swatinem/rust-cache@v2 | ||
id: cache-rust-deps | ||
with: | ||
workspaces: unity-tests~/server-rust | ||
key: ${{ steps.checkout-stdb.outputs.commit }} | ||
# Cache Rust deps even if unit tests have failed. | ||
cache-on-failure: true | ||
# Cache the CLI as well. | ||
cache-all-crates: true | ||
|
||
- name: Install SpacetimeDB CLI from the local checkout | ||
# Rebuild only if we didn't get a precise cache hit. | ||
if: steps.cache-rust-deps.outputs.cache-hit == 'false' | ||
run: | | ||
cargo install --force --path SpacetimeDB~/crates/cli --locked --message-format=short | ||
cargo install --force --path SpacetimeDB~/crates/standalone --locked --message-format=short | ||
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules). | ||
ln -sf $HOME/.cargo/bin/spacetimedb-cli $HOME/.cargo/bin/spacetime | ||
env: | ||
# Share the target directory with our local project to avoid rebuilding same SpacetimeDB crates twice. | ||
CARGO_TARGET_DIR: unity-tests~/server-rust/target | ||
|
||
- name: Generate client bindings | ||
working-directory: unity-tests~/server-rust | ||
run: bash ./generate.sh -y | ||
|
||
- name: Check for changes | ||
run: | | ||
git diff --exit-code unity-tests~/client-unity/Assets/Scripts/autogen || { | ||
echo "Error: Bindings are dirty. Please generate bindings again and commit them to this branch." | ||
exit 1 | ||
} | ||
|
||
- name: Check Unity meta files | ||
uses: DeNA/unity-meta-check@v3 | ||
with: | ||
enable_pr_comment: ${{ github.event_name == 'pull_request' }} | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
|
||
- name: Start SpacetimeDB | ||
run: | | ||
spacetime start & | ||
disown | ||
|
||
- name: Run regression tests | ||
run: bash tools~/run-regression-tests.sh SpacetimeDB~ | ||
|
||
- name: Publish unity-tests module to SpacetimeDB | ||
working-directory: unity-tests~/server-rust | ||
run: | | ||
spacetime logout && spacetime login --server-issued-login local | ||
bash ./publish.sh | ||
|
||
- name: Patch com.clockworklabs.spacetimedbsdk dependency in manifest.json | ||
working-directory: unity-tests~/client-unity/Packages | ||
run: | | ||
# Replace the com.clockworklabs.spacetimedbsdk dependency with the current branch. | ||
# TODO: find out why pointing to a local directory doesn't work - is it because Unity CI action uses Docker? | ||
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk.git#${{ github.head_ref }}"' manifest.json | ||
cat manifest.json | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
path: unity-tests~/client-unity/Library | ||
key: Unity-${{ github.head_ref }} | ||
restore-keys: Unity- | ||
|
||
- name: Run Unity tests | ||
uses: game-ci/unity-test-runner@v4 | ||
with: | ||
unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag | ||
projectPath: unity-tests~/client-unity # 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,78 @@ | ||
# This .gitignore file should be placed at the root of your Unity project directory | ||
# | ||
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore | ||
# | ||
/[Ll]ibrary/ | ||
/[Tt]emp/ | ||
/[Oo]bj/ | ||
/[Bb]uild/ | ||
/[Bb]uilds/ | ||
/[Ll]ogs/ | ||
/[Uu]ser[Ss]ettings/ | ||
|
||
# MemoryCaptures can get excessive in size. | ||
# They also could contain extremely sensitive data | ||
/[Mm]emoryCaptures/ | ||
|
||
# Recordings can get excessive in size | ||
/[Rr]ecordings/ | ||
|
||
# Uncomment this line if you wish to ignore the asset store tools plugin | ||
# /[Aa]ssets/AssetStoreTools* | ||
|
||
# Autogenerated Jetbrains Rider plugin | ||
/[Aa]ssets/Plugins/Editor/JetBrains* | ||
|
||
# Visual Studio cache directory | ||
.vs/ | ||
|
||
# Gradle cache directory | ||
.gradle/ | ||
|
||
# Autogenerated VS/MD/Consulo solution and project files | ||
ExportedObj/ | ||
.consulo/ | ||
*.unityproj | ||
*.suo | ||
*.tmp | ||
*.user | ||
*.userprefs | ||
*.pidb | ||
*.booproj | ||
*.svd | ||
*.pdb | ||
*.mdb | ||
*.opendb | ||
*.VC.db | ||
|
||
# Unity3D generated meta files | ||
*.pidb.meta | ||
*.pdb.meta | ||
*.mdb.meta | ||
|
||
# Unity3D generated file on crash reports | ||
sysinfo.txt | ||
|
||
# Builds | ||
*.apk | ||
*.aab | ||
*.unitypackage | ||
*.app | ||
|
||
# Crashlytics generated file | ||
crashlytics-build.properties | ||
|
||
# Packed Addressables | ||
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* | ||
|
||
# Temporary auto-generated Android Assets | ||
/[Aa]ssets/[Ss]treamingAssets/aa.meta | ||
/[Aa]ssets/[Ss]treamingAssets/aa/* | ||
|
||
bin~ | ||
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,3 @@ | ||
[submodule "SpacetimeDBCircleGame"] | ||
path = unity-tests~ | ||
url = https://github.com/clockworklabs/SpacetimeDBCircleGame |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Notes for maintainers | ||
|
||
## `SpacetimeDB.ClientApi` | ||
|
||
To regenerate this namespace, run the `tools~/gen-client-api.sh` or the | ||
`tools~/gen-client-api.bat` script. | ||
|
||
## Developing against a local clone of SpacetimeDB | ||
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. | ||
|
||
To develop against a local clone of SpacetimeDB at `../SpacetimeDB`, run the following command: | ||
|
||
```sh | ||
dotnet pack ../SpacetimeDB/crates/bindings-csharp/BSATN.Runtime && ./tools~/write-nuget-config.sh ../SpacetimeDB | ||
``` | ||
|
||
This will create a (`.gitignore`d) `nuget.config` file that uses the local build of the package, instead of the package on NuGet. | ||
|
||
You'll need to rerun this command whenever you update `BSATN.Codegen` or `BSATN.Runtime`. |
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,6 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<BaseOutputPath>bin~</BaseOutputPath> | ||
<BaseIntermediateOutputPath>obj~</BaseIntermediateOutputPath> | ||
</PropertyGroup> | ||
</Project> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.