Skip to content

Commit affa2af

Browse files
authored
Add script to generate nuget.config (#115)
## Description of Changes Adds a utility script to generate `nuget.config` given a path to the `SpacetimeDB` repo. ## API No ## Requires SpacetimeDB PRs None ## Testing - [x] CI - [x] Ran locally --------- Co-authored-by: Zeke Foppa <[email protected]>
1 parent fa87e36 commit affa2af

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

sdks/csharp/.github/workflows/dotnet.yml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,9 @@ jobs:
3636
# available. Otherwise, `spacetimedb-csharp-sdk` will use the NuGet versions of the packages.
3737
# This means that (if version numbers match) we will test the local versions of the C# packages, even
3838
# if they're not pushed to NuGet.
39-
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file,
40-
# and https://tldp.org/LDP/abs/html/here-docs.html for more info on this bash feature.
41-
cat >nuget.config <<EOF
42-
<?xml version="1.0" encoding="utf-8"?>
43-
<configuration>
44-
<packageSources>
45-
<!-- Local NuGet repositories -->
46-
<add key="Local SpacetimeDB.BSATN.Runtime" value="../SpacetimeDB/crates/bindings-csharp/BSATN.Runtime/bin/Release" />
47-
</packageSources>
48-
<packageSourceMapping>
49-
<!-- Ensure that SpacetimeDB.BSATN.Runtime is used from the local folder. -->
50-
<!-- Otherwise we risk an outdated version being quietly pulled from NuGet for testing. -->
51-
<packageSource key="Local SpacetimeDB.BSATN.Runtime">
52-
<package pattern="SpacetimeDB.BSATN.Runtime" />
53-
</packageSource>
54-
<!-- Fallback for other packages (e.g. test deps). -->
55-
<packageSource key="nuget.org">
56-
<package pattern="*" />
57-
</packageSource>
58-
</packageSourceMapping>
59-
</configuration>
60-
EOF
39+
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file.
40+
./tools~/write-nuget-config.sh ../SpacetimeDB
41+
6142
- name: Restore dependencies
6243
working-directory: spacetimedb-csharp-sdk
6344
run: dotnet restore

sdks/csharp/tests~/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Running tests
2+
You can use `dotnet test` (either in this directory or in the project root directory) to run the tests.
3+
4+
# Using a different SpacetimeDB version
5+
To run tests using a local version of the `SpacetimeDB` repo, you can add a `nuget.config` file in the **root** of this repository.
6+
7+
The `tools/write-nuget-config.sh` script can generate the `nuget.config`. It takes one parameter: the path to the root SpacetimeDB repository (relative or absolute).
8+
9+
Then, you need to `dotnet pack` the `BSATN.Runtime` package in the `SpacetimeDB` repo.
10+
11+
Lastly, before running `dotnet test`, you should `dotnet nuget locals all --clear` to clear out any cached packages. This ensures you're actually testing with the new package you just built.
12+
13+
Example:
14+
```bash
15+
$ export SPACETIMEDB_REPO_PATH="../SpacetimeDB"
16+
$ tools/write-nuget-config.sh "${SPACETIMEDB_REPO_PATH}"
17+
$ ( cd "${SPACETIMEDB_REPO_PATH}"/crates/bindings-csharp/BSATN.Runtime && dotnet pack )
18+
$ dotnet nuget locals all --clear
19+
$ dotnet test
20+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
set -ueo pipefail
2+
3+
SPACETIMEDB_REPO_PATH="$1"
4+
5+
cd "$(dirname "$(readlink -f "$0")")"
6+
cd ..
7+
8+
# Write out the nuget config file to `nuget.config`. This causes the spacetimedb-csharp-sdk repository
9+
# to be aware of the local versions of the `bindings-csharp` packages in SpacetimeDB, and use them if
10+
# available.
11+
# See https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file for more info on the config file,
12+
# and https://tldp.org/LDP/abs/html/here-docs.html for more info on this bash feature.
13+
cat >nuget.config <<EOF
14+
<?xml version="1.0" encoding="utf-8"?>
15+
<configuration>
16+
<packageSources>
17+
<!-- Local NuGet repositories -->
18+
<add key="Local SpacetimeDB.BSATN.Runtime" value="${SPACETIMEDB_REPO_PATH}/crates/bindings-csharp/BSATN.Runtime/bin/Release" />
19+
</packageSources>
20+
<packageSourceMapping>
21+
<!-- Ensure that SpacetimeDB.BSATN.Runtime is used from the local folder. -->
22+
<!-- Otherwise we risk an outdated version being quietly pulled from NuGet for testing. -->
23+
<packageSource key="Local SpacetimeDB.BSATN.Runtime">
24+
<package pattern="SpacetimeDB.BSATN.Runtime" />
25+
</packageSource>
26+
<!-- Fallback for other packages (e.g. test deps). -->
27+
<packageSource key="nuget.org">
28+
<package pattern="*" />
29+
</packageSource>
30+
</packageSourceMapping>
31+
</configuration>
32+
EOF
33+
34+
echo "Wrote nuget.config contents:"
35+
cat nuget.config

0 commit comments

Comments
 (0)