From 6b6d57180c086b313399d268605e39f903d96358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6ppner?= <jonas.hoeppner@garz-fricke.com> Date: Mon, 14 Mar 2022 13:48:12 +0100 Subject: [PATCH] CI: Add common gitlab-ci file for all yocto repositories. Create a merged version of the gitlab-ci files from the layers and the repositoried referenced by the SRCREV file to be included in the projects, to replace the project-individual implementation. BCS 746-000646 --- manifest-integration.yml | 153 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 manifest-integration.yml diff --git a/manifest-integration.yml b/manifest-integration.yml new file mode 100644 index 00000000..6ead7050 --- /dev/null +++ b/manifest-integration.yml @@ -0,0 +1,153 @@ +--- +# --------------------------------------------------------------------------------------- +# Global +# --------------------------------------------------------------------------------------- +image: "${CI_IMAGES}/python/3.9:99e363bc5feaa27ff18dbe7731a76ff04d7d0deb" + +stages: + - prepare + - integrate + - merge + - build + - check + +variables: + # CI_IMAGES_BASEPATH: Environment variable configure in gitlab + CI_IMAGES: ${CI_IMAGES_BASEPATH}/ci-images + # Include git submodules + GIT_SUBMODULE_STRATEGY: recursive + # FIXME: due to a missing feature in GitLab we cannot use this variable + # in the build stage further down this file. If it ever changes, it has + # to be changed there too. + # (https://gitlab.com/gitlab-org/gitlab/-/issues/249583) + MANIFEST_PROJECT: ${CI_PROJECT_ROOT_NAMESPACE}/yocto/manifest + MASTER_BRANCH_MANIFEST: dunfell + MASTER_BRANCH_PROJECT: dunfell + # The BB_RECIPE_NAME is used for projects referenced in the SRCREV file + # to match the repository and the bitbake recipe name. + # We set it here to none, as every project needing it + # has to specify it in its own gitlab-ci.yml file. + # The BB_RECIPE_NAME is passed to the python scripts below anyway, but not + # used for projects referenced in the manifest file. + BB_RECIPE_NAME: none + # Reduced depth as checkout of larger projects (like the kernel) + # may take too long + GIT_DEPTH: 5 + +workflow: + rules: + # Do not run pipelines on forked projects. + # The pipelines would not work anyway because of the users permissions. + # There are two cases catched here: + # 1. The project is forked into someones gitlab namespace and a MR to + # include a change into this forked project is created. In this case + # is the CI_PROJECT_ROOT_NAMESPACE not SECO-Northern-Europe but the + # namespace the fork lives in. + # 2. The MR from the forked project is created to merge the change into this + # the project in the SECO-Northern-Europe namespace (customer sending + # change to us). Here the the IDs used below differ. + # + - if: $CI_PROJECT_ROOT_NAMESPACE == "SECO-Northern-Europe" + && $CI_MERGE_REQUEST_SOURCE_PROJECT_ID == $CI_MERGE_REQUEST_PROJECT_ID + +# --------------------------------------------------------------------------------------- +# Stage: prepare +# --------------------------------------------------------------------------------------- +yamllint: + stage: prepare + rules: + - if: $CI_COMMIT_REF_NAME != $MASTER_BRANCH + tags: + - infrastructure + timeout: 2m + script: + - yamllint -c .gitlab-ci/.yamllint.yml .*.yml + +# --------------------------------------------------------------------------------------- +# Stage: integrate +# --------------------------------------------------------------------------------------- +integrate: + stage: integrate + rules: + # We have to make sure that the pipeline runs for the current manifest + # master at the time a merge request is created. Otherwise we cannot + # guarantee a green master after merging. + - if: $CI_MERGE_REQUEST_IID + tags: + - infrastructure + timeout: 5m + cache: + policy: push + script: + - cd ${CI_PROJECT_DIR} + - .gitlab-ci/integrate_into_manifest.py + --gitlab-url=${CI_SERVER_URL} + --token=${GITBOT_TOKEN} + --manifest-project=${MANIFEST_PROJECT} + --integration-base=${MASTER_BRANCH_MANIFEST} + --project=${CI_PROJECT_PATH} + --merge-request=${CI_MERGE_REQUEST_IID} + --save-revision-to=manifest_revision + --recipe-name=${BB_RECIPE_NAME} + artifacts: + paths: + - manifest_revision + +# --------------------------------------------------------------------------------------- +# Stage: merge +# --------------------------------------------------------------------------------------- +merge: + stage: merge + rules: + - if: $CI_COMMIT_BRANCH == $MASTER_BRANCH_PROJECT + tags: + - infrastructure + timeout: 5m + script: + - cd ${CI_PROJECT_DIR} + - .gitlab-ci/merge_into_manifest.py + --gitlab-url=${CI_SERVER_URL} + --token=${GITBOT_TOKEN} + --manifest-project=${MANIFEST_PROJECT} + --master-branch=${MASTER_BRANCH_MANIFEST} + --project=${CI_PROJECT_PATH} + --master-branch-project=${MASTER_BRANCH_PROJECT} + --commit=${CI_COMMIT_SHA} + --save-revision-to=manifest_revision + --recipe-name=${BB_RECIPE_NAME} + artifacts: + paths: + - manifest_revision + +# --------------------------------------------------------------------------------------- +# Stage: build +# --------------------------------------------------------------------------------------- +build: + stage: build + rules: + - if: $CI_MERGE_REQUEST_IID + trigger: + project: SECO-Northern-Europe/yocto/manifest + branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}" + strategy: depend + +# --------------------------------------------------------------------------------------- +# Stage: check +# --------------------------------------------------------------------------------------- +check: + stage: check + rules: + - if: $CI_MERGE_REQUEST_IID + needs: ["integrate"] + tags: + - infrastructure + timeout: 5m + script: + - cd ${CI_PROJECT_DIR} + - .gitlab-ci/check_if_integration_branch_is_up_to_date.py + --gitlab-url=${CI_SERVER_URL} + --token=${GITBOT_TOKEN} + --manifest-project=${MANIFEST_PROJECT} + --integration-base=${MASTER_BRANCH_MANIFEST} + --project=${CI_PROJECT_PATH} + --merge-request=${CI_MERGE_REQUEST_IID} -- GitLab