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

CI: Test 'multi-deploy' job

parent 9e3a7fb3
No related branches found
No related tags found
No related merge requests found
Pipeline #8845 passed with stages
in 1 minute and 2 seconds
...@@ -18,6 +18,7 @@ default: ...@@ -18,6 +18,7 @@ default:
stages: stages:
- analyze - analyze
- deploy-test
- deploy - deploy
workflow: workflow:
...@@ -53,6 +54,28 @@ yamllint: ...@@ -53,6 +54,28 @@ yamllint:
- yamllint -c .yamllint.yml *.yml .*.yml - yamllint -c .yamllint.yml *.yml .*.yml
# ---------------------------------------------------------------------------------------
# Stage: deploy-test
# ---------------------------------------------------------------------------------------
deploy-foobar-manifest:
stage: deploy-test
# when: manual
allow_failure: true
script:
- cd ${CI_PROJECT_DIR}
- if [[ "$CI_COMMIT_BRANCH" == "master" ]]; then MERGE="--merge"; else MERGE=""; fi
- PROJECT_ROOT="${CI_PROJECT_ROOT_NAMESPACE}/yocto/infrastructure/ci-test"
- ./deploy_gitlab_ci.py
--gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN}
--submodule=.gitlab-ci
--revision=${CI_COMMIT_SHA}
--verbose
${MERGE}
--manifest-project=${PROJECT_ROOT}/minimal-manifest
${PROJECT_ROOT}/minimal-foo
${PROJECT_ROOT}/minimal-bar
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
# Stage: deploy # Stage: deploy
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
......
...@@ -41,9 +41,9 @@ def main(): ...@@ -41,9 +41,9 @@ def main():
) )
parser.add_argument( parser.add_argument(
"--project", "--project",
"--manifest-project",
help="""name of the GitLab project""", help="""name of the GitLab project""",
dest="project", dest="project",
required=True,
) )
parser.add_argument( parser.add_argument(
"--submodule", "--submodule",
...@@ -72,6 +72,12 @@ def main(): ...@@ -72,6 +72,12 @@ def main():
required=False, required=False,
default=False, default=False,
) )
parser.add_argument(
"projects",
help="""List of projects the change should be deployed to additionally
to the manifest project given as named parameter.""",
nargs="*",
)
parser.add_argument( parser.add_argument(
"-v", "-v",
"--verbose", "--verbose",
...@@ -86,6 +92,8 @@ def main(): ...@@ -86,6 +92,8 @@ def main():
gitlab = Gitlab(args.gitlab_url, private_token=args.token) gitlab = Gitlab(args.gitlab_url, private_token=args.token)
project = common.get_project(gitlab, args.project) project = common.get_project(gitlab, args.project)
logging.debug("Integrate into: %s", args.project)
# Update submodule # Update submodule
integration_branch, _, submodule_project = update_submodule( integration_branch, _, submodule_project = update_submodule(
project, project,
...@@ -93,6 +101,7 @@ def main(): ...@@ -93,6 +101,7 @@ def main():
args.revision, args.revision,
args.branch, args.branch,
pre_commit_hook=update_rev_in_gitlab_ci, pre_commit_hook=update_rev_in_gitlab_ci,
replace_exising_branch=len(args.projects) > 0,
) )
logging.debug("Integration branch: %s", integration_branch) logging.debug("Integration branch: %s", integration_branch)
...@@ -100,6 +109,20 @@ def main(): ...@@ -100,6 +109,20 @@ def main():
if not integration_branch: if not integration_branch:
sys.exit(0) sys.exit(0)
for p in args.projects:
gitlab_p = common.get_project(gitlab, p)
logging.debug("Integrate into: %s", p)
# Update submodule
integration_branch, _, submodule_project = update_submodule(
gitlab_p,
args.submodule,
args.revision,
args.branch,
pre_commit_hook=update_rev_in_gitlab_ci,
)
logging.debug("Integration branch: %s", integration_branch)
# Get source merge request # Get source merge request
mrs = get_merge_requests( mrs = get_merge_requests(
submodule_project, submodule_project,
......
...@@ -62,6 +62,7 @@ integrate: ...@@ -62,6 +62,7 @@ integrate:
cache: cache:
policy: push policy: push
script: script:
- printenv
- cd ${CI_PROJECT_DIR} - cd ${CI_PROJECT_DIR}
- .gitlab-ci/integrate_into_manifest.py - .gitlab-ci/integrate_into_manifest.py
--gitlab-url=${CI_SERVER_URL} --gitlab-url=${CI_SERVER_URL}
...@@ -71,6 +72,7 @@ integrate: ...@@ -71,6 +72,7 @@ integrate:
--project=${CI_PROJECT_PATH} --project=${CI_PROJECT_PATH}
--merge-request=${CI_MERGE_REQUEST_IID} --merge-request=${CI_MERGE_REQUEST_IID}
--save-revision-to=manifest_revision --save-revision-to=manifest_revision
--verbose
artifacts: artifacts:
paths: paths:
- manifest_revision - manifest_revision
...@@ -105,7 +107,10 @@ merge: ...@@ -105,7 +107,10 @@ merge:
build: build:
stage: build stage: build
rules: rules:
- if: $CI_MERGE_REQUEST_IID # execute this in MR only and not for integrate/gitlab-ci/ integrations
# branches. These are build after the integration has been done in all
# projects
- if: $CI_MERGE_REQUEST_IID && $CI_COMMIT_REF_NAME !~ /^integrate\/gitlab-ci\/.*/
trigger: trigger:
project: SECO-Northern-Europe/yocto/infrastructure/ci-test/minimal-manifest project: SECO-Northern-Europe/yocto/infrastructure/ci-test/minimal-manifest
branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}" branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}"
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import common import common
import argparse import argparse
import logging
import sys import sys
import tempfile import tempfile
import re import re
...@@ -42,14 +43,36 @@ def integrate_into_manifest( ...@@ -42,14 +43,36 @@ def integrate_into_manifest(
except IndexError: except IndexError:
sys.exit("ERROR: branch '%s' not found" % integration_base) sys.exit("ERROR: branch '%s' not found" % integration_base)
# Create integration branch (delete former one if already exists) # Special handling for the gitlab-ci integration
integration_branch = common.integration_branch_name( # When the branch 'merge_request.source_branch' already starts with
project.name, merge_request.source_branch # integrate/gitlab-ci we add our new commit to this branch
) # Otherwise (normal behaviour) a new integration branch is created
for ref in manifest_repo.references: integration_branch = None
if integration_branch == ref.name: if merge_request.source_branch.startswith("integrate/gitlab-ci"):
manifest_repo.delete_head(ref) logging.debug("Integration of gitlab-ci: %s", merge_request.source_branch)
manifest_repo.head.set_reference(manifest_repo.create_head(integration_branch)) for ref in manifest_repo.references:
# 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
break
if integration_branch is None:
# Create integration branch (delete former one if already exists)
integration_branch = common.integration_branch_name(
project.name, merge_request.source_branch
)
for ref in manifest_repo.references:
if integration_branch == ref.name:
manifest_repo.delete_head(ref)
manifest_repo.head.set_reference(
manifest_repo.create_head(integration_branch)
)
logging.debug("Integration branch: %s", integration_branch)
# Parse manifest file # Parse manifest file
try: try:
...@@ -199,8 +222,16 @@ def main(): ...@@ -199,8 +222,16 @@ def main():
dest="revision_file", dest="revision_file",
required=False, required=False,
) )
parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="""Increase verbosity.""",
)
args, _ = parser.parse_known_args() args, _ = parser.parse_known_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
gitlab = Gitlab(args.gitlab_url, private_token=args.token) gitlab = Gitlab(args.gitlab_url, private_token=args.token)
......
...@@ -12,7 +12,12 @@ from gitlab import Gitlab ...@@ -12,7 +12,12 @@ from gitlab import Gitlab
def update_submodule( def update_submodule(
project, submodule_name, submodule_revision, branch=None, pre_commit_hook=None project,
submodule_name,
submodule_revision,
branch=None,
pre_commit_hook=None,
replace_exising_branch=False,
): ):
"""Update submodule of gitlab project to given revision """Update submodule of gitlab project to given revision
...@@ -23,6 +28,7 @@ def update_submodule( ...@@ -23,6 +28,7 @@ def update_submodule(
branch (string): branch to update, if None, the projects default branch is used branch (string): branch to update, if None, the projects default branch is used
pre_commit_hook: Function to be called before the actual commit is done, to add additional changes. pre_commit_hook: Function to be called before the actual commit is done, to add additional changes.
Arguments passed: ( repo, submodule_project, submodule_revision) Arguments passed: ( repo, submodule_project, submodule_revision)
replace_exising_branch: When an existing integration branch is found it is always replaced.
Returns: tuple of: Returns: tuple of:
branch (string): Name of the newly created integration branch branch (string): Name of the newly created integration branch
revision (string): hexsha of the new commit revision (string): hexsha of the new commit
...@@ -116,16 +122,16 @@ def update_submodule( ...@@ -116,16 +122,16 @@ def update_submodule(
if existing_branch: if existing_branch:
repo.head.set_reference(existing_branch) repo.head.set_reference(existing_branch)
submodule = common.get_submodule(repo, submodule_name) submodule = common.get_submodule(repo, submodule_name)
if submodule.hexsha == submodule_revision: if replace_exising_branch or submodule.hexsha != submodule_revision:
print("Replacing outdated integration branch %s" % integration_branch)
repo.head.set_reference(branch)
submodule = common.get_submodule(repo, submodule_name)
else:
print( print(
"Submodule is already at %s on branch %s" "Submodule is already at %s on branch %s"
% (submodule_revision, integration_branch) % (submodule_revision, integration_branch)
) )
return (integration_branch, existing_branch.commit, submodule_project) return (integration_branch, existing_branch.commit, submodule_project)
else:
print("Replacing outdated integration branch %s" % integration_branch)
repo.head.set_reference(branch)
submodule = common.get_submodule(repo, submodule_name)
else: else:
print("Creating integration branch %s" % integration_branch) print("Creating integration branch %s" % integration_branch)
......
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