Skip to content

Commit

Permalink
Merge pull request #48 from truenas/bump-script
Browse files Browse the repository at this point in the history
add script for version bump
  • Loading branch information
stavros-k authored Aug 29, 2024
2 parents 219b180 + 1314a45 commit 8063cdb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
54 changes: 54 additions & 0 deletions apps_ci/scripts/bump_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
import argparse
import os
import pathlib
import yaml

from apps_ci.version_bump import map_renovate_bump_type, bump_version, rename_versioned_dir
from apps_exceptions import AppDoesNotExist, ValidationErrors


def update_app_version(app_path: str, bump_type: str) -> None:
if not os.path.exists(app_path):
raise AppDoesNotExist(app_path)

verrors = ValidationErrors()
app_dir = pathlib.Path(app_path)
app_metadata_file = app_dir / 'app.yaml'
if not app_metadata_file.is_file():
verrors.add('app_metadata', 'app.yaml file is missing')

verrors.check()

with open(str(app_metadata_file), 'r') as f:
app_config = yaml.safe_load(f.read())

old_version = app_config['version']
app_config['version'] = bump_version(old_version, bump_type)
rename_versioned_dir(old_version, app_config['version'], app_dir.parent.name, app_dir)

with open(str(app_metadata_file), 'w') as f:
f.write(yaml.safe_dump(app_config))

print(
f'[\033[92mOK\x1B[0m]\tUpdated app {app_dir.name!r} version from {old_version!r} to {app_config["version"]!r}'
)


def main():
parser = argparse.ArgumentParser()
parser.add_argument('--path', help='Specify path of the app to be updated')
parser.add_argument(
'--bump', type=map_renovate_bump_type,
help='Version bump type for app that the hash was updated'
)

args = parser.parse_args()
if not args.path or not args.bump:
parser.print_help()
else:
update_app_version(args.path, args.bump)


if __name__ == '__main__':
main()
4 changes: 4 additions & 0 deletions apps_ci/version_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from apps_exceptions import AppDoesNotExist, ValidationErrors


def map_renovate_bump_type(bump: str) -> str:
return bump if bump in ('patch', 'minor', 'major') else 'patch'


def is_valid_version(version: str) -> bool:
return isinstance(version, str) and version.count('.') == 2

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
platforms='any',
entry_points={
'console_scripts': [
'app_bump_version = apps_ci.scripts.bump_version:main',
'apps_catalog_hash_generate = catalog_reader.scripts.apps_hashes:main',
'apps_catalog_update = apps_ci.scripts.catalog_update:main',
'apps_catalog_validate = apps_validation.scripts.catalog_validate:main',
Expand Down

0 comments on commit 8063cdb

Please sign in to comment.