1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pyinventory_ynh.git synced 2024-09-03 20:16:09 +02:00

Test if current package version is the latest github tag

This commit is contained in:
JensDiemer 2022-10-03 18:28:55 +02:00
parent 7157df1b36
commit 9416f4bd84

View file

@ -4,10 +4,12 @@ import shutil
import subprocess import subprocess
from pathlib import Path from pathlib import Path
import requests
import tomli import tomli
from django_tools.serve_media_app.utils import clean_filename from django_tools.serve_media_app.utils import clean_filename
from django_tools.unittest_utils.assertments import assert_is_dir, assert_is_file from django_tools.unittest_utils.assertments import assert_is_dir, assert_is_file
from django_tools.unittest_utils.project_setup import check_editor_config from django_tools.unittest_utils.project_setup import check_editor_config
from packaging.version import Version
import inventory import inventory
@ -23,8 +25,24 @@ def assert_file_contains_string(file_path, string):
raise AssertionError(f'File {file_path} does not contain {string!r} !') raise AssertionError(f'File {file_path} does not contain {string!r} !')
def get_github_version_tag(github_project_url):
api_url = github_project_url.replace('github.com', 'api.github.com/repos')
tags = requests.get(f'{api_url}/tags').json()
for tag in tags:
version_str = tag['name']
ver_obj = Version(version_str)
if ver_obj.base_version and not ver_obj.is_prerelease:
return ver_obj
def test_version(): def test_version():
upstream_version = inventory.__version__ upstream_version = inventory.__version__
current_ver_obj = Version(upstream_version)
github_ver = get_github_version_tag(github_project_url='https://github.com/jedie/PyInventory')
assert (
github_ver == current_ver_obj
), f'Current version from github is: {github_ver} but current package version is: {current_ver_obj}'
pyproject_toml_path = Path(PACKAGE_ROOT, 'pyproject.toml') pyproject_toml_path = Path(PACKAGE_ROOT, 'pyproject.toml')
pyproject_toml = tomli.loads(pyproject_toml_path.read_text(encoding='UTF-8')) pyproject_toml = tomli.loads(pyproject_toml_path.read_text(encoding='UTF-8'))