Skip to content
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

Add support for updating buildComposerProject's vendorHash #217

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ venv/
ENV/
env.bak/
venv.bak/
.direnv

# Spyder project settings
.spyderproject
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ designed to work with nixpkgs but also other package sets.
- update buildRustPackage's cargoHash/cargoSha256 and cargoSetupHook's cargoDeps
- update buildGoModule's vendorHash/vendorSha256
- update buildNpmPackage's npmDepsHash and npmConfigHook's npmDeps
- update buildComposerProject's vendorHash
- update fetchYarnDeps offlineCache output hash
- update flake outputs (see `--flake`)
- build and run the resulting package (see `--build`,
Expand Down
2 changes: 2 additions & 0 deletions nix_update/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Package:
cargo_deps: str | None
npm_deps: str | None
yarn_deps: str | None
composer_deps: str | None
tests: list[str]
has_update_script: bool

Expand Down Expand Up @@ -157,6 +158,7 @@ def eval_expression(
if res.success then res.value.file else false
else
null;
composer_deps = pkg.composerRepository.outputHash or null;
npm_deps = pkg.npmDeps.outputHash or null;
yarn_deps = pkg.offlineCache.outputHash or null;
tests = builtins.attrNames (pkg.passthru.tests or {{}});
Expand Down
8 changes: 8 additions & 0 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ def update_cargo_lock(
print(line, end="")


def update_composer_deps_hash(opts: Options, filename: str, current_hash: str) -> None:
target_hash = nix_prefetch(opts, "composerRepository")
replace_hash(filename, current_hash, target_hash)


def print_hashes(hashes: dict[str, str], indent: str) -> None:
if not hashes:
return
Expand Down Expand Up @@ -367,6 +372,9 @@ def update(opts: Options) -> Package:
):
update_cargo_lock(opts, package.filename, package.cargo_lock)

if package.composer_deps:
update_composer_deps_hash(opts, package.filename, package.composer_deps)

if package.npm_deps:
update_npm_deps_hash(opts, package.filename, package.npm_deps)

Expand Down
27 changes: 27 additions & 0 deletions tests/test_composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess

import conftest

from nix_update.options import Options
from nix_update.update import update


def test_update(helpers: conftest.Helpers) -> None:
with helpers.testpkgs() as path:
opts = Options(attribute="composer", import_path=str(path))
update(opts)
version = subprocess.run(
[
"nix",
"eval",
"--raw",
"--extra-experimental-features",
"nix-command",
"-f",
path,
"composer.version",
],
text=True,
stdout=subprocess.PIPE,
).stdout.strip()
assert tuple(map(int, version.split("."))) >= (0, 11, 1)
17 changes: 17 additions & 0 deletions tests/testpkgs/composer.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ fetchFromGitHub
, php
}:

php.buildComposerProject (finalAttrs: {
pname = "castor";
version = "0.10.0";

src = fetchFromGitHub {
owner = "jolicode";
repo = "castor";
rev = "v${finalAttrs.version}";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};

vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
})
1 change: 1 addition & 0 deletions tests/testpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
bitbucket-snapshot = pkgs.callPackage ./bitbucket.nix { isSnapshot = true; };
cargoLock.expand = pkgs.callPackage ./cargo-lock-expand { };
cargoLock.update = pkgs.callPackage ./cargo-lock-update { };
composer = pkgs.callPackage ./composer.nix { };
crate = pkgs.callPackage ./crate.nix { };
gitea = pkgs.callPackage ./gitea.nix { };
github = pkgs.callPackage ./github.nix { };
Expand Down