From 80a233a030a74e60408a250e510d13457f6d569e Mon Sep 17 00:00:00 2001 From: s j <sj@1729.be> Date: Tue, 25 Oct 2022 11:12:04 +0200 Subject: [PATCH 1/2] imp: cleanup gitlabci odoo repo --- README.md | 14 +++++ docker.template.yml | 117 ---------------------------------------- odoo-tests.template.yml | 2 +- starter.gitlab-ci.yml | 15 ++++++ 4 files changed, 30 insertions(+), 118 deletions(-) create mode 100644 README.md delete mode 100644 docker.template.yml create mode 100644 starter.gitlab-ci.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..e1edff2 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +Gitlab CI template for ODOO +=========================== + +This repo contains a gitlab ci template to run a pipeline on your repo +similar to the OCA github actions (travis before). + +Getting started +--------------- + +To get started with this gitlab-ci copy the starter file to .gitlab-ci.yml and +adjust appropriately. + + + diff --git a/docker.template.yml b/docker.template.yml deleted file mode 100644 index 66cf601..0000000 --- a/docker.template.yml +++ /dev/null @@ -1,117 +0,0 @@ -variables: - BUILD_IMAGE: 0 - DOCKER_BUILD_DOCKER_IMAGE: "docker:19.03.12" - DOCKER_BUILD_DOCKER_DIND_IMAGE: "docker:19.03.12-dind" - -stages: - - build - - release - - deploy - -.build_image: - variables: - DOCKER_TLS_CERTDIR: "/certs" - DOCKER_BUILD_ARG: "" - stage: build - tags: - - dind - image: $DOCKER_BUILD_DOCKER_IMAGE - services: - - name: $DOCKER_BUILD_DOCKER_DIND_IMAGE - alias: docker - script: - - 'which ssh-agent || ( apk add --update openssh )' - - eval "$(ssh-agent -s)" - - if [ ! -z "${SSH_PRIVATE_KEY}" ]; then echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -; fi - - apk add gettext - - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY - # fetches the latest image (not failing if image is not found) - - docker pull $IMAGE:latest || true - # build the image - - > - cat $DOCKERFILE | envsubst '$$CI_COMMIT_SHA $$CI_REGISTRY_IMAGE $$CI_REPOSITORY_URL $$CI_SERVER_HOST $$CI_JOB_TOKEN $$PRIVATE_TOKEN' | - DOCKER_BUILDKIT=1 PROGRESS_NO_TRUNC=1 docker build - --ssh default - --pull - --progress=plain - --tag $IMAGE:$CI_COMMIT_SHA - $DOCKER_BUILD_ARG - . -f - - # FIXME: https://github.com/moby/buildkit/issues/569 - # --cache-from $IMAGE:latest - - docker push $IMAGE:$CI_COMMIT_SHA - -# Here, the goal is to tag the "master" branch as "latest" -.push_latest: - variables: - # We are just playing with Docker here. - # We do not need GitLab to clone the source code. - GIT_STRATEGY: none - DOCKER_TLS_CERTDIR: "/certs" - stage: release - tags: - - dind - image: $DOCKER_BUILD_DOCKER_IMAGE - services: - - name: $DOCKER_BUILD_DOCKER_DIND_IMAGE - alias: docker - rules: - # Only default branch should be tagged "latest" - - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - script: - - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY - # Because we have no guarantee that this job will be picked up by the same runner - # that built the image in the previous step, we pull it again locally - - docker pull $IMAGE:$CI_COMMIT_SHA - # Then we tag it "latest" - - docker tag $IMAGE:$CI_COMMIT_SHA $IMAGE:latest - # Annnd we push it. - - docker push $IMAGE:latest - -# Finally, the goal here is to Docker tag any Git tag -# GitLab will start a new pipeline everytime a Git tag is created, which is pretty awesome -.push_tag: - variables: - # Again, we do not need the source code here. Just playing with Docker. - GIT_STRATEGY: none - DOCKER_TLS_CERTDIR: "/certs" - PUSH_TAG: $CI_COMMIT_REF_NAME - stage: release - tags: - - dind - image: $DOCKER_BUILD_DOCKER_IMAGE - services: - - name: $DOCKER_BUILD_DOCKER_DIND_IMAGE - alias: docker - rules: - # We want this job to be run on tags only. - - if: $CI_COMMIT_TAG != null - script: - - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY - - docker pull $IMAGE:$CI_COMMIT_SHA - - docker tag $IMAGE:$CI_COMMIT_SHA $IMAGE:$PUSH_TAG - - docker push $IMAGE:$PUSH_TAG - -build_image: - extends: .build_image - rules: - - if: '$BUILD_IMAGE == "1"' - variables: - IMAGE: $CI_REGISTRY_IMAGE - DOCKERFILE: docker/Dockerfile.tmpl - -push_latest_image: - extends: .push_latest - needs: ["build_image"] - rules: - - if: '$BUILD_IMAGE == "1" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - variables: - IMAGE: $CI_REGISTRY_IMAGE - -push_tag_image: - extends: .push_tag - needs: ["build_image"] - rules: - - if: '$BUILD_IMAGE == "1" && $CI_COMMIT_TAG != null' - variables: - IMAGE: $CI_REGISTRY_IMAGE diff --git a/odoo-tests.template.yml b/odoo-tests.template.yml index 4f6b99c..fcf4d9b 100644 --- a/odoo-tests.template.yml +++ b/odoo-tests.template.yml @@ -7,7 +7,7 @@ variables: ODOO_REPO: "OCA/OCB" GIT_DEPTH: "3" # Lower clone depth for better performance ODOO_PRECOMMIT: "1" - ODOO_LINT: "1" + ODOO_LINT: "0" ODOO_TEST: "1" workflow: diff --git a/starter.gitlab-ci.yml b/starter.gitlab-ci.yml new file mode 100644 index 0000000..fbdf226 --- /dev/null +++ b/starter.gitlab-ci.yml @@ -0,0 +1,15 @@ +# Only run for (updates to) merge requests and the default branch. +workflow: + rules: + - if: $CI_MERGE_REQUEST_IID + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + +include: + - project: 'ci/gitlab-ci-templates' + ref: master + file: '/odoo-tests.template.yml' + +variables: + ODOO_PRECOMMIT: "1" + ODOO_LINT: "0" + ODOO_TEST: "1" -- GitLab From 40088188751f140f4383cafcd88407edb62647bd Mon Sep 17 00:00:00 2001 From: s j <sj@1729.be> Date: Wed, 26 Oct 2022 09:23:59 +0200 Subject: [PATCH 2/2] ref: unittest using github action tools instead of travis tools --- odoo-tests.template.yml | 54 +++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/odoo-tests.template.yml b/odoo-tests.template.yml index fcf4d9b..3ffa631 100644 --- a/odoo-tests.template.yml +++ b/odoo-tests.template.yml @@ -68,32 +68,34 @@ odoo-test: POSTGRES_DB: project_ci_test POSTGRES_USER: odoo POSTGRES_PASSWORD: "odoo" - LINT_CHECK: "0" - TESTS: "1" rules: - if: '$ODOO_TEST == "1"' script: - # prepare ci image - - rm /usr/bin/lessc - - rm /etc/odoo.cfg - - ln -s /root/.openerp_serverrc /etc/odoo.cfg - # We need to export the PG* here, otherwise the postgresql container - # will pick them up - - export PGHOST="postgres" - - export PGUSER="odoo" - - export PGPASSWORD="odoo" - # Add oca maintainer tools - - git clone https://github.com/OCA/maintainer-quality-tools.git -b master ${HOME}/maintainer-quality-tools - - export PATH=${HOME}/maintainer-quality-tools/travis:${HOME}/gitlab_tools:${PATH} - # Change oca_dependencies.txt formatting to fetch from private GitLab by changing to https and injecting the job token. - - sed -i -E "/^#/! s|(https://${CI_SERVER_HOST})(.*\.git)|https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}\2|g; /^#/! s|(git@${CI_SERVER_HOST}:)(.*\.git)|https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/\2|g" oca_dependencies.txt - # Change oca_dependencies.txt formatting to fetch from github.com-enterprise to fetch using CI_ENTERPRISE_TOKEN - - sed -i -E "/^#/! s|(git@github.com-enterprise:)(.*\.git)|https://${CI_ENTERPRISE_TOKEN}@github.com/\2|g" oca_dependencies.txt - # mimick travis_install_nightly - - ln -s /opt/odoo ${HOME}/OCB-${VERSION} - - clone_oca_dependencies - - cp ${HOME}/maintainer-quality-tools/cfg/.coveragerc . - # run tests - - travis_run_tests - - coverage report --show-missing - coverage: '/TOTAL.+ ([0-9]{1,3}%)/' + - oca_install_addons + - oca_init_test_database + - oca_run_tests + + # # prepare ci image + # - rm /usr/bin/lessc + # - rm /etc/odoo.cfg + # - ln -s /root/.openerp_serverrc /etc/odoo.cfg + # # We need to export the PG* here, otherwise the postgresql container + # # will pick them up + # - export PGHOST="postgres" + # - export PGUSER="odoo" + # - export PGPASSWORD="odoo" + # # Add oca maintainer tools + # - git clone https://github.com/OCA/maintainer-quality-tools.git -b master ${HOME}/maintainer-quality-tools + # - export PATH=${HOME}/maintainer-quality-tools/travis:${HOME}/gitlab_tools:${PATH} + # # Change oca_dependencies.txt formatting to fetch from private GitLab by changing to https and injecting the job token. + # - sed -i -E "/^#/! s|(https://${CI_SERVER_HOST})(.*\.git)|https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}\2|g; /^#/! s|(git@${CI_SERVER_HOST}:)(.*\.git)|https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/\2|g" oca_dependencies.txt + # # Change oca_dependencies.txt formatting to fetch from github.com-enterprise to fetch using CI_ENTERPRISE_TOKEN + # - sed -i -E "/^#/! s|(git@github.com-enterprise:)(.*\.git)|https://${CI_ENTERPRISE_TOKEN}@github.com/\2|g" oca_dependencies.txt + # # mimick travis_install_nightly + # - ln -s /opt/odoo ${HOME}/OCB-${VERSION} + # - clone_oca_dependencies + # - cp ${HOME}/maintainer-quality-tools/cfg/.coveragerc . + # # run tests + # - travis_run_tests + # - coverage report --show-missing + # coverage: '/TOTAL.+ ([0-9]{1,3}%)/' -- GitLab