Skip to content
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
4 changes: 4 additions & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Unreleased

## Features

* #485: Improved nox task `release:trigger`
3 changes: 1 addition & 2 deletions exasol/toolbox/nox/_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ 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")

run("git", "tag", str(release_version))
run("git", "push", "origin", str(release_version))
Expand Down
112 changes: 21 additions & 91 deletions test/unit/release_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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"),
],
Expand Down Expand Up @@ -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)