diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f70b677ac0c..46627105cc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,14 @@ jobs: with: global-json-file: global.json + - name: Override NuGet packages + shell: bash + run: | + dotnet pack -c Release crates/bindings-csharp/BSATN.Runtime + dotnet pack -c Release crates/bindings-csharp/Runtime + cd sdks/csharp + ./tools~/write-nuget-config.sh ../.. + # nodejs and pnpm are required for the typescript quickstart smoketest - name: Set up Node.js uses: actions/setup-node@v4 @@ -571,6 +579,10 @@ jobs: cd sdks/csharp ./tools~/write-nuget-config.sh ../.. + - name: Restore .NET solution + working-directory: sdks/csharp + run: dotnet restore --configfile NuGet.Config SpacetimeDB.ClientSDK.sln + # Now, setup the Unity tests. - name: Patch spacetimedb dependency in Cargo.toml working-directory: demo/Blackholio/server-rust @@ -693,9 +705,13 @@ jobs: cd sdks/csharp ./tools~/write-nuget-config.sh ../.. + - name: Restore .NET solution + working-directory: sdks/csharp + run: dotnet restore --configfile NuGet.Config SpacetimeDB.ClientSDK.sln + - name: Run .NET tests working-directory: sdks/csharp - run: dotnet test -warnaserror + run: dotnet test -warnaserror --no-restore - name: Verify C# formatting working-directory: sdks/csharp diff --git a/sdks/csharp/tools~/write-nuget-config.sh b/sdks/csharp/tools~/write-nuget-config.sh index 7849ed08a96..aabae5a19e3 100755 --- a/sdks/csharp/tools~/write-nuget-config.sh +++ b/sdks/csharp/tools~/write-nuget-config.sh @@ -10,14 +10,16 @@ cd .. # available. # 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 <NuGet.Config < + + @@ -36,5 +38,33 @@ cat >nuget.config < EOF -echo "Wrote nuget.config contents:" -cat nuget.config +cat >"${SPACETIMEDB_REPO_PATH}/NuGet.Config" < + + + + + + + + + + + + + + + + + + + + + + + + +EOF + +echo "Wrote sdks/csharp/NuGet.Config contents:" +cat NuGet.Config diff --git a/smoketests/tests/quickstart.py b/smoketests/tests/quickstart.py index 254db8bed04..18696caae0c 100644 --- a/smoketests/tests/quickstart.py +++ b/smoketests/tests/quickstart.py @@ -57,6 +57,18 @@ def load_nuget_config(p: Path): return xmltodict.parse(f.read(), force_list=["add", "packageSource", "package"]) return {} + +def _nuget_config_path(project_dir: Path) -> Path: + p_upper = project_dir / "NuGet.Config" + if p_upper.exists(): + return p_upper + + p_lower = project_dir / "nuget.config" + if p_lower.exists(): + return p_lower + + return p_upper + def save_nuget_config(p: Path, doc: dict): # Write back (pretty, UTF-8, no BOM) xml = xmltodict.unparse(doc, pretty=True) @@ -66,8 +78,8 @@ def add_source(doc: dict, *, key: str, path: str) -> None: cfg = doc.setdefault("configuration", {}) sources = cfg.setdefault("packageSources", {}) source_entries = sources.setdefault("add", []) - source = {"@key": key, "@value": path} - source_entries.append(source) + + source_entries.append({"@key": key, "@value": str(path)}) def add_mapping(doc: dict, *, key: str, pattern: str) -> None: cfg = doc.setdefault("configuration", {}) @@ -90,12 +102,25 @@ def add_mapping(doc: dict, *, key: str, pattern: str) -> None: def override_nuget_package(*, project_dir: Path, package: str, source_dir: Path, build_subdir: str): """Override nuget config to use a local NuGet package on a .NET project""" # Make sure the local package is built - run_cmd("dotnet", "pack", cwd=source_dir) + repo_nuget_config = STDB_DIR / "NuGet.Config" + if repo_nuget_config.exists(): + run_cmd( + "dotnet", + "restore", + "--configfile", + str(repo_nuget_config), + cwd=source_dir, + capture_stderr=True, + ) + run_cmd("dotnet", "pack", "-c", "Release", "--no-restore", cwd=source_dir) + else: + run_cmd("dotnet", "pack", "-c", "Release", cwd=source_dir) - p = Path(project_dir) / "nuget.config" + p = _nuget_config_path(Path(project_dir)) doc = load_nuget_config(p) add_source(doc, key=package, path=source_dir/build_subdir) add_mapping(doc, key=package, pattern=package) + add_source(doc, key="nuget.org", path="https://api.nuget.org/v3/index.json") # Fallback for other packages add_mapping(doc, key="nuget.org", pattern="*") save_nuget_config(p, doc)