Skip to content

Commit

Permalink
[BCIRepoPublisher] trigger a rebuild of :Update:BCI as well
Browse files Browse the repository at this point in the history
  • Loading branch information
dcermak committed Oct 24, 2023
1 parent b4e3d4b commit 34cfa12
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions gocd/bci_repo_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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__":
Expand Down

0 comments on commit 34cfa12

Please sign in to comment.