Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Extend] version-automation to rockcraft.yaml #636

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
53 changes: 53 additions & 0 deletions updatesnap/SnapVersionModule/snap_version_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ def process_snap_version_data(upstreamversion, snap_name, version_schema, has_up
return f"{upstreamversion}-{packagerelease}"


def process_rock_version_data(upstreamversion, prevversion, version_schema, has_update):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upstream_version and previous_version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

""" Returns processed rock version"""

match = re.match(version_schema, upstreamversion)
if not match:
logging.warning("Version schema does not match with rock repository version")
return None
upstreamversion = match.group(1).replace('_', '.')

def version_tuple(v):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to create a function just for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed function and now using inline tuple to resolve version

return tuple(map(int, v.split('.')))

upstream_tuple = version_tuple(upstreamversion)
prev_tuple = version_tuple(prevversion.split('-')[0])

if upstream_tuple > prev_tuple:
return f"{upstreamversion}-1"
# Determine package release number
if has_update:
packagerelease = int(prevversion.split('-')[-1]) + 1
else:
packagerelease = int(prevversion.split('-')[-1])

return f"{upstreamversion}-{packagerelease}"


def is_version_update(snap, manager_yaml, arguments, has_update):
""" Returns if snap version update available """
has_version_update = False
Expand All @@ -87,3 +113,30 @@ def is_version_update(snap, manager_yaml, arguments, has_update):
version_file.write(f"{snap_version}")

return has_version_update


def is_rock_version_update(rock, manager_yaml, arguments, has_update):
""" Returns if rock version update available """
has_version_update = False
if arguments.rock_version_schema == 'None':
return False
metadata = rock.process_metadata()
rock_version = process_rock_version_data(metadata['upstream-version'], metadata['version'],
arguments.rock_version_schema, has_update)
if rock_version is None:
return False
if metadata['version'] != rock_version:
rock_version_data = manager_yaml.get_part_metadata('version')
if rock_version_data is not None:
logging.info("Updating rock version from %s to %s",
metadata['version'], rock_version)
rock_version_data['data'] = f"version: '{rock_version}'"
has_version_update = True
else:
logging.warning("Version is not defined in metadata")

if has_version_update:
with open('version_file', 'w', encoding="utf8") as version_file:
version_file.write(f"{rock_version}")

return has_version_update
7 changes: 5 additions & 2 deletions updatesnap/updatesnapyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
from SnapModule.snapmodule import Snapcraft, Github
from SnapModule.manageYAML import ManageYAML
from SnapVersionModule.snap_version_module import is_version_update
from SnapVersionModule.snap_version_module import is_version_update, is_rock_version_update
UPDATE_BRANCH = 'update_versions'


Expand Down Expand Up @@ -74,6 +74,8 @@ def main():
help='Access token for accesing Github projects.')
parser.add_argument('--version-schema', action='store', default='None',
help='Version schema of snapping repository')
parser.add_argument('--rock-version-schema', action='store', default='None',
help='Version schema of rock repository')
parser.add_argument('--verbose', action='store_true', default=False)
parser.add_argument('project', default='.', help='The project URI')
arguments = parser.parse_args(sys.argv[1:])
Expand Down Expand Up @@ -124,7 +126,8 @@ def main():
has_update = True

logging.basicConfig(level=logging.INFO)
if (is_version_update(snap, manager_yaml, arguments, has_update) or has_update):
if (is_version_update(snap, manager_yaml, arguments, has_update) or
is_rock_version_update(snap, manager_yaml, arguments, has_update) or has_update):
with open('output_file', 'w', encoding="utf8") as output_file:
output_file.write(manager_yaml.get_yaml())
else:
Expand Down
Loading