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

[Fixes] git module import error #524

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion .github/workflows/updatesnaptests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
python3 -m pip install pyyaml
python3 -m pip install python-debian
python3 -m pip install packaging
python3 -m pip install gitpython
- name: Code tests
env:
GITHUB_USER: ubuntu
Expand Down
6 changes: 0 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ runs:
ref: stable
path: desktop-snaps

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install gitpython
shell: bash

# Step to run the script that will generate a new output_file with an updated tag, if one is available. If there was a change, then we move this to the snapcraft.yaml and note that there was a change.
- name: run updatesnapyaml
id: updatesnapyaml
Expand Down
8 changes: 6 additions & 2 deletions updatesnap/SnapModule/snapmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def process_part(self, part: str) -> Optional[dict]:
"missing_format": False,
"updates": [],
"version_format": {},
"source_url": None,
"source_tag": None,
}

if self._config is None:
Expand All @@ -685,6 +685,8 @@ def process_part(self, part: str) -> Optional[dict]:
else:
current_tag = None

part_data['source_tag'] = current_tag

version_format = data['version-format'] if ('version-format' in data) else {}

if ('ignore' in version_format) and (version_format['ignore']):
Expand Down Expand Up @@ -915,7 +917,9 @@ def process_metadata(self) -> Optional[dict]:
upstream_data = self.process_part(data['adopt-info'])
metadata['upstream-url'] = upstream_data['source_url']
if len(upstream_data['updates']) != 0:
metadata['upstream-version'] = upstream_data['updates'][0]
metadata['upstream-version'] = upstream_data['updates'][0]['name']
else:
metadata['upstream-version'] = upstream_data['source_tag']

if 'grade' in data:
metadata['grade'] = data['grade']
Expand Down
38 changes: 10 additions & 28 deletions updatesnap/SnapVersionModule/snap_version_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
to the package result in an increment of the package release number by 1 """

import subprocess
import os
import shutil
import re
from datetime import datetime
import logging
import requests
import git


def process_snap_version_data(git_repo_url, snap_name, version_schema):
def process_snap_version_data(upstreamversion, snap_name, version_schema, has_update):
""" Returns processed snap version and grade """

# Time stamp of Snap build in Snap Store
Expand Down Expand Up @@ -47,49 +44,34 @@ def process_snap_version_data(git_repo_url, snap_name, version_schema):
next((channel["version"] for channel in snap_info["channel-map"]
if channel["channel"]["name"] == "edge"))
)
# Clone the leading upstream repository if it doesn't exist
repo_dir = os.path.basename(git_repo_url.rstrip('.git'))
if not os.path.exists(repo_dir):
try:
git.Repo.clone_from(git_repo_url, repo_dir)
except git.exc.GitError:
logging.warning('Some error occur in cloning leading upstream repo')
os.chdir('..')
return None

os.chdir(repo_dir)

upstreamversion = subprocess.run(["git", "describe", "--tags", "--always"],
stdout=subprocess.PIPE,
text=True, check=True).stdout.strip()
os.chdir('..')
shutil.rmtree(repo_dir)
match = re.match(version_schema, upstreamversion)
if not match:
logging.warning("Version schema does not match with snapping repository version")
return None
upstreamversion = match.group(1).replace('_', '.')

if upstreamversion != prevversion.split('-')[0]:
if upstreamversion > prevversion.split('-')[0]:
return f"{upstreamversion}-1"
# Determine package release number
packagerelease = int(
prevversion.split('-')[-1]) + 1 if gitcommitdate > snapbuilddate \
else prevversion.split('-')[-1]
if (gitcommitdate > snapbuilddate or 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):
def is_version_update(snap, manager_yaml, arguments, has_update):
""" Returns if snap version update available """
has_version_update = False
if arguments.version_schema == 'None':
return False
metadata = snap.process_metadata()
if process_snap_version_data(metadata['upstream-url'],
metadata['name'], arguments.version_schema) is not None:
if process_snap_version_data(metadata['upstream-version'], metadata['name'],
arguments.version_schema, has_update) is not None:
snap_version = process_snap_version_data(
metadata['upstream-url'], metadata['name'], arguments.version_schema)
metadata['upstream-version'], metadata['name'], arguments.version_schema, has_update)
if metadata['version'] != snap_version:
snap_version_data = manager_yaml.get_part_metadata('version')
if snap_version_data is not None:
Expand Down
9 changes: 5 additions & 4 deletions updatesnap/unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def test_snap_version_automation(self):
version_schema=r'^gutenprint-(\d+_\d+_\d+)',
)
logging.basicConfig(level=logging.ERROR)
test = is_version_update(snap, yaml_obj, args)
test = is_version_update(snap, yaml_obj, args, has_update=False)
os.remove('version_file')
assert test is not None

Expand All @@ -452,7 +452,7 @@ def test_no_version_in_metadata(self):
version_schema=r'^debian/(\d+\.\d+\.\d+)',
)
logging.basicConfig(level=logging.ERROR)
test = is_version_update(snap, yaml_obj, args)
test = is_version_update(snap, yaml_obj, args, has_update=False)
assert not test

def test_correct_snap_version(self):
Expand All @@ -465,12 +465,13 @@ def test_correct_snap_version(self):
version_schema=r'^gutenprint-(\d+_\d+_\d+)',
)

def mock_process_version_data(_git_repo_url, _snap_name, _version_schema):
def mock_process_version_data(_git_repo_url, _snap_name,
_version_schema, _has_update=False):
return "5.3.4-1"

temp = snap_version_module.process_snap_version_data
snap_version_module.process_snap_version_data = mock_process_version_data
test = is_version_update(snap, manager_yaml, args)
test = is_version_update(snap, manager_yaml, args, has_update=False)
snap_version_module.process_snap_version_data = temp
assert not test

Expand Down
2 changes: 1 addition & 1 deletion updatesnap/updatesnapyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def main():
has_update = True

logging.basicConfig(level=logging.INFO)
if (is_version_update(snap, manager_yaml, arguments) or has_update):
if (is_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