Add a script to trigger refresh on packages that need one
Signed-off-by: Nicolas Belouin <nicolas.belouin@suse.com>
This commit is contained in:
parent
f90f614746
commit
9f2dc045e9
@ -1,3 +1,3 @@
|
||||
PROJECT = "isv:SUSE:Edge:Factory"
|
||||
PROJECT = "isv:SUSE:Edge:Factory:Devel"
|
||||
REPOSITORY = "https://src.opensuse.org/suse-edge/Factory"
|
||||
BRANCH = "main"
|
||||
BRANCH = "devel"
|
||||
|
65
.obs/trigger_package.py
Normal file
65
.obs/trigger_package.py
Normal file
@ -0,0 +1,65 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
import subprocess
|
||||
|
||||
from sync_packages import get_local_packages
|
||||
from common import PROJECT
|
||||
|
||||
def get_service_repo(package):
|
||||
with open(f"{package}/_service") as service:
|
||||
root = ET.parse(service).getroot()
|
||||
for service in root.findall("service"):
|
||||
if service.get("mode") in ["manual", "disabled"]:
|
||||
continue
|
||||
if service.get("name") not in ["obs_scm", "tar_scm"]:
|
||||
continue
|
||||
ref = service.find("param[@name='revision']").text
|
||||
repo = service.find("param[@name='url']").text
|
||||
return (repo, ref)
|
||||
return None
|
||||
|
||||
|
||||
def get_remote_ref(project, package):
|
||||
files = subprocess.run(["osc", "ls", "-e", project, package], encoding='utf-8' , capture_output=True).stdout.splitlines()
|
||||
for filename in files:
|
||||
if filename.startswith("_service") and filename.endswith(".obsinfo"):
|
||||
obsinfo = subprocess.run(["osc", "cat", project, package, filename], encoding='utf-8' , capture_output=True).stdout.splitlines()
|
||||
for line in obsinfo:
|
||||
if line.startswith("commit:"):
|
||||
return line.split(':')[-1].strip()
|
||||
|
||||
def get_upstream_ref(repo, ref):
|
||||
refs = subprocess.run(["git", "ls-remote", repo, ref, f"{ref}^{{}}"], encoding='utf-8' , capture_output=True).stdout.splitlines()
|
||||
refpath = ref.split('/')
|
||||
best = None
|
||||
for rref in refs:
|
||||
value = rref.split('\t')
|
||||
(sha, name) = (value[0].strip(), value[1].strip())
|
||||
namepath = name.split('/')
|
||||
if len(namepath) == len(refpath) or len(namepath) - 2 == len(refpath):
|
||||
if name.endswith(ref) and best is None:
|
||||
best = sha
|
||||
if name.endswith("^{}"):
|
||||
best = sha
|
||||
return best
|
||||
|
||||
def trigger_service(project, package):
|
||||
subprocess.run(["osc", "service", "remoterun", project, package], encoding="utf-8",check=True)
|
||||
|
||||
def main():
|
||||
packages = get_local_packages()
|
||||
for package in packages:
|
||||
try:
|
||||
(repo, ref) = get_service_repo(package)
|
||||
print(f"{package} uses {repo} at {ref}")
|
||||
except: # Package is not using server side scm service
|
||||
continue
|
||||
remote_ref = get_remote_ref(PROJECT, package)
|
||||
upstream_ref = get_upstream_ref(repo, ref)
|
||||
if upstream_ref != remote_ref:
|
||||
print(f"\t{package} needs a refresh")
|
||||
print(f"\tOBS ref is {remote_ref}")
|
||||
print(f"\tgit ref is {upstream_ref}")
|
||||
trigger_service(PROJECT, package)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user