Skip to content

Commit

Permalink
Merge branch 'topic/okurth/ci-cayman_poi-submodules' into 'master'
Browse files Browse the repository at this point in the history
add python script to wait for cayman_poi CI

See merge request core-build/photon-os-installer!94
  • Loading branch information
Oliver Kurth committed Oct 27, 2024
2 parents 6997ab1 + 3404461 commit a7e96d8
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 6 deletions.
15 changes: 9 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ stages:
- github

build-container:
stage: build
script:
- cd docker && docker build -t ${POI_IMAGE_NAME} --build-arg DOCKER_PROXY=dockerhub.artifactory.eng.vmware.com/ --build-context poi-helper=$(realpath $(pwd)/..) .
- docker system prune -f
stage: build
needs: []
script:
- cd docker && docker build -t ${POI_IMAGE_NAME} --build-context poi-helper=$(realpath $(pwd)/..) .
- docker system prune -f

cayman_poi:
stage: build
needs: []
script:
- gitlab --private-token=$CAYMAN_POI_CICD_API_TOKEN project-branch create --project-id core-build/cayman_photon-os-installer --branch test/poi-submodule/$CI_COMMIT_SHORT_SHA --ref vmware-master
- gitlab --private-token=$CAYMAN_POI_CICD_API_TOKEN project update-submodule --id core-build/cayman_photon-os-installer --branch test/poi-submodule/$CI_COMMIT_SHORT_SHA --submodule poi/src --commit-sha $CI_COMMIT_SHA
- ./ci/gitlab/submodule_ci.py --private-token=$CAYMAN_POI_CICD_API_TOKEN --project-id core-build/cayman_photon-os-installer --branch test/poi-submodule/$CI_COMMIT_SHORT_SHA --parent-branch vmware-master --submodule-path poi/src --submodule-sha $CI_COMMIT_SHA

pytest:
stage: test
needs:
- build-container
script:
- pytest-3 -x tests/poi-container-test.py

Expand Down
96 changes: 96 additions & 0 deletions ci/gitlab/submodule_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/env python3

import getopt
import gitlab
import os
import sys
import time


def main():
do_keep_branch = False
parent_branch = None
private_token = None
project_id = None
server = None
submodule_path = None
submodule_sha = None

try:
opts, args = getopt.getopt(
sys.argv[1:],
"",
longopts=["branch=", "keep-branch", "parent-branch=", "private-token=", "project-id=", "submodule-path=", "submodule-sha="]
)
except getopt.GetoptError as e:
print(e.msg)
sys.exit(2)

for o, a in opts:
if o in ["--branch"]:
branch = a
elif o in ["--keep-branch"]:
do_keep_branch = True
elif o in ["--parent-branch"]:
parent_branch = a
elif o in ["--private-token"]:
private_token = a
elif o in ["--project-id"]:
project_id = a
elif o in ["--submodule-path"]:
submodule_path = a
elif o in ["--submodule-sha"]:
submodule_sha = a
else:
assert False, f"unhandled option {o}"

assert branch is not None, "no branch is set"
assert parent_branch is not None, "no parent_branch is set"
assert private_token is not None, "no private_token is set"
assert submodule_path is not None, "no submodule_path is set"
assert submodule_sha is not None, "no submodule_sha is set"

if server is None:
server = os.environ['CI_SERVER_URL']

gl = gitlab.Gitlab(url=server, private_token=private_token)

project = gl.projects.get(project_id)

project.branches.create({'branch': branch, 'ref': parent_branch})
print(f"branch {branch} created in {project_id}", flush=True)

response = project.update_submodule(submodule_path, branch, submodule_sha)
print(f"sub module {submodule_path} updated to {submodule_sha}", flush=True)

sha = response['id']

while True:
pipelines = project.pipelines.list(sha=sha)
if pipelines:
break
print(f"waiting for pipeline for sha={sha}", flush=True)
time.sleep(5)

pipeline = pipelines[0]
print(f"pipeline url is {pipeline.web_url}", flush=True)

print(f"pipeline status is {pipeline.status}", flush=True)
while pipeline.status not in ["success", "failed", "canceled"]:
time.sleep(15)
pipeline.refresh()
print(f"pipeline status is {pipeline.status}", flush=True)

if not do_keep_branch:
project.branches.delete(branch)
print(f"branch {branch} deleted")

if pipeline.status != "success":
print(f"pipeline failed with status {pipeline.status}", flush=True)
sys.exit(1)

print(f"pipeline succeeded with status {pipeline.status}", flush=True)


if __name__ == "__main__":
main()

0 comments on commit a7e96d8

Please sign in to comment.