diff --git a/pyproject.toml b/pyproject.toml index d3df7ab..643a112 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,3 +14,4 @@ dependencies = [ [project.scripts] gitea-release-action = "main:main_cli" +increment-version = "increment_version:main_cli" diff --git a/src/increment_version.py b/src/increment_version.py new file mode 100755 index 0000000..11cd59a --- /dev/null +++ b/src/increment_version.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +from argparse import ArgumentParser + +import yaml + +from release import versioning +from release.project import parse_project_description + + +def main_cli(): + parser = ArgumentParser() + parser.add_argument( + '--release-yaml-filename', default='.gitea/release.yaml') + + bump_group = parser.add_mutually_exclusive_group() + bump_group.add_argument('--major', action='store_true') + bump_group.add_argument('--minor', action='store_true') # the default + bump_group.add_argument('--patch', action='store_true') + + args = parser.parse_args() + + with open(args.release_yaml_filename, 'r') as f: + project_description = parse_project_description( + yaml.safe_load(f)) + + version = versioning.use_any(project_description.version_descriptor) + + if args.major: + version.version = version.version.bump_major() + elif args.minor: + version.version = version.version.bump_minor() + elif args.patch: + version.version = version.version.bump_patch() + else: + version.version = version.version.bump_minor() + + print(f'incremented version: {version.version}') + version.store() + + +if __name__ == '__main__': + main_cli()