Accepting request 1035079 from home:dcassany:branches:Virtualization:containers

- Update to version 1668090256.71deb28:
  * Bump version: 0.0.5 → 0.0.6
  * Link to the official poetry installation guide
  * Update replace_using_package_version.service
  * Update README.md
  * Update README.md
  * Update README.md
  * Update integration_tests/test_version_extraction.py
  * Update replace_using_package_version.service
  * Attempt to read version from obsinfo if no version is found
  * Add Leap 15.4 & SLE 15 SP4 to the CI

OBS-URL: https://build.opensuse.org/request/show/1035079
OBS-URL: https://build.opensuse.org/package/show/Virtualization:containers/obs-service-replace_using_package_version?expand=0&rev=14
This commit is contained in:
2022-11-10 15:26:12 +00:00
committed by Git OBS Bridge
parent 6aa25f3db8
commit 4012585222
5 changed files with 63 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
<servicedata> <servicedata>
<service name="tar_scm"> <service name="tar_scm">
<param name="url">https://github.com/openSUSE/obs-service-replace_using_package_version.git</param> <param name="url">https://github.com/openSUSE/obs-service-replace_using_package_version.git</param>
<param name="changesrevision">ab6de1ec8beb3631af0039074430a3d0cbf59eb6</param></service></servicedata> <param name="changesrevision">71deb28fee3d2bd774404ee4018080fbb47a6247</param></service></servicedata>

View File

@@ -1,3 +1,18 @@
-------------------------------------------------------------------
Thu Nov 10 14:26:46 UTC 2022 - containers@suse.com
- Update to version 1668090256.71deb28:
* Bump version: 0.0.5 → 0.0.6
* Link to the official poetry installation guide
* Update replace_using_package_version.service
* Update README.md
* Update README.md
* Update README.md
* Update integration_tests/test_version_extraction.py
* Update replace_using_package_version.service
* Attempt to read version from obsinfo if no version is found
* Add Leap 15.4 & SLE 15 SP4 to the CI
------------------------------------------------------------------- -------------------------------------------------------------------
Thu Nov 10 13:11:18 UTC 2022 - containers@suse.com Thu Nov 10 13:11:18 UTC 2022 - containers@suse.com

View File

@@ -19,7 +19,7 @@
%define service replace_using_package_version %define service replace_using_package_version
Name: obs-service-%{service} Name: obs-service-%{service}
Version: 0.0.5 Version: 0.0.6
Release: 0 Release: 0
Summary: An OBS service: Replaces a regex with the version value of a package Summary: An OBS service: Replaces a regex with the version value of a package
License: GPL-3.0-or-later License: GPL-3.0-or-later

View File

@@ -59,6 +59,7 @@ version_regex = {
'patch_update': r'^(\d+(\.\d+){0,3})', 'patch_update': r'^(\d+(\.\d+){0,3})',
'offset': r'^(?:\d+(?:\.\d+){0,3})[+-.~](?:git|svn|cvs)(\d+)' 'offset': r'^(?:\d+(?:\.\d+){0,3})[+-.~](?:git|svn|cvs)(\d+)'
} }
obsinfo_regex = r'version: (.+)'
def guess_recipe_filename_from_env() -> Optional[str]: def guess_recipe_filename_from_env() -> Optional[str]:
@@ -160,26 +161,45 @@ def apply_regex_to_file(input_file, output_file, regex, replacement):
def find_package_version(package, rpm_dir): def find_package_version(package, rpm_dir):
version = parse_version('')
try: try:
version = get_pkg_version(package) version = get_pkg_version(package)
except Exception: except Exception:
# If package is not found in rpmdb check local repositories version = find_package_version_in_local_repos(rpm_dir, package)
version = parse_version('')
for root, _, files in os.walk(rpm_dir): if not str(version):
packages = [ version = find_package_version_in_obsinfo('.', package)
f for f in files if f.endswith('rpm') and package in f
]
for pkg in packages:
rpm_file = os.path.realpath(os.path.join(root, pkg))
if get_pkg_name_from_rpm(rpm_file) == package:
rpm_version = get_pkg_version_from_rpm(rpm_file)
if rpm_version >= version:
version = rpm_version
if not str(version): if not str(version):
raise Exception('Package version not found') raise Exception('Package version not found')
return str(version) return str(version)
def find_package_version_in_local_repos(repo_path, package):
version = parse_version('')
for root, _, files in os.walk(repo_path):
packages = [
f for f in files if f.endswith('rpm') and package in f
]
for pkg in packages:
rpm_file = os.path.join(root, pkg)
if get_pkg_name_from_rpm(rpm_file) == package:
rpm_ver = get_pkg_version_from_rpm(rpm_file)
if rpm_ver >= version:
version = rpm_ver
return version
def find_package_version_in_obsinfo(path, package):
version = parse_version('')
for f in os.listdir(path):
if f.endswith('obsinfo') and package in f:
obsinfo_ver = get_pkg_version_from_obsinfo(f)
if obsinfo_ver >= version:
version = obsinfo_ver
return version
def find_match_in_version(regexpr, version): def find_match_in_version(regexpr, version):
search = re.search(regexpr, version) search = re.search(regexpr, version)
if search is None: if search is None:
@@ -192,6 +212,16 @@ def run_command(command: List[str]) -> str:
return subprocess.check_output(command).decode() return subprocess.check_output(command).decode()
def get_pkg_version_from_obsinfo(obsinfo_file):
regex = re.compile(obsinfo_regex)
with open(obsinfo_file) as f:
for line in f:
match = regex.match(line)
if match:
return parse_version(match[1])
return parse_version('')
def get_pkg_name_from_rpm(rpm_file): def get_pkg_name_from_rpm(rpm_file):
command = [ command = [
'rpm', '-qp', '--queryformat', '%{NAME}', rpm_file 'rpm', '-qp', '--queryformat', '%{NAME}', rpm_file

View File

@@ -12,7 +12,10 @@ It uses python re module syntax</description>
</parameter> </parameter>
<parameter name="package"> <parameter name="package">
<description>This is the package which version will be used as a replacement <description>This is the package which version will be used as a replacement
for the regex. It must be included in the build as a dependency.</description> for the regex. If it is not found as a build dependency it will fallback to
look for an *.obsinfo file with the package name (the *obsinfo file is
generated by the obs_scm service). It fails if no version is found.
</description>
</parameter> </parameter>
<parameter name="parse-version"> <parameter name="parse-version">
<description>Parses the package version string to match the <description>Parses the package version string to match the