From e11c5cbf0fd05cb2d4a92e97220c86b12d729c9c Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Tue, 11 Jun 2019 22:17:05 +0200
Subject: [PATCH] [enh] #149: Set-up CI/CD adding .gitlab-ci.yml file

- #245: Use own built images with Poetry
- Checks: build, format
- Use Black installed from Docker image v3.8
- tests: Pytest for Python v3.5, 3.6, 3.7 (+ coverage), and 3.8
- Coverage published to GitLab Pages once tests-3.7 job is done
---
 .gitlab-ci.yml | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 00000000..62cc5576
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,80 @@
+stages:
+  - checks
+  - tests
+  - coverage
+
+variables:
+  DOCKER_IMAGE: "registry.duniter.org/docker/python3/poetry"
+  PYTHON_VERSION: "3.7"
+
+image: $DOCKER_IMAGE/$PYTHON_VERSION:latest
+
+.code_changes:
+  only:
+    changes:
+      - bin/silkaj
+      - silkaj/*.py
+      - tests/*.py
+
+.changes:
+  extends: .code_changes
+  only:
+    changes:
+      - .gitlab-ci.yml
+      - pyproject.toml
+      - poetry.lock
+
+build:
+  extends: .changes
+  stage: checks
+  script:
+    - poetry build
+
+format:
+  extends: .code_changes
+  stage: checks
+  image: $DOCKER_IMAGE/3.8:latest
+  script:
+    - black --check bin silkaj tests
+
+.tests:
+  extends: .changes
+  stage: tests
+  image: $DOCKER_IMAGE/$PYTHON_VERSION:latest
+  script:
+    - poetry install
+    - poetry run pytest
+
+tests-3.5:
+  extends: .tests
+  variables:
+    PYTHON_VERSION: "3.5"
+
+tests-3.6:
+  extends: .tests
+  variables:
+    PYTHON_VERSION: "3.6"
+
+tests-3.7-coverage:
+  extends: .tests
+  script:
+    - poetry install
+    - poetry run pytest --cov silkaj --cov-report html:cov_html
+  artifacts:
+    paths:
+      - cov_html
+
+tests-3.8:
+  extends: .tests
+  variables:
+    PYTHON_VERSION: "3.8"
+
+pages:
+  extends: .code_changes
+  needs: [tests-3.7-coverage]
+  stage: coverage
+  script: mv cov_html/ public/
+  artifacts:
+    paths:
+      - public
+    expire_in: 2 days
-- 
GitLab