Skip to content

Commit

Permalink
Merge pull request #283 from patka-123/build-composer-project-v2
Browse files Browse the repository at this point in the history
Add support for new Composer builder
  • Loading branch information
Mic92 authored Sep 29, 2024
2 parents c1ef5aa + 2278b7d commit d033f05
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 16 deletions.
4 changes: 3 additions & 1 deletion nix_update/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Package:
pnpm_deps: str | None
yarn_deps: str | None
composer_deps: str | None
composer_deps_old: str | None
maven_deps: str | None
mix_deps: str | None
tests: list[str]
Expand Down Expand Up @@ -185,7 +186,8 @@ def eval_expression(
if res.success then res.value.file else false
else
null;
composer_deps = pkg.composerRepository.outputHash or null;
composer_deps = pkg.composerVendor.outputHash or null;
composer_deps_old = pkg.composerRepository.outputHash or null;
npm_deps = pkg.npmDeps.outputHash or null;
pnpm_deps = pkg.pnpmDeps.outputHash or null;
yarn_deps = pkg.offlineCache.outputHash or null;
Expand Down
12 changes: 12 additions & 0 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ def disable_copystat():


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


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

Expand Down Expand Up @@ -467,6 +474,11 @@ def update(opts: Options) -> Package:
if package.composer_deps:
update_composer_deps_hash(opts, package.filename, package.composer_deps)

if package.composer_deps_old:
update_composer_deps_hash_old(
opts, package.filename, package.composer_deps_old
)

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

Expand Down
11 changes: 2 additions & 9 deletions tests/test_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@

from nix_update.options import Options
from nix_update.update import update
from nix_update.version.version import VersionPreference


def test_update(helpers: conftest.Helpers) -> None:
with helpers.testpkgs() as path:
opts = Options(
attribute="composer",
import_path=str(path),
# For 0.14.0 we get inconsistent lock file errors
version="0.13.1",
version_preference=VersionPreference.FIXED,
)
opts = Options(attribute="composer", import_path=str(path))
update(opts)
version = subprocess.run(
[
Expand All @@ -31,4 +24,4 @@ def test_update(helpers: conftest.Helpers) -> None:
text=True,
stdout=subprocess.PIPE,
).stdout.strip()
assert tuple(map(int, version.split("."))) >= (0, 11, 1)
assert tuple(map(int, version.split("."))) >= (11, 3, 1)
34 changes: 34 additions & 0 deletions tests/test_composer_old.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import subprocess

import conftest

from nix_update.options import Options
from nix_update.update import update
from nix_update.version.version import VersionPreference


def test_update(helpers: conftest.Helpers) -> None:
with helpers.testpkgs() as path:
opts = Options(
attribute="composer-old",
import_path=str(path),
# For 0.14.0 we get inconsistent lock file errors
version="0.13.1",
version_preference=VersionPreference.FIXED,
)
update(opts)
version = subprocess.run(
[
"nix",
"eval",
"--raw",
"--extra-experimental-features",
"nix-command",
"-f",
path,
"composer-old.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-old.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=";
})
12 changes: 6 additions & 6 deletions tests/testpkgs/composer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
, php
}:

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

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

Expand Down
1 change: 1 addition & 0 deletions tests/testpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
cargoLock.generate.with-lockfile-metadata-path-outside-workspace = pkgs.callPackage ./cargo-lock-generate/with-lockfile-metadata-path-outside-workspace { };
cargoLock.update = pkgs.callPackage ./cargo-lock-update { };
composer = pkgs.callPackage ./composer.nix { };
composer-old = pkgs.callPackage ./composer-old.nix { };
crate = pkgs.callPackage ./crate.nix { };
gitea = pkgs.callPackage ./gitea.nix { };
github = pkgs.callPackage ./github.nix { };
Expand Down

0 comments on commit d033f05

Please sign in to comment.