From d7d1ef3134a8dbee9f1fe691b77cb99e80103bce Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 29 Oct 2025 14:06:49 +0100 Subject: [PATCH 1/2] #485: Improved nox task `release:trigger` --- doc/changes/unreleased.md | 4 ++ exasol/toolbox/nox/_release.py | 5 +- test/unit/release_test.py | 112 +++++++-------------------------- 3 files changed, 28 insertions(+), 93 deletions(-) diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index 79e701b84..30c000a0c 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -1 +1,5 @@ # Unreleased + +## Features + +* #485: Improved nox task `release:trigger` diff --git a/exasol/toolbox/nox/_release.py b/exasol/toolbox/nox/_release.py index b0fbf512f..6553034c6 100644 --- a/exasol/toolbox/nox/_release.py +++ b/exasol/toolbox/nox/_release.py @@ -94,10 +94,11 @@ def run(*args: str): release_version: Version = Version.from_poetry() print(f"release version: {release_version}") + run("git", "fetch", "--all") if re.search(rf"{release_version}", run("git", "tag", "--list")): raise ReleaseError(f"tag {release_version} already exists") - if re.search(rf"{release_version}", run("gh", "release", "list")): - raise ReleaseError(f"release {release_version} already exists") + # if re.search(rf"{release_version}", run("gh", "release", "list")): + # raise ReleaseError(f"release {release_version} already exists") run("git", "tag", str(release_version)) run("git", "push", "origin", str(release_version)) diff --git a/test/unit/release_test.py b/test/unit/release_test.py index 3bd344518..2128f271c 100644 --- a/test/unit/release_test.py +++ b/test/unit/release_test.py @@ -29,7 +29,7 @@ class TestTriggerReleaseWithMocking: def _get_mock_string(args) -> str: if args == ("git", "remote", "show", "origin"): return "test\nHEAD branch: main\ntest" - if args in [("git", "tag", "--list"), ("gh", "release", "list")]: + if args == ("git", "tag", "--list"): return "0.1.0\n0.2.0" return "" @@ -50,50 +50,17 @@ def simulate_pass(args, **kwargs): with patch("subprocess.run", side_effect=simulate_pass) as subprocess_mock: result = _trigger_release(noxconfig.PROJECT_CONFIG) - assert subprocess_mock.mock_calls == [ - call( - ("git", "remote", "show", "origin"), - capture_output=True, - text=True, - check=True, - ), - call( - ("git", "checkout", "main"), - capture_output=True, - text=True, - check=True, - ), - call(("git", "pull"), capture_output=True, text=True, check=True), - call( - ("git", "tag", "--list"), capture_output=True, text=True, check=True - ), - call( - ("gh", "release", "list"), - capture_output=True, - text=True, - check=True, - ), - call( - ("git", "tag", "0.3.0"), capture_output=True, text=True, check=True - ), - call( - ("git", "push", "origin", "0.3.0"), - capture_output=True, - text=True, - check=True, - ), - call( - ("git", "tag", "-f", "v0"), - capture_output=True, - text=True, - check=True, - ), - call( - ("git", "push", "-f", "origin", "v0"), - capture_output=True, - text=True, - check=True, - ), + commands = [c.args[0] for c in subprocess_mock.mock_calls] + assert commands == [ + ("git", "remote", "show", "origin"), + ("git", "checkout", "main"), + ("git", "pull"), + ("git", "fetch", "--all"), + ("git", "tag", "--list"), + ("git", "tag", "0.3.0"), + ("git", "push", "origin", "0.3.0"), + ("git", "tag", "-f", "v0"), + ("git", "push", "-f", "origin", "v0"), ] assert result == mock_from_poetry.return_value @@ -106,38 +73,15 @@ def simulate_pass(args, **kwargs): with patch("subprocess.run", side_effect=simulate_pass) as subprocess_mock: result = _trigger_release(DummyConfig) - assert subprocess_mock.mock_calls == [ - call( - ("git", "remote", "show", "origin"), - capture_output=True, - text=True, - check=True, - ), - call( - ("git", "checkout", "main"), - capture_output=True, - text=True, - check=True, - ), - call(("git", "pull"), capture_output=True, text=True, check=True), - call( - ("git", "tag", "--list"), capture_output=True, text=True, check=True - ), - call( - ("gh", "release", "list"), - capture_output=True, - text=True, - check=True, - ), - call( - ("git", "tag", "0.3.0"), capture_output=True, text=True, check=True - ), - call( - ("git", "push", "origin", "0.3.0"), - capture_output=True, - text=True, - check=True, - ), + commands = [c.args[0] for c in subprocess_mock.mock_calls] + assert commands == [ + ("git", "remote", "show", "origin"), + ("git", "checkout", "main"), + ("git", "pull"), + ("git", "fetch", "--all"), + ("git", "tag", "--list"), + ("git", "tag", "0.3.0"), + ("git", "push", "origin", "0.3.0"), ] assert result == mock_from_poetry.return_value @@ -148,7 +92,6 @@ def simulate_pass(args, **kwargs): ("git", "checkout", "main"), ("git", "pull"), ("git", "tag", "--list"), - ("gh", "release", "list"), ("git", "tag", "0.3.0"), ("git", "push", "origin", "0.3.0"), ], @@ -189,16 +132,3 @@ def simulate_fail(args, **kwargs): with pytest.raises(ReleaseError) as ex: _trigger_release(noxconfig.PROJECT_CONFIG) assert f"tag {version} already exists" in str(ex) - - def test_release_already_exists(self, mock_from_poetry): - version = mock_from_poetry.return_value - - def simulate_fail(args, **kwargs): - if args == ("gh", "release", "list"): - return MagicMock(returncode=0, stdout=f"0.1.0\n0.2.0\n{version}") - return self._get_subprocess_run_mock(args) - - with patch("subprocess.run", side_effect=simulate_fail): - with pytest.raises(ReleaseError) as ex: - _trigger_release(noxconfig.PROJECT_CONFIG) - assert f"release {version} already exists" in str(ex) From b72abd145316d8f4cb4ef3f0a60ddfa2cd03f1f0 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 29 Oct 2025 14:08:40 +0100 Subject: [PATCH 2/2] Removed dead code --- exasol/toolbox/nox/_release.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/exasol/toolbox/nox/_release.py b/exasol/toolbox/nox/_release.py index 6553034c6..922a1f00a 100644 --- a/exasol/toolbox/nox/_release.py +++ b/exasol/toolbox/nox/_release.py @@ -97,8 +97,6 @@ def run(*args: str): run("git", "fetch", "--all") if re.search(rf"{release_version}", run("git", "tag", "--list")): raise ReleaseError(f"tag {release_version} already exists") - # if re.search(rf"{release_version}", run("gh", "release", "list")): - # raise ReleaseError(f"release {release_version} already exists") run("git", "tag", str(release_version)) run("git", "push", "origin", str(release_version))