Skip to content
Snippets Groups Projects
Commit e86d320a authored by Jonas Höppner's avatar Jonas Höppner
Browse files

CI: Multideploy: Detect exiting integration branch

parent 0ee24df0
No related branches found
No related tags found
1 merge request!101CI: Create pipeline to deploy changes in gitlab-ci to all subprojects, include all CI implementations from there.
......@@ -2,6 +2,7 @@
import requests
import sys
import logging
import time
from git import Actor, GitCommandError
from git.repo.base import Repo
......@@ -124,6 +125,7 @@ def commit_and_push(project: Project, repo: Repo, branch, message, name, email):
# Push commit
try:
origin = repo.remote("origin")
logging.debug("Push branch %s to %s",branch, origin)
origin.push(branch, force=True)
except GitCommandError as e:
sys.exit("ERROR: could not commit changes\n" + str(e))
......
......@@ -51,13 +51,26 @@ def integrate_into_manifest(
if merge_request.source_branch.startswith("integrate/gitlab-ci"):
logging.debug("Integration of gitlab-ci: %s", merge_request.source_branch)
for ref in manifest_repo.references:
refname = ref.name
logging.debug("Found ref: %s", refname)
if not refname.startswith("origin/"):
continue
# remove 'origin/' from the ref before compare
refname = ref.name.split("/", 1)[1]
logging.debug("Found ref: %s", refname)
if merge_request.source_branch == ref.name:
logging.debug("Found integration for gitlab-ci")
manifest_repo.head.set_reference(ref)
integration_branch = merge_request.source_branch
logging.debug("Splitted refname: %s", refname)
if merge_request.source_branch == refname:
logging.debug("Found integration branch for gitlab-ci")
integration_branch = refname
logging.debug("Integration branch: %s", integration_branch)
manifest_repo.git.checkout('-b', integration_branch, ref.name)
#origin = manifest_repo.remote("origin")
#fetch = origin.fetch(integration_branch)
#logging.debug("Fetch:%s", fetch)
logging.debug("Heads: %s", manifest_repo.heads)
manifest_repo.heads[integration_branch].checkout()
integration_branch = ref.name
break
if integration_branch is None:
......@@ -68,11 +81,12 @@ def integrate_into_manifest(
for ref in manifest_repo.references:
if integration_branch == ref.name:
manifest_repo.delete_head(ref)
logging.debug("Integration branch: %s", integration_branch)
manifest_repo.head.set_reference(
manifest_repo.create_head(integration_branch)
)
logging.debug("Integration branch: %s", integration_branch)
# Parse manifest file
try:
......@@ -239,38 +253,30 @@ def main():
manifest_project = common.get_project(gitlab, args.manifest_project)
project = common.get_project(gitlab, args.project)
logging.debug(project)
mr_iid = args.merge_request
logging.debug(mr_iid)
logging.debug("Project: %s", project.name )
logging.debug("Merge Request: %s", args.merge_request)
# MR may also be specified as
# SECO-Northern-Europe/yocto/infrastructure/ci-test/minimal-bar!115
if mr_iid.startswith(args.project):
mr_number = int(mr_iid.split("!")[-1])
if args.merge_request.startswith(args.project):
mr_number = int(args.merge_request.split("!")[-1])
logging.debug("Number of MR: %d", mr_number)
logging.debug(project.mergerequests.list())
mr_iid = None
for mr in project.mergerequests.list():
logging.debug(mr)
logging.debug(int(mr.iid))
logging.debug(mr.id)
if int(mr.iid) == mr_number:
mr_iid = mr.id
break
logging.debug(mr_iid)
if mr_iid is None:
try:
merge_request = project.mergerequests.get(mr_number, retry_transient_errors=True)
except GitlabGetError as e:
sys.exit(
"ERROR: could not get %s"
% (args.merge_request)
"ERROR: could not get %s!%s: %s"
% (project.name, args.merge_request, e.error_message)
)
else:
# Get the merge request by passed id
try:
merge_request = project.mergerequests.get(args.merge_request, retry_transient_errors=True)
except GitlabGetError as e:
sys.exit(
"ERROR: could not get %s!%s: %s"
% (project.name, args.merge_request, e.error_message)
)
try:
merge_request = project.mergerequests.get(mr_iid, retry_transient_errors=True)
except GitlabGetError as e:
sys.exit(
"ERROR: could not get %s!%s: %s"
% (project.name, args.merge_request, e.error_message)
)
manifest_revision = integrate_into_manifest(
manifest_project=manifest_project,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment