Skip to content

Commit

Permalink
[BCIRepoPublisher] trigger a rebuild of devel:BCI:SLE-15-SPX as well
Browse files Browse the repository at this point in the history
  • Loading branch information
dcermak committed Oct 27, 2023
1 parent 42c86f2 commit de1d827
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
12 changes: 8 additions & 4 deletions gocd/bci.gocd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pipelines:
environment_variables:
OSC_CONFIG: /home/go/config/oscrc-totest-manager
BCI_TOKEN: '{{SECRET:[opensuse.secrets][BCI_TOKEN]}}'
DEVEL_BCI_REBUILD_TOKEN: '{{SECRET:[opensuse.secrets][DEVEL_BCI_REBUILD_TOKEN]}}'
stages:
- Run:
approval: manual
Expand All @@ -148,7 +149,7 @@ pipelines:
tasks:
- script: |
export PYTHONPATH=scripts
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--token=$BCI_TOKEN" 15-SP3
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--publish-token=$BCI_TOKEN" "--rebuild-token=$DEVEL_BCI_REBUILD_TOKEN" 15-SP3
SLE_BCI_15SP4.RelPkgs:
group: BCI
Expand Down Expand Up @@ -248,6 +249,7 @@ pipelines:
environment_variables:
OSC_CONFIG: /home/go/config/oscrc-totest-manager
BCI_TOKEN: '{{SECRET:[opensuse.secrets][BCI_TOKEN]}}'
DEVEL_BCI_REBUILD_TOKEN: '{{SECRET:[opensuse.secrets][DEVEL_BCI_REBUILD_TOKEN]}}'
stages:
- Run:
approval: manual
Expand All @@ -256,7 +258,7 @@ pipelines:
tasks:
- script: |
export PYTHONPATH=scripts
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--token=$BCI_TOKEN" 15-SP4
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--publish-token=$BCI_TOKEN" "--rebuild-token=$DEVEL_BCI_REBUILD_TOKEN" 15-SP4
SLE_BCI_15SP5.RelPkgs:
group: BCI
Expand Down Expand Up @@ -356,6 +358,7 @@ pipelines:
environment_variables:
OSC_CONFIG: /home/go/config/oscrc-totest-manager
BCI_TOKEN: '{{SECRET:[opensuse.secrets][BCI_TOKEN]}}'
DEVEL_BCI_REBUILD_TOKEN: '{{SECRET:[opensuse.secrets][DEVEL_BCI_REBUILD_TOKEN]}}'
stages:
- Run:
approval: manual
Expand All @@ -364,7 +367,7 @@ pipelines:
tasks:
- script: |
export PYTHONPATH=scripts
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--token=$BCI_TOKEN" 15-SP5
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--publish-token=$BCI_TOKEN" "--rebuild-token=$DEVEL_BCI_REBUILD_TOKEN" 15-SP5
SLE_BCI_15SP6.RelPkgs:
group: BCI
Expand Down Expand Up @@ -464,6 +467,7 @@ pipelines:
environment_variables:
OSC_CONFIG: /home/go/config/oscrc-totest-manager
BCI_TOKEN: '{{SECRET:[opensuse.secrets][BCI_TOKEN]}}'
DEVEL_BCI_REBUILD_TOKEN: '{{SECRET:[opensuse.secrets][DEVEL_BCI_REBUILD_TOKEN]}}'
stages:
- Run:
approval: manual
Expand All @@ -472,5 +476,5 @@ pipelines:
tasks:
- script: |
export PYTHONPATH=scripts
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--token=$BCI_TOKEN" 15-SP6
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--publish-token=$BCI_TOKEN" "--rebuild-token=$DEVEL_BCI_REBUILD_TOKEN" 15-SP6
3 changes: 2 additions & 1 deletion gocd/bci.gocd.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pipelines:
environment_variables:
OSC_CONFIG: /home/go/config/oscrc-totest-manager
BCI_TOKEN: '{{SECRET:[opensuse.secrets][BCI_TOKEN]}}'
DEVEL_BCI_REBUILD_TOKEN: '{{SECRET:[opensuse.secrets][DEVEL_BCI_REBUILD_TOKEN]}}'
stages:
- Run:
approval: manual
Expand All @@ -148,5 +149,5 @@ pipelines:
tasks:
- script: |
export PYTHONPATH=scripts
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--token=$BCI_TOKEN" 15-<%= sp %>
./scripts/gocd/bci_repo_publish.py -A https://api.suse.de --verbose --debug run "--publish-token=$BCI_TOKEN" "--rebuild-token=$DEVEL_BCI_REBUILD_TOKEN" 15-<%= sp %>
<% end %>
30 changes: 23 additions & 7 deletions gocd/bci_repo_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ def is_repo_published(self, project: str, repo: str, arch: Optional[str] = None)

return True

def run(self, version: _SLE_VERSION_T, token: Optional[str]=None) -> None:
def fetch_package_names_in_project(self, apiurl: str, prj_name: str) -> List[str]:
url = makeurl(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, publish_token: Optional[str] = None,
rebuild_token: Optional[str] = None) -> None:

class Package(TypedDict):
arch: str
Expand All @@ -101,6 +107,8 @@ class Package(TypedDict):
published_mtime: int

build_prj = f'SUSE:SLE-{version}:Update:BCI'
devel_prj = f'devel:BCI:SLE-{version}'
_DEVEL_PRJ_APIURL = "https://api.opensuse.org"

if not self.is_repo_published(build_prj, 'images', 'local'):
self.logger.info(f'{build_prj}/images not successfully built')
Expand Down Expand Up @@ -174,8 +182,16 @@ class Package(TypedDict):
return
openqa_passed_packages.append(pkg)

if rebuild_token:
for pkg in self.fetch_package_names_in_project(_DEVEL_PRJ_APIURL, devel_prj):
url = makeurl(_DEVEL_PRJ_APIURL, ['trigger', 'rebuild'], {'project': devel_prj, 'package': pkg})
req = requests.post(url, headers={'Authorization': f'Token {rebuild_token}'})
req.raise_for_status()
else:
self.logger.warning('Would rebuild %s now, but no token specified', devel_prj)

# Trigger publishing
if token is None:
if publish_token is None:
self.logger.warning(f'Would publish {[pkg["name"] for pkg in openqa_passed_packages]}, but no token specified')
return

Expand All @@ -188,9 +204,8 @@ 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 {publish_token}'})
req.raise_for_status()

self.logger.info('Waiting for publishing to finish')
for pkg in openqa_passed_packages:
Expand All @@ -212,15 +227,16 @@ def setup_tool(self):

return tool

@cmdln.option('--token', help='The token for publishing. Does a dry run if not given.')
@cmdln.option('--publish-token', help='The token for publishing. Does a dry run if not given.')
@cmdln.option('--rebuild-token', help='The token for rebuilding devel:BCI, no rebuild is triggered if omitted.')
def do_run(self, subcmd, opts, project):
"""${cmd_name}: run BCI repo publisher for the project, e.g. 15-SP5.
${cmd_usage}
${cmd_option_list}
"""

self.tool.run(project, token=opts.token)
self.tool.run(project, publish_token=opts.publish_token, rebuild_token=opts.rebuild_token)


if __name__ == "__main__":
Expand Down

0 comments on commit de1d827

Please sign in to comment.