Skip to content

Commit

Permalink
Merge pull request #320 from gepbird/dotnet-support
Browse files Browse the repository at this point in the history
Add support for updating dotnet packages
  • Loading branch information
Mic92 authored Jan 19, 2025
2 parents 7bf6549 + 58603e3 commit cea66cb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nix_update/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Package:
composer_deps_old: str | None
maven_deps: str | None
mix_deps: str | None
has_nuget_deps: bool
tests: list[str]
has_update_script: bool

Expand Down Expand Up @@ -200,6 +201,7 @@ def eval_expression(
yarn_deps = pkg.yarnOfflineCache.outputHash or null;
yarn_deps_old = pkg.offlineCache.outputHash or null;
maven_deps = pkg.fetchedMavenDeps.outputHash or null;
has_nuget_deps = pkg ? nugetDeps;
mix_deps = pkg.mixFodDeps.outputHash or null;
tests = builtins.attrNames (pkg.passthru.tests or {{}});
has_update_script = {has_update_script};
Expand Down
17 changes: 17 additions & 0 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,20 @@ def update_mix_deps_hash(opts: Options, filename: str, current_hash: str) -> Non
replace_hash(filename, current_hash, target_hash)


def update_nuget_deps(opts: Options) -> None:
fetch_deps_script_path = run(
[
"nix-build",
opts.import_path,
"-A",
f"{opts.attribute}.fetch-deps",
"--no-out-link",
]
).stdout.strip()

run([fetch_deps_script_path])


def update_version(
package: Package, version: str, preference: VersionPreference, version_regex: str
) -> bool:
Expand Down Expand Up @@ -557,6 +571,9 @@ def update(opts: Options) -> Package:
if package.mix_deps:
update_mix_deps_hash(opts, package.filename, package.mix_deps)

if package.has_nuget_deps:
update_nuget_deps(opts)

if isinstance(package.cargo_lock, CargoLockInSource | CargoLockInStore):
if opts.generate_lockfile:
generate_lockfile(opts, package.filename, "cargo")
Expand Down
47 changes: 47 additions & 0 deletions tests/test_nuget_deps_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json
import subprocess

import conftest

from nix_update import main


def test_update(helpers: conftest.Helpers) -> None:
with helpers.testpkgs(init_git=True) as path:
main(
[
"--file",
str(path),
"--commit",
"nuget-deps-generate",
"--version",
"v1.1.1",
]
)

nuget_deps_raw = subprocess.run(
[
"nix",
"eval",
"--json",
"--extra-experimental-features",
"nix-command",
"-f",
path,
"nuget-deps-generate.nugetDeps",
],
check=True,
text=True,
stdout=subprocess.PIPE,
).stdout.strip()
nuget_deps = json.loads(nuget_deps_raw)
assert len(nuget_deps) > 0

diff = subprocess.run(
["git", "-C", path, "log"],
text=True,
stdout=subprocess.PIPE,
check=True,
).stdout.strip()
print(diff)
assert "https://github.com/ExOK/Celeste64/compare/v1.1.0...v1.1.1" in diff
1 change: 1 addition & 0 deletions tests/testpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
cargoVendorDeps.rustPackage = pkgs.callPackage ./cargo-vendor-deps/rust-package.nix { };
composer-old = pkgs.callPackage ./composer-old.nix { };
crate = pkgs.callPackage ./crate.nix { };
nuget-deps-generate = pkgs.callPackage ./nuget-deps-generate { };
gitea = pkgs.callPackage ./gitea.nix { };
github = pkgs.callPackage ./github.nix { };
github-no-release = pkgs.callPackage ./github-no-release.nix { };
Expand Down
18 changes: 18 additions & 0 deletions tests/testpkgs/nuget-deps-generate/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
buildDotnetModule,
fetchFromGitHub,
}:

buildDotnetModule rec {
pname = "celeste64";
version = "1.1.0";

src = fetchFromGitHub {
owner = "ExOK";
repo = "Celeste64";
tag = "v${version}";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};

nugetDeps = ./deps.json;
}
1 change: 1 addition & 0 deletions tests/testpkgs/nuget-deps-generate/deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit cea66cb

Please sign in to comment.