From cf5a5e4bf5badc48b0fbb9499a17c275e63b226e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6z=C3=BCkan=20Hande?= <hande.gozukan@inria.fr> Date: Wed, 17 Jan 2024 08:17:43 +0000 Subject: [PATCH 1/9] Enh practical 5 --- docker/Dockerfile | 2 +- practical/5.yml_for_docker.md | 65 ++++++++++++++--------------------- 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 3d0f1c8..85cf0f7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12-slim-bookworm +FROM python:3.12-bookworm WORKDIR /tmp diff --git a/practical/5.yml_for_docker.md b/practical/5.yml_for_docker.md index dae21eb..4186414 100644 --- a/practical/5.yml_for_docker.md +++ b/practical/5.yml_for_docker.md @@ -4,16 +4,11 @@ ## 1st version - Create a job to build Docker image -Create a new job with name `build docker` using [image](https://docs.gitlab.com/ee/ci/yaml/#image) `docker:20.10.16`. +- Create a new job with name `build docker` using [image](https://docs.gitlab.com/ee/ci/yaml/#image) `docker:20.10.16`. -Set the [stage](https://docs.gitlab.com/ee/ci/yaml/#stage) of the job as -`.pre`. It will run before all defined stages in the `.gilab-ci.yml` file. +- Set the `stage` of the job as `.pre`. It will run before all defined stages in the `.gilab-ci.yml` file. -As we are going to build a Docker image, we need Docker commands available. In -that case, we need to use a `Docker-in-Docker` (dind) image. Specify -this in [services](https://docs.gitlab.com/ee/ci/yaml/#services) section. - -Add the steps to [build the Docker image](../docker/README.md#build-docker-image). +- Modify `script` section to add the steps to [build the Docker image](../docker/README.md#build-docker-image). ```yml build docker: @@ -22,43 +17,39 @@ build docker: tags: - ci.inria.fr # For using shared runners - small # For selecting small shared runners - services: - - docker:20.10.16-dind script: (...) ``` -Verify the CI is launched and successful. +- Verify the CI is launched and successful. ## 2nd version - Name the Docker image using Predefined CI Variables. -[Authenticate with the GitLab container registry](https://docs.gitlab.com/ee/user/packages/container_registry/authenticate_with_container_registry.html) using -[before_script](https://docs.gitlab.com/ee/ci/yaml/#before_script) section -together with [Predefined GitLab CI variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html) +- Add [before_script](https://docs.gitlab.com/ee/ci/yaml/#before_script) + section to [Authenticate with the GitLab container registry](https://docs.gitlab.com/ee/user/packages/container_registry/authenticate_with_container_registry.html) using [Predefined GitLab CI variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html) `CI_REGISTRY_USER`, `CI_REGISTRY_PASSWORD` and `CI_REGISTRY`. | Variable | Description | | -------- | ----------- | -| CI_REGISTRY_USER | The username to push containers to the project’s GitLab container registry. Only available if the container registry is enabled for the project. | -| CI_REGISTRY_PASSWORD | The password to push containers to the GitLab project’s container registry. Only available if the container registry is enabled for the project. This password value is the same as the CI_JOB_TOKEN and is valid only as long as the job is running. Use the CI_DEPLOY_PASSWORD for long-lived access to the registry | +| CI_REGISTRY_USER | The username to push containers to the project’s GitLab container registry. Only available if the container registry is enabled for the project. Its value is `gitlab-ci-token`. | +| CI_REGISTRY_PASSWORD | The password to push containers to the GitLab project’s container registry. Only available if the container registry is enabled for the project. This password value is the same as the CI_JOB_TOKEN and is valid only as long as the job is running. Use the CI_DEPLOY_PASSWORD for long-lived access to the registry. | | CI_REGISTRY | Address of the container registry server, formatted as <host>[:<port>]. For example: registry.gitlab.example.com. Only available if the container registry is enabled for the GitLab instance. | ```yml tags: (...) - services: - (...) before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: (...) ``` -Use [variables](https://docs.gitlab.com/ee/ci/yaml/#variables) section and -Predefined GitLab CI variables `CI_REGISTRY_IMAGE` and `CI_COMMIT_REF_SLUG` to -define $IMAGE_TAG as a variable. (To be able to push to GitLab registry, image -names should follow the container registry naming convention. This name is -provided by `CI_REGISTRY_IMAGE` variable. Instead of tagging the image with `v1`, we can use `CI_COMMIT_REF_SLUG` and tag using the branch name.) +- Define `IMAGE_TAG` as a variable using +[variables](https://docs.gitlab.com/ee/ci/yaml/#variables) section and Predefined GitLab CI variables `CI_REGISTRY_IMAGE` and `CI_COMMIT_REF_SLUG`. +> To be able to push to GitLab registry, image names should follow the container +registry naming convention. This name is provided by `CI_REGISTRY_IMAGE` +variable. Instead of tagging the image with `v1`, we can use +`CI_COMMIT_REF_SLUG` and tag using the branch name. | Variable | Description | | -------- | ----------- | @@ -66,9 +57,6 @@ provided by `CI_REGISTRY_IMAGE` variable. Instead of tagging the image with `v1` | CI_COMMIT_REF_SLUG | `CI_COMMIT_REF_NAME` in lowercase, shortened to 63 bytes, and with everything except 0-9 and a-z replaced with -. No leading / trailing -. Use in URLs, host names and domain names. | ```yml - - services: - (...) variables: IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG before_script: @@ -79,9 +67,9 @@ provided by `CI_REGISTRY_IMAGE` variable. Instead of tagging the image with `v1` ``` -Modify script to build Docker image using `IMAGE_TAG` variable. +- Modify `script` section to build Docker image using `IMAGE_TAG` variable. -Modify script to push generated image to GitLab container registry. +- Modify `script` section to push generated Docker image to GitLab container registry. ```yml @@ -96,18 +84,19 @@ Modify script to push generated image to GitLab container registry. - docker push $IMAGE_TAG ``` -Verify the CI is launched and successful. +- Verify the CI is launched and successful. + +- Verify that the Docker image is saved in the GitLab container registry. -Verify that the Docker image is saved in the GitLab container registry. -- On the left sidebar in the GitLab interface, go to **Deploy** → **Container Registry**. + o On the left sidebar in the GitLab interface, go to **Deploy** → **Container Registry**. ## 3rd version - Use Docker Image for CI Jobs -Move `variables` section to global level. +- Move `variables` section to global level. -Update image used by job `test python 3.12` with `$IMAGE_TAG`. +- Update `image` section of job `test python 3.12` with `$IMAGE_TAG`. -Update image used by job `pages` with `$IMAGE_TAG`. +- Update `image` section of job `pages` with `$IMAGE_TAG`. ```yml variables: @@ -119,8 +108,6 @@ build docker: tags: - ci.inria.fr # For using shared runners - small # For selecting small shared runners - services: - - docker:20.10.16-dind before_script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY script: @@ -137,7 +124,7 @@ test python 3.12: - small script: - pip install -e . - - pytest + - pytest --cov=projection --cov-report=html test python 3.11: image: python:3.11 @@ -147,7 +134,7 @@ test python 3.11: - small script: - pip install -e .[test] - - pytest --cov=projection --cov-report=html + - pytest artifacts: paths: - htmlcov @@ -170,4 +157,4 @@ pages: - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH ``` -Verify the CI is launched and successful. +- Verify the CI is launched and successful. -- GitLab From 5a2aaebc05759135fbae900072f41e5f780379ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hande=20G=C3=B6z=C3=BCkan?= <hande@ginkgo.work> Date: Wed, 17 Jan 2024 11:15:33 +0100 Subject: [PATCH 2/9] itemize --- practical/3.yml_for_unitary_tests.md | 34 +++++++++++++++------------- practical/4.yml_for_doc_build.md | 5 ++-- practical/5.yml_for_docker.md | 3 +-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/practical/3.yml_for_unitary_tests.md b/practical/3.yml_for_unitary_tests.md index 1625184..4e10fbf 100644 --- a/practical/3.yml_for_unitary_tests.md +++ b/practical/3.yml_for_unitary_tests.md @@ -2,7 +2,7 @@ ## 1st version - Projection installation -Add the following `.gitlab-ci.yml` file at the git repository root in order to +- Add the following `.gitlab-ci.yml` file at the git repository root in order to [install the projection module](../README.md#install-projection-with-pip): ```yml @@ -18,7 +18,7 @@ tests: - echo "Projection is installed" ``` -Add the `.gitlab-ci.yml` file, commit and push your modifications: +- Add the `.gitlab-ci.yml` file, commit and push your modifications: ```bash git add .gitlab-ci.yml @@ -26,24 +26,25 @@ git commit -m "First version - Projection installation in CI" git push ``` -Verify the CI is launched and successful: -- On the left sidebar in the Gitlab interface, go to **Build** → **Jobs**. -- Check the job is passed. -- Click on the **Passed** icon and verify the logs. +- Verify the CI is launched and successful: + + - On the left sidebar in the Gitlab interface, go to **Build** → **Jobs**. + - Check the job is passed. + - Click on the **Passed** icon and verify the logs. ## 2nd version - Projection tests -Add the required steps in the `script` section of the `.gitlab-ci.yml` file to [run the tests](../README.md#run-the-tests). +- Add the required steps in the `script` section of the `.gitlab-ci.yml` file to [run the tests](../README.md#run-the-tests). -Add the `.gitlab-ci.yml` file, commit and push your modifications. +- Add the `.gitlab-ci.yml` file, commit and push your modifications. -Verify the CI is launched and successful. +- Verify the CI is launched and successful. ## 3rd version - Projection tests coverage report -Modify how [the tests are run](../README.md#run-the-tests) to produce the coverage report. +- Modify how [the tests are run](../README.md#run-the-tests) to produce the coverage report. -Provide the coverage report as an artifact by adding in the `.gitlab-ci.yml` file: +- Provide the coverage report as an artifact by adding in the `.gitlab-ci.yml` file: ```yml script: - pip install -e . @@ -54,11 +55,12 @@ Provide the coverage report as an artifact by adding in the `.gitlab-ci.yml` fil - htmlcov ``` -Verify the CI is launched and successful: -- On the left sidebar in the Gitlab interface, go to **Build** → **Jobs**. -- Check the job is passed. -- Click on the **Passed** icon and verify the logs. -- On the right sidebar in the Gitlab interface, browse the job artifact. +- Verify the CI is launched and successful: + + - On the left sidebar in the Gitlab interface, go to **Build** → **Jobs**. + - Check the job is passed. + - Click on the **Passed** icon and verify the logs. + - On the right sidebar in the Gitlab interface, browse the job artifact. ## 4th version (OPTIONAL) diff --git a/practical/4.yml_for_doc_build.md b/practical/4.yml_for_doc_build.md index bdc9f19..a73ad00 100644 --- a/practical/4.yml_for_doc_build.md +++ b/practical/4.yml_for_doc_build.md @@ -59,9 +59,8 @@ directory as artifact, `pages:deploy` job has failed. - Verify the CI is launched and successful. - Verify that the html pages are published. - - o On the left sidebar in the GitLab interface, go to **Deploy** → **Pages**. - o Click on link provided in the **Access Pages** section. + - On the left sidebar in the GitLab interface, go to **Deploy** → **Pages**. + - Click on link provided in the **Access Pages** section. ## 3rd version - Build documentation only for default branch (OPTIONAL) diff --git a/practical/5.yml_for_docker.md b/practical/5.yml_for_docker.md index 3266849..8d4c91f 100644 --- a/practical/5.yml_for_docker.md +++ b/practical/5.yml_for_docker.md @@ -87,8 +87,7 @@ variable. Instead of tagging the image with `v1`, we can use - Verify the CI is launched and successful. - Verify that the Docker image is saved in the GitLab container registry. - - o On the left sidebar in the GitLab interface, go to **Deploy** → **Container Registry**. + - On the left sidebar in the GitLab interface, go to **Deploy** → **Container Registry**. ## 3rd version - Use Docker Image for CI Jobs -- GitLab From 9d4edcec9e1593f26e2c0d3e9506dc262c306ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hande=20G=C3=B6z=C3=BCkan?= <hande@ginkgo.work> Date: Wed, 17 Jan 2024 11:25:33 +0100 Subject: [PATCH 3/9] update CI verification steps --- practical/3.yml_for_unitary_tests.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/practical/3.yml_for_unitary_tests.md b/practical/3.yml_for_unitary_tests.md index 4e10fbf..6a31fad 100644 --- a/practical/3.yml_for_unitary_tests.md +++ b/practical/3.yml_for_unitary_tests.md @@ -29,8 +29,9 @@ git push - Verify the CI is launched and successful: - On the left sidebar in the Gitlab interface, go to **Build** → **Jobs**. - - Check the job is passed. - - Click on the **Passed** icon and verify the logs. + - Check the job is running. + - Click on the **Running** icon and verify the logs. + - See the job is passed. ## 2nd version - Projection tests -- GitLab From 2ced55e6c1a521f2bd45e26068d028bdb54aa342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hande=20G=C3=B6z=C3=BCkan?= <hande@ginkgo.work> Date: Wed, 17 Jan 2024 12:35:59 +0100 Subject: [PATCH 4/9] update coverage commands --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e5fe2ec..2c610f4 100644 --- a/README.md +++ b/README.md @@ -65,12 +65,37 @@ Then execute the following command from project root directory: pytest ``` -To run the tests and create coverage report: +To run the tests and view coverage report in terminal window: + +```bash + pytest --cov=projection --cov-report term-missing +``` + +To run the tests and create coverage report in html format: ```bash pytest --cov=projection --cov-report=html ``` +This will generate coverage report in html format under the `htmlcov` directory +in the project's root directory. + +To run the tests and create coverage report in xml format: + +```bash + pytest --cov=projection --cov-report xml:coverage.xml +``` + +This will generate coverage report in xml format under in the project's root directory. + +It is possible to combine the commands to generate all at once: + +```bash + pytest --cov=projection --cov-report term-missing \ + --cov-report=html \ + --cov-report xml:coverage.xml +``` + ## Build documentation To build documentation, install `projection` package with `doc` option which -- GitLab From 35c5cbce23fae1e2889b323647657ec5c90bb95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hande=20G=C3=B6z=C3=BCkan?= <hande@ginkgo.work> Date: Wed, 17 Jan 2024 12:37:55 +0100 Subject: [PATCH 5/9] add part to make coverage work with merge requests and badge --- practical/3.yml_for_unitary_tests.md | 32 +++++++++++++++++++++++++++- practical/5.yml_for_docker.md | 14 ++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/practical/3.yml_for_unitary_tests.md b/practical/3.yml_for_unitary_tests.md index 6a31fad..b0f04a4 100644 --- a/practical/3.yml_for_unitary_tests.md +++ b/practical/3.yml_for_unitary_tests.md @@ -43,7 +43,8 @@ git push ## 3rd version - Projection tests coverage report -- Modify how [the tests are run](../README.md#run-the-tests) to produce the coverage report. +- Modify how [the tests are run](../README.md#run-the-tests) to produce the + coverage report in html format. - Provide the coverage report as an artifact by adding in the `.gitlab-ci.yml` file: ```yml @@ -86,6 +87,35 @@ To do so on this project: - Badge Image URL: `https://gitlab.inria.fr/%{project_path}/badges/%{default_branch}/coverage.svg` - Click on the **Add badge** button. +- Modify `script` section to generate coverage report both in html and xml formats. + +- Add [coverage](https://docs.gitlab.com/16.7/ee/ci/yaml/index.html#coverage) +section to project’s `.gitlab-ci.yml` file to provide test coverage results to +a merge request. Provided regex is used to find the coverage in the tool’s +output. + +- Add [reports](https://docs.gitlab.com/ee/ci/yaml/index.html#artifactsreports) + section to `artifacts` and specify `coverage.xml` for coverage analysis to + work. + +> Here we still keep `artifacts:paths` part as report artifacts are not + downloadable from the job details page. + +```yml + script: + - (...) + - pytest --cov=projection --cov-report term-missing --cov-report xml:coverage.xml --cov-report html + coverage: '/^TOTAL.+?(\d+\%)$/' + artifacts: + reports: + coverage_report: + coverage_format: cobertura + path: coverage.xml + paths: + - htmlcov + - coverage.xml +``` + ## 5th version Let's introduce another useful feature of GitLab-CI: [the pipelines](https://docs.gitlab.com/ee/ci/pipelines/). diff --git a/practical/5.yml_for_docker.md b/practical/5.yml_for_docker.md index 8d4c91f..c3fccc3 100644 --- a/practical/5.yml_for_docker.md +++ b/practical/5.yml_for_docker.md @@ -123,7 +123,16 @@ test python 3.12: - small script: - pip install -e . - - pytest --cov=projection --cov-report=html + - pytest --cov=projection --cov-report term-missing --cov-report xml:coverage.xml --cov-report html + coverage: '/^TOTAL.+?(\d+\%)$/' + artifacts: + reports: + coverage_report: + coverage_format: cobertura + path: coverage.xml + paths: + - htmlcov + - coverage.xml test python 3.11: image: python:3.11 @@ -134,9 +143,6 @@ test python 3.11: script: - pip install -e .[test] - pytest - artifacts: - paths: - - htmlcov pages: image: $IMAGE_TAG -- GitLab From 8060965149f01e8d23d473f39beb19fcd2a193fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hande=20G=C3=B6z=C3=BCkan?= <hande@ginkgo.work> Date: Wed, 17 Jan 2024 12:40:39 +0100 Subject: [PATCH 6/9] add heading for coverage section --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c610f4..74508f3 100644 --- a/README.md +++ b/README.md @@ -65,13 +65,14 @@ Then execute the following command from project root directory: pytest ``` +#### Test coverage To run the tests and view coverage report in terminal window: ```bash pytest --cov=projection --cov-report term-missing ``` -To run the tests and create coverage report in html format: +To run the tests and generate coverage report in `html` format: ```bash pytest --cov=projection --cov-report=html @@ -80,7 +81,7 @@ To run the tests and create coverage report in html format: This will generate coverage report in html format under the `htmlcov` directory in the project's root directory. -To run the tests and create coverage report in xml format: +To run the tests and generate coverage report in `xml` format: ```bash pytest --cov=projection --cov-report xml:coverage.xml -- GitLab From 34d1eb44ed6faf5993a2d49712f37cf275ca9d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hande=20G=C3=B6z=C3=BCkan?= <hande@ginkgo.work> Date: Wed, 17 Jan 2024 12:46:50 +0100 Subject: [PATCH 7/9] minor enh --- practical/3.yml_for_unitary_tests.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/practical/3.yml_for_unitary_tests.md b/practical/3.yml_for_unitary_tests.md index b0f04a4..bffb114 100644 --- a/practical/3.yml_for_unitary_tests.md +++ b/practical/3.yml_for_unitary_tests.md @@ -44,7 +44,7 @@ git push ## 3rd version - Projection tests coverage report - Modify how [the tests are run](../README.md#run-the-tests) to produce the - coverage report in html format. + coverage report in `html` format. - Provide the coverage report as an artifact by adding in the `.gitlab-ci.yml` file: ```yml @@ -87,7 +87,7 @@ To do so on this project: - Badge Image URL: `https://gitlab.inria.fr/%{project_path}/badges/%{default_branch}/coverage.svg` - Click on the **Add badge** button. -- Modify `script` section to generate coverage report both in html and xml formats. +- Modify `script` section to generate coverage report both in `html` and `xml` formats. - Add [coverage](https://docs.gitlab.com/16.7/ee/ci/yaml/index.html#coverage) section to project’s `.gitlab-ci.yml` file to provide test coverage results to -- GitLab From 4d454dcd8c7b9d849a22cb71068559389e8b7171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hande=20G=C3=B6z=C3=BCkan?= <hande@ginkgo.work> Date: Wed, 17 Jan 2024 12:49:20 +0100 Subject: [PATCH 8/9] remove unnecessary line --- practical/3.yml_for_unitary_tests.md | 1 - 1 file changed, 1 deletion(-) diff --git a/practical/3.yml_for_unitary_tests.md b/practical/3.yml_for_unitary_tests.md index bffb114..d1978aa 100644 --- a/practical/3.yml_for_unitary_tests.md +++ b/practical/3.yml_for_unitary_tests.md @@ -104,7 +104,6 @@ output. ```yml script: - (...) - - pytest --cov=projection --cov-report term-missing --cov-report xml:coverage.xml --cov-report html coverage: '/^TOTAL.+?(\d+\%)$/' artifacts: reports: -- GitLab From 379ce0c3bb9aae558c5f154167113ff17835d5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hande=20G=C3=B6z=C3=BCkan?= <hande@ginkgo.work> Date: Wed, 17 Jan 2024 12:51:08 +0100 Subject: [PATCH 9/9] minor enh --- practical/3.yml_for_unitary_tests.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/practical/3.yml_for_unitary_tests.md b/practical/3.yml_for_unitary_tests.md index d1978aa..cb3b8cc 100644 --- a/practical/3.yml_for_unitary_tests.md +++ b/practical/3.yml_for_unitary_tests.md @@ -27,7 +27,6 @@ git push ``` - Verify the CI is launched and successful: - - On the left sidebar in the Gitlab interface, go to **Build** → **Jobs**. - Check the job is running. - Click on the **Running** icon and verify the logs. @@ -58,7 +57,6 @@ git push ``` - Verify the CI is launched and successful: - - On the left sidebar in the Gitlab interface, go to **Build** → **Jobs**. - Check the job is passed. - Click on the **Passed** icon and verify the logs. @@ -98,7 +96,7 @@ output. section to `artifacts` and specify `coverage.xml` for coverage analysis to work. -> Here we still keep `artifacts:paths` part as report artifacts are not +> Here we still keep `artifacts:paths` part as `reports` artifacts are not downloadable from the job details page. ```yml -- GitLab