Skip to content

Commit

Permalink
test: Add tag assert
Browse files Browse the repository at this point in the history
  • Loading branch information
bennetrr committed Apr 5, 2024
1 parent cdcfff0 commit 135fe34
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
36 changes: 24 additions & 12 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def test_initial(self):
version_name='v0.0.0-pre',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name=None
)

args_beta = ActionArguments(
Expand All @@ -61,7 +62,8 @@ def test_initial(self):
version_name='v0.0.0-beta',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name=None
)

args_prod = ActionArguments(
Expand All @@ -76,7 +78,8 @@ def test_initial(self):
version_name='v0.0.0',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name=None
)

# Act
Expand Down Expand Up @@ -108,7 +111,8 @@ def test_first_fix(self):
version_name='v0.0.1-pre',
previous_version='',
previous_version_name='',
has_changes=True
has_changes=True,
latest_tag_name='v0.0.1-pre'
)

args_beta = ActionArguments(
Expand All @@ -123,7 +127,8 @@ def test_first_fix(self):
version_name='v0.0.1-beta',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name='v0.0.1-beta'
)

args_prod = ActionArguments(
Expand All @@ -138,7 +143,8 @@ def test_first_fix(self):
version_name='v0.0.1',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name='v0.0.1'
)

# Act
Expand Down Expand Up @@ -172,7 +178,8 @@ def test_first_feature(self):
version_name='v0.1.0-pre',
previous_version='',
previous_version_name='',
has_changes=True
has_changes=True,
latest_tag_name='v0.1.0-pre'
)

args_beta = ActionArguments(
Expand All @@ -187,7 +194,8 @@ def test_first_feature(self):
version_name='v0.1.0-beta',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name='v0.1.0-beta'
)

args_prod = ActionArguments(
Expand All @@ -202,7 +210,8 @@ def test_first_feature(self):
version_name='v0.1.0',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name='v0.1.0'
)

# Act
Expand Down Expand Up @@ -236,7 +245,8 @@ def test_first_breaking(self):
version_name='v1.0.0-pre',
previous_version='',
previous_version_name='',
has_changes=True
has_changes=True,
latest_tag_name='v1.0.0-pre'
)

args_beta = ActionArguments(
Expand All @@ -251,7 +261,8 @@ def test_first_breaking(self):
version_name='v1.0.0-beta',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name='v1.0.0-beta'
)

args_prod = ActionArguments(
Expand All @@ -266,7 +277,8 @@ def test_first_breaking(self):
version_name='v1.0.0',
previous_version='',
previous_version_name='',
has_changes=False
has_changes=False,
latest_tag_name='v1.0.0'
)

# Act
Expand Down
12 changes: 11 additions & 1 deletion tests/utils/action_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from pathlib import Path
from typing import Any

from git import Repo

logger = logging.getLogger('wemogy.get-release-version-action.tests.wrapper')


Expand Down Expand Up @@ -57,6 +59,9 @@ class ActionOutputs:
has_changes: bool
"""If any relevant changes got detected."""

latest_tag_name: str | None
"""The name of the newest git tag or None, if no tags exist."""

@classmethod
def from_github_output(cls, github_output_file: Path):
lines = github_output_file.read_text().splitlines()
Expand All @@ -77,7 +82,12 @@ def from_github_output(cls, github_output_file: Path):

ctor_args[name] = value

return cls(**ctor_args)
try:
latest_tag_name = sorted(Repo(os.getcwd()).tags, key=lambda t: t.commit.committed_datetime, reverse=True)[0].name
except IndexError:
latest_tag_name = None

return cls(**ctor_args, latest_tag_name=latest_tag_name)


def run_action(args: ActionArguments, python_executable: Path = None, python_path: Path = None, script_path: Path = None) -> ActionOutputs:
Expand Down

0 comments on commit 135fe34

Please sign in to comment.