Skip to content

Commit

Permalink
Merge pull request #313 from DimitarNestorov/fetchurl-with-version-regex
Browse files Browse the repository at this point in the history
fix `fetchurl` with `--version-regex`
  • Loading branch information
Mic92 authored Jan 4, 2025
2 parents a292264 + 5577446 commit b13ad79
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def replace_version(package: Package) -> bool:
break
with fileinput.FileInput(package.filename, inplace=True) as f:
for i, line in enumerate(f, 1):
if package.new_version.rev:
if package.rev is not None and package.new_version.rev:
line = line.replace(old_rev_tag, package.new_version.rev)
if (
not version_string_in_version_declaration
Expand Down
40 changes: 40 additions & 0 deletions tests/test_version_regex_no_rev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import subprocess

import conftest

from pathlib import Path
from nix_update import main

def test_main(helpers: conftest.Helpers) -> None:
with helpers.testpkgs(init_git=True) as path:
main(["--file", str(path), "--commit", "net-news-wire", "--version-regex", "^mac-(\\d+\\.\\d+\\.\\d+)$"])
version = get_nix_value(path, "net-news-wire.version")
src = get_nix_value(path, "net-news-wire.src")
commit = subprocess.run(
["git", "-C", path, "show"],
text=True,
stdout=subprocess.PIPE,
check=True,
).stdout.strip()
print(commit)
assert src != "/nix/store/8k7nkbk4xbxwc6zc2bp85i8pvbvzzx6a-NetNewsWire6.1.5.zip"
assert version != "6.1.5"
assert version in commit
assert "net-news-wire: 6.1.5 ->" in commit

def get_nix_value(path: Path, key: str) -> str:
return subprocess.run(
[
"nix",
"eval",
"--raw",
"--extra-experimental-features",
"nix-command",
"-f",
path,
key,
],
check=True,
text=True,
stdout=subprocess.PIPE,
).stdout.strip()
1 change: 1 addition & 0 deletions tests/testpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
pypi = pkgs.python3.pkgs.callPackage ./pypi.nix { };
sourcehut = pkgs.python3.pkgs.callPackage ./sourcehut.nix { };
savanna = pkgs.python3.pkgs.callPackage ./savanna.nix { };
net-news-wire = pkgs.callPackage ./net-news-wire.nix { };
npm = pkgs.callPackage ./npm.nix { };
npm-package = pkgs.callPackage ./npm-package.nix { };
npm-lock-generate = pkgs.callPackage ./npm-lock-generate { };
Expand Down
15 changes: 15 additions & 0 deletions tests/testpkgs/net-news-wire.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
stdenvNoCC,
fetchurl,
nix-update-script,
}:

stdenvNoCC.mkDerivation rec {
pname = "net-news-wire";
version = "6.1.5";

src = fetchurl {
url = "https://github.com/Ranchero-Software/NetNewsWire/releases/download/mac-${version}/NetNewsWire${version}.zip";
hash = "sha256-92hsVSEpa661qhebeSd5lxt8MtIJRn7YZyKlMs0vle0=";
};
}

0 comments on commit b13ad79

Please sign in to comment.