Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • seco-ne/yocto/infrastructure/gitlab-ci
1 result
Show changes
Commits on Source (6)
......@@ -200,51 +200,3 @@ merge-yocto:
- .merge
variables:
MANIFEST_BRANCH: dunfell,kirkstone
# --------------------------------------------------------------------------------------
# Stage: build
# --------------------------------------------------------------------------------------
.build-master:
stage: build
rules:
- if: $CI_COMMIT_BRANCH == "master"
when: manual
.build-master-ci-test:
extends: .build-master
needs: ["merge-ci-test"]
trigger:
project: seco-ne/yocto/infrastructure/ci-test/minimal-manifest
branch: "${MANIFEST_BRANCH}"
strategy: depend
.build-master-yocto:
extends: .build-master
needs: ["merge-yocto"]
trigger:
project: seco-ne/yocto/manifest
branch: "${MANIFEST_BRANCH}"
strategy: depend
# Jobs
build-master-ci-test:primary:
extends: .build-master-ci-test
variables:
MANIFEST_BRANCH: primary
build-master-ci-test:secondary:
extends: .build-master-ci-test
variables:
MANIFEST_BRANCH: secondary
build-master-yocto:dunfell:
extends: .build-master-yocto
variables:
MANIFEST_BRANCH: dunfell
build-master-yocto:kirkstone:
extends: .build-master-yocto
variables:
MANIFEST_BRANCH: kirkstone
......@@ -22,10 +22,12 @@ stages:
- cd ${CI_PROJECT_DIR}
- VERSION=$(cd .repo/manifests && git describe --tags)
- cat .repo/manifests/default.xml
- ls * > files-$VERSION.txt
- ls *
- FOO_FILES=$(cd foo && ls | wc -l)
- BAR_FILES=$(cd bar && ls | wc -l)
- find foo -name "[0-9]*.txt" -printf '%P\n' | sort -V > files-foo-$VERSION.txt
- cat files-foo-$VERSION.txt
- find bar -name "[0-9]*.txt" -printf '%P\n' | sort -V > files-bar-$VERSION.txt
- cat files-bar-$VERSION.txt
- FOO_FILES=$(cat files-foo-$VERSION.txt | wc -l)
- BAR_FILES=$(cat files-bar-$VERSION.txt | wc -l)
- DIFF=$((BAR_FILES-FOO_FILES))
- (($DIFF >= -1 && $DIFF <= 1))
......
......@@ -63,42 +63,6 @@ build:
branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}/into/${TARGET_BRANCH}"
strategy: depend
check:
extends: .infrastructure
stage: manifest-integration-jobs
rules:
# Do not run check if the "skip build" label is set on the merge request
- if: $CI_MERGE_REQUEST_LABELS =~ /skip build/
when: never
- if: $CI_MERGE_REQUEST_IID
needs: ["integrate"]
allow_failure: true
script:
- cd ${CI_PROJECT_DIR}
# When running in a trigger pipeline the CII_MERGE_REQUEST_IID is not set
# but CI_OPEN_MERGE_REQUESTS. We use the first of this comma separated list
# in this case
- if [ -n "${CI_MERGE_REQUEST_IID}" ];then
MERGE_REQUEST="${CI_MERGE_REQUEST_IID}";
else
MERGE_REQUEST="${CI_OPEN_MERGE_REQUESTS%%,*}";
fi
# The 'parent_merge_request' is passed from the trigger
# in case this check job is part of a gitlab-ci integration
# pipeline. It is only used to display the correct MR to run again
# in a failed check
- if [ -n "${parent_merge_request}" ];then
PARENT_MR="--parent-merge-request=${parent_merge_request}";
fi
- .gitlab-ci/scripts/check_if_integration_branch_is_up_to_date.py
--gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN}
--manifest-project=${TARGET_PROJECT}
--integration-base=${TARGET_BRANCH}
--project=${CI_PROJECT_PATH}
--merge-request=${MERGE_REQUEST}
${PARENT_MR}
# --------------------------------------------------------------------------------------
# Master pipeline
# --------------------------------------------------------------------------------------
......
......@@ -86,6 +86,35 @@ trigger-pipelines:
job: generate-pipelines
strategy: depend
check:
extends:
- .infrastructure
- .skip-for-gitlab-ci-integrations
stage: manifest-integration
rules:
- if: $CI_MERGE_REQUEST_IID && $CI_COMMIT_REF_NAME !~ /^integrate\/gitlab-ci\/.*/
needs:
- trigger-pipelines
allow_failure: true
script:
- cd ${CI_PROJECT_DIR}
# Loop over all integrations and check each integration branch
- while read -r integration; do
SOURCE_BRANCH=$(echo $integration | cut -d':' -f1);
TARGET_PROJECT=$(echo $integration | cut -d':' -f2);
TARGET_BRANCH=$(echo $integration | cut -d':' -f3);
if [[ "$SOURCE_BRANCH" == "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]]; then
.gitlab-ci/scripts/check_if_integration_branch_is_up_to_date.py
--gitlab-url=${CI_SERVER_URL}
--token=${GITBOT_TOKEN}
--target-project=${TARGET_PROJECT}
--target-branch=${TARGET_BRANCH}
--source-project=${CI_PROJECT_PATH}
--merge-request=${CI_MERGE_REQUEST_IID}
;
fi;
done <<< "$INTEGRATION"
yamllint:
extends: .yamllint
stage: manifest-integration
......@@ -5,55 +5,42 @@ import argparse
import sys
import logging
from gitlab import Gitlab, GitlabGetError
from gitlab.v4.objects import Project
def check_if_integration_branch_is_up_to_date(
manifest_project,
integration_base,
project,
merge_request,
target_project: Project,
target_branch_name: str,
integration_branch_name: str,
):
integration_branch = None
branch_list = []
if common.is_gitlab_ci_integration_branch(merge_request.source_branch):
try:
integration_branch = manifest_project.branches.get(
merge_request.source_branch,
retry_transient_errors=True,
)
branch_list.append(merge_request.source_branch)
except GitlabGetError:
# Branch not found
pass
if integration_branch is None:
integration_branch_name = common.integration_branch_name(
project.name, merge_request.source_branch, integration_base
try:
integration_branch = target_project.branches.get(
integration_branch_name, retry_transient_errors=True
)
branch_list.append(integration_branch)
try:
integration_branch = manifest_project.branches.get(
integration_branch_name,
retry_transient_errors=True,
)
except GitlabGetError:
sys.exit(
"ERROR: could not find integration branch in {},"
"branch names checked: {}\n".format(manifest_project.name, branch_list)
except GitlabGetError:
sys.exit(
"ERROR: could not find integration branch {} in {}.".format(
integration_branch_name, target_project.name
)
)
try:
integration_base_branch = manifest_project.branches.get(
integration_base, retry_transient_errors=True
target_branch = target_project.branches.get(
target_branch_name, retry_transient_errors=True
)
except GitlabGetError:
sys.exit("ERROR: could not find integration base branch\n")
integration_base_id = integration_base_branch.commit["id"]
sys.exit(
"ERROR: could not find target branch {} in {}.".format(
target_branch_name, target_project.name
)
)
# Loop over the commits until the integration_branch head id is found
return common.is_commit_parent_of_project_commit(
manifest_project, integration_branch.commit["id"], integration_base_id, limit=10
target_project,
integration_branch.commit["id"],
target_branch.commit["id"],
limit=10,
)
......@@ -72,34 +59,29 @@ def main():
required=True,
)
parser.add_argument(
"--manifest-project",
help="""name of the manifest project""",
dest="manifest_project",
"--target-project",
help="""name of the target project""",
dest="target_project",
required=True,
)
parser.add_argument(
"--integration-base",
help="""manifest branch to branch off from""",
dest="integration_base",
"--target-branch",
help="""target branch to integrate into""",
dest="target_branch",
required=True,
)
parser.add_argument(
"--project",
help="""name of the project, as specified in the manifest""",
dest="project",
"--source-project",
help="""name of the source project""",
dest="source_project",
required=True,
)
parser.add_argument(
"--merge-request",
help="""project merge request IID containing the changes to be integrated""",
help="""source project merge request IID containing the changes to be integrated""",
dest="merge_request",
required=True,
)
parser.add_argument(
"--parent-merge-request",
help="""parent merge requests link, only used for a hint when the check failes""",
dest="parent_merge_request",
)
parser.add_argument(
"-v",
"--verbose",
......@@ -114,29 +96,39 @@ def main():
gitlab = Gitlab(args.gitlab_url, private_token=args.token)
logging.debug(args)
manifest_project = common.get_project(gitlab, args.manifest_project)
project = common.get_project(gitlab, args.project)
merge_request = common.get_merge_request(project, args.merge_request)
target_project = common.get_project(gitlab, args.target_project)
source_project = common.get_project(gitlab, args.source_project)
merge_request = common.get_merge_request(source_project, args.merge_request)
if merge_request is None:
sys.exit("ERROR: could not get %s %s" % (project.name, args.merge_request))
sys.exit(
"ERROR: could not get %s %s" % (source_project.name, args.merge_request)
)
integration_branch_name = common.integration_branch_name(
source_project.name, merge_request.source_branch, args.target_branch
)
if check_if_integration_branch_is_up_to_date(
manifest_project=manifest_project,
integration_base=args.integration_base,
project=project,
merge_request=merge_request,
target_project=target_project,
target_branch_name=args.target_branch,
integration_branch_name=integration_branch_name,
):
print("Integration branch is up to date.")
print(
"Integration branch {} in {} is up to date.".format(
integration_branch_name, target_project.name
)
)
else:
mr_url = merge_request.web_url + "/pipelines"
if args.parent_merge_request is not None:
mr_url = args.parent_merge_request + "/pipelines"
sys.exit(
"Integration branch is not up to date. Please re-run the MR pipeline:\n"
"Integration branch {} in {} is not up to date.\n"
"Please re-run the MR pipeline:\n"
" 1. Open the MR pipelines page:\n"
" %s\n"
" 2. Click 'Run Pipeline'" % (mr_url)
" {}\n"
" 2. Click 'Run Pipeline'".format(
integration_branch_name,
target_project.name,
merge_request.web_url + "/pipelines",
)
)
......
......@@ -90,7 +90,6 @@ def main():
pipeline,
args.job,
states,
include_children=True,
)
if not jobs:
print(
......