Skip to content

Commit

Permalink
Merge pull request #48 from wemogy/fix/action
Browse files Browse the repository at this point in the history
Fix action errors
  • Loading branch information
Bennet Ranft authored Mar 22, 2024
2 parents ad6f0f5 + 25650c6 commit ffdcb59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 4 additions & 8 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ inputs:
suffix:
description: "The suffix that should appended to the version."
required: false
default: ""
default: "NONE"
previous-version-suffix:
description: "The suffix that should be replaced with the value in `suffix`."
required: false
default: ""
default: "NONE"
bumping-suffix:
description: "The suffix to append to the version (or increment if it already exists) if `only-bump-suffix` is `true`."
required: false
Expand Down Expand Up @@ -45,15 +45,11 @@ runs:
- ${{ inputs.prefix }}
- --suffix
- ${{ inputs.suffix }}
- --only-increase-suffix
- ${{ inputs.only-increase-suffix }}
- --only-replace-suffix-with
- ${{ inputs.only-replace-suffix-with }}
- --create-tag
- ${{ inputs.create-tag }}
- --previous-version-suffix
- ${{ inputs.previous-version-suffix }}
- --bumping-suffix
- ${{ inputs.bumping-suffix }}
- --only-bump-suffix
- ${{ inputs.only-bump-suffix }}
- --create-tag
- ${{ inputs.create-tag }}
16 changes: 11 additions & 5 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def parse_bool(string: str) -> bool:

def nullable_string(string: str) -> str | None:
"""Return None if the string is empty or only contains whitespace characters."""
if string.strip() == '':
if string.strip() == '' or string == 'NONE':
return None
return string

Expand Down Expand Up @@ -117,15 +117,15 @@ def run_command(*command: str | bytes | os.PathLike[str] | os.PathLike[bytes]) -
return process.stdout


def get_current_version_tag(repo: git.Repo, prefix: str, suffix: str) -> git.TagReference | None:
def get_current_version_tag(repo: git.Repo, prefix: str, suffix: str | None) -> git.TagReference | None:
"""
Get the current version (= the latest git tag).
If there are no tags, return None.
"""
# Reverse the list of tags to start with the most recent one
for tag in sorted(repo.tags, key=lambda t: t.commit.committed_datetime, reverse=True):
# Check if the tag name starts with the specified prefix
if tag.name.startswith(prefix) and suffix in tag.name:
if tag.name.startswith(prefix) and (suffix is None or suffix in tag.name):
logger.debug('Found tag %s (%s)', tag.name, tag.commit.hexsha)
return tag

Expand Down Expand Up @@ -297,6 +297,7 @@ def main() -> None:
'--prefix',
dest='prefix',
type=str,
required=False,
default='v',
help='The prefix that should be prepended to the version.'
)
Expand All @@ -305,22 +306,25 @@ def main() -> None:
'--suffix',
dest='suffix',
type=nullable_string,
default='',
required=False,
default='NONE',
help='The suffix that should be appended to the version (e.g. `beta`).'
)

parser.add_argument(
'--previous-version-suffix',
dest='previous_version_suffix',
type=nullable_string,
default='',
required=False,
default='NONE',
help='The suffix that should be replaced with the value in `suffix`.'
)

parser.add_argument(
'--bumping-suffix',
dest='bumping_suffix',
type=str,
required=False,
default='hotfix',
help='The suffix to append to the version (or increment if it already exists) if `only-bump-suffix` is `true`.'
)
Expand All @@ -329,6 +333,7 @@ def main() -> None:
'--only-bump-suffix',
dest='only_bump_suffix',
type=parse_bool,
required=False,
default='false',
help='Bump the `bumping-suffix` instead of the version if changes were detected.'
)
Expand All @@ -337,6 +342,7 @@ def main() -> None:
'--create-tag',
dest='create_tag',
type=parse_bool,
required=False,
default='true',
help='Create a git tag for the version and push it if a remote is configured.'
)
Expand Down

0 comments on commit ffdcb59

Please sign in to comment.