From 34cfa128db91e0587a160164a7c4c7ae50388363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Tue, 24 Oct 2023 15:43:54 +0200 Subject: [PATCH] [BCIRepoPublisher] trigger a rebuild of :Update:BCI as well --- gocd/bci_repo_publish.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/gocd/bci_repo_publish.py b/gocd/bci_repo_publish.py index 6775eef4a..e7b5ba56c 100755 --- a/gocd/bci_repo_publish.py +++ b/gocd/bci_repo_publish.py @@ -83,7 +83,13 @@ def is_repo_published(self, project: str, repo: str) -> bool: return True - def run(self, version: _SLE_VERSION_T, token: Optional[str]=None) -> None: + def _fetch_package_names_in_project(self, prj_name: str) -> List[str]: + url = makeurl(self.apiurl, ['source', prj_name]) + root = ET.parse(http_GET(url)).getroot() + return [elem.get("name") for elem in root] + + def run(self, version: _SLE_VERSION_T, bci_repo_token: Optional[str]=None, + bci_rebuild_token: Optional[str]=None) -> None: class Package(TypedDict): arch: str @@ -167,7 +173,7 @@ class Package(TypedDict): return # Trigger publishing - if token is None: + if bci_repo_token is None or bci_rebuild_token is None: self.logger.warning('Would publish now, but no token specified') return @@ -180,9 +186,13 @@ class Package(TypedDict): } url = makeurl(self.apiurl, ['trigger', 'release'], params) # No bindings for using tokens yet, so do the request manually - req = requests.post(url, headers={'Authorization': f'Token {token}'}) - if req.status_code != 200: - raise RuntimeError(f'Releasing failed: {req.text}') + req = requests.post(url, headers={'Authorization': f'Token {bci_repo_token}'}) + req.raise_for_status() + + for pkg in self._fetch_package_names_in_project(build_prj): + url = makeurl(self.apiurl, ['trigger', 'rebuild'], {'project': build_prj, 'package': pkg}) + req = requests.post(url, headers={'Authorization': f'Token {bci_rebuild_token}'}) + req.raise_for_status() self.logger.info('Waiting for publishing to finish') for pkg in packages: @@ -204,7 +214,8 @@ def setup_tool(self): return tool - @cmdln.option('--token', help='The token for publishing. Does a dry run if not given.') + @cmdln.option('--bci-repo-token', help='The token for publishing. Does a dry run if not given.') + @cmdln.option('--bci-rebuild-token', help='The token for rebuilding devel:BCI. Does a dry run if not given.') def do_run(self, subcmd, opts, project): """${cmd_name}: run the BCI repo publisher for the specified project, e.g. 15-SP3 @@ -213,7 +224,7 @@ def do_run(self, subcmd, opts, project): ${cmd_option_list} """ - self.tool.run(project, token=opts.token) + self.tool.run(project, bci_repo_token=opts.bci_repo_token, bci_rebuild_token=opts.bci_rebuild_token) if __name__ == "__main__":