From dc97f3f6e1a791031c11bcabb1c91e6cdb7d9576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6ppner?= <jonas.hoeppner@garz-fricke.com> Date: Fri, 18 Mar 2022 11:59:06 +0100 Subject: [PATCH] CI: Add .gitlab-ci.yml for foobar manifest project to gitlab-ci repo To have one repo for all the CI implementation move also the manifests yml file here. BCS 746-000646 --- foobar-manifest.yml | 211 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 foobar-manifest.yml diff --git a/foobar-manifest.yml b/foobar-manifest.yml new file mode 100644 index 00000000..849f8da7 --- /dev/null +++ b/foobar-manifest.yml @@ -0,0 +1,211 @@ +# -------------------------------------------------------------------------------------- +# Global +# -------------------------------------------------------------------------------------- +--- +stages: + - retrigger + - build + - test + +variables: + # CI_IMAGES_BASEPATH: Environment variable configure in gitlab + CI_IMAGES_PATH: ${CI_IMAGES_BASEPATH}/ci-images + CI_IMAGES_REV: 835a7096092eef5cecde23fd933209e7a8488637 + CI_IMAGE_PYTHON: "${CI_IMAGES_PATH}/python/3.9:${CI_IMAGES_REV}" + CI_IMAGE_YOCTO: "${CI_IMAGES_PATH}/yocto-build/ubuntu-20.04:${CI_IMAGES_REV}" + # The master branch is hardcoded here, because it cannot be determined automatically. + # Has to be modified for new branches, e.g. new Yocto versions or fix releases. + MASTER_BRANCH: master + +workflow: + rules: + # Explicitly allow externally triggered pipelines in every case + - if: $CI_PIPELINE_SOURCE == "pipeline" || $CI_PIPELINE_SOURCE == "api" + # Do not run pipelines for merge requests + - if: $CI_MERGE_REQUEST_IID + when: never + # Do not run pipelines on forked projects + # (use id instead of name because of rename) + - if: $CI_PROJECT_ID != "21745909" + when: never + # Do not run pipelines on integration branches, except from gitlab-ci repo + - if: $CI_COMMIT_REF_NAME =~ /^integrate\/.*/ && + $CI_COMMIT_REF_NAME !~ /^integrate\/gitlab-ci\/.*/ + when: never + # In all other cases, run the pipeline automatically + - when: always + + +# -------------------------------------------------------------------------------------- +# Stage: retrigger +# -------------------------------------------------------------------------------------- +retrigger: + stage: retrigger + rules: + - if: $CI_COMMIT_REF_NAME == $MASTER_BRANCH && $CI_PIPELINE_SOURCE != "api" + tags: + - infrastructure + timeout: 2m + image: ${CI_IMAGE_PYTHON} + variables: + # Include git submodules + GIT_SUBMODULE_STRATEGY: recursive + script: + - PROJECTS=$( + .gitlab-ci/get_manifest_projects.py + --manifest=default.xml + --remote=ci-test + ) + - echo -e "Projects:\n${PROJECTS}" + - for PROJECT in ${PROJECTS}; do + .gitlab-ci/retrigger_mr_pipeline_jobs.py + --gitlab-url=${CI_SERVER_URL} + --token=${GITBOT_TOKEN} + --project=${PROJECT} + --state=opened + --target-branch=${MASTER_BRANCH} + --job=check + ; + done + +# -------------------------------------------------------------------------------------- +# Stage: build +# -------------------------------------------------------------------------------------- +.setup_ssh: &setup_ssh + # setup ssh key to access private repos + # https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + # add content of variable SSH_KNOWN_HOSTS to known hosts + # https://docs.gitlab.com/ee/ci/ssh_keys/#verifying-the-ssh-host-keys + - echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + +.repo_checkout: &repo_checkout + # setup build dir + - cd ${CI_PROJECT_DIR} + - repo init -u ${CI_REPOSITORY_URL} -b refs/pipelines/${CI_PIPELINE_ID} + - repo sync --detach --current-branch --no-tags --force-remove-dirty + --optimized-fetch --force-sync + +.build: &build + - 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) + - DIFF=$((BAR_FILES-FOO_FILES)) + - (($DIFF >= -1 && $DIFF <= 1)) + +build:files: + stage: build + rules: + - if: $CI_COMMIT_REF_NAME != $MASTER_BRANCH || $CI_PIPELINE_SOURCE == "api" + needs: [] + tags: + - infrastructure + timeout: 2m + image: + name: "${CI_IMAGE_YOCTO}" + # Override entrypoint so we can pass --id to set the UID and GID for the user that + # is created in the container. This is a feature of the crops/poky images. + # See poky-entry.py for details. + entrypoint: + - "/usr/bin/distro-entry.sh" + - "/usr/bin/dumb-init" + - "--" + - "/usr/bin/poky-entry.py" + - "--id=118:998" + variables: + GIT_STRATEGY: none + before_script: + - *setup_ssh + script: + - *repo_checkout + - *build + artifacts: + expire_in: 7d + paths: + - files-* + +build:echo: + stage: build + rules: + - if: $CI_COMMIT_REF_NAME != $MASTER_BRANCH || $CI_PIPELINE_SOURCE == "api" + needs: [] + tags: + - infrastructure + timeout: 2m + image: ${CI_IMAGE_PYTHON} + script: + - printenv + - echo "Build successful" + +build:merge_request: + stage: build + rules: + - if: $CI_COMMIT_REF_NAME == $MASTER_BRANCH && $CI_PIPELINE_SOURCE != "api" + needs: [] + tags: + - infrastructure + timeout: 2m + image: ${CI_IMAGE_PYTHON} + variables: + # Include git submodules + GIT_SUBMODULE_STRATEGY: recursive + script: + - cd ${CI_PROJECT_DIR} + # Get pipeline for merge request + - MR_PIPELINE=$(.gitlab-ci/get_pipelines.py + --gitlab-url=${CI_SERVER_URL} + --token=${GITBOT_TOKEN} + --project=${CI_PROJECT_PATH} + --commit=${CI_COMMIT_SHA} + --ref=^${MASTER_BRANCH} || true | head -1) + # If pipeline exists, mirror its result + - if [ ! -z "${MR_PIPELINE}" ]; then + .gitlab-ci/mirror_pipeline_result.py + --gitlab-url=${CI_SERVER_URL} + --token=${GITBOT_TOKEN} + --project=${CI_PROJECT_PATH} + --pipeline=${MR_PIPELINE} + # If no pipeline found, trigger a new one on the master + - else + .gitlab-ci/trigger_pipeline.py + --gitlab-url=${CI_SERVER_URL} + --token=${GITBOT_TOKEN} + --project=${CI_PROJECT_PATH} + --ref=${MASTER_BRANCH} + - fi + + +# -------------------------------------------------------------------------------------- +# Stage: test +# -------------------------------------------------------------------------------------- +.test: + stage: test + rules: + - if: $CI_COMMIT_REF_NAME != $MASTER_BRANCH || $CI_PIPELINE_SOURCE == "api" + when: manual + allow_failure: true + tags: + - infrastructure + image: ${CI_IMAGE_PYTHON} + script: + - exit ${RETURNCODE} + +test:pass: + extends: + - .test + variables: + RETURNCODE: 0 + +test:fail: + extends: + - .test + variables: + RETURNCODE: 1 -- GitLab