-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
97 lines (87 loc) · 2.88 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# List of stages (jobs on the same stage run in parallel). Unused stages are ignored.
# See https://docs.gitlab.com/ee/ci/yaml/#stages
stages:
- build
- test
- deploy
# Set some environment variables based on Gitlab-specific variables
# See https://docs.gitlab.com/ee/ci/variables/
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"
# Global cache settings for test jobs (each job by default uses own copy of these settings)
# If key files do not change, restore the listed paths from cache (if cached).
# At the end, store those directories in cache.
# See https://docs.gitlab.com/ee/ci/caching/
cache: &global_cache
key:
files:
- poetry.lock
- .pre-commit-config.yaml
prefix: $CI_JOB_NAME
paths:
- .cache
- .venv
policy: pull-push
# Prepare environment with all required tools.
# Defined as hidden job (starting with dot) + YAML anchor (for referencing)
# See https://docs.gitlab.com/ee/ci/yaml/#anchors
.prepare-env-template: &prepare-env
before_script:
- pip install pipx==1.2.0
- pipx ensurepath
- pipx install poetry
- export PATH="${PATH}:~/.local/bin" # put poetry on PATH
- ln -s ~/.local/bin/poetry /usr/bin/poetry # for poe (PATH is set only locally)
- poetry --version
- poetry config virtualenvs.in-project true
- poetry install --no-root
- source .venv/bin/activate
# ----
# Generate docs and expose as Gitlab job artifact, so that it can be downloaded.
# If Gitlab Pages is enabled on your instance, better serve the documentation there.
# In that case, you should use `mike` to provide documentaion for each tagged version.
# See https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#access-the-latest-job-artifacts-by-url
# and https://stackoverflow.com/a/72481235
make-docs:
image: python:latest
stage: deploy
<<: *prepare-env
script:
- poetry install --with docs
- OFFLINE=true poetry run poe docs # generate docs
artifacts:
paths:
- site/
# Run pre-commit, just to make sure the developers did not mess up.
# It uses its own cache for its isolated environments (location: PRE_COMMIT_HOME).
run-pre-commit:
image: python:latest
stage: build
<<: *prepare-env
script:
- poetry run poe lint --all-files
- pipx install safety
- safety check -r pyproject.toml
# ----
# Test job template (combine with image(s) containing a specific Python version):
.run-pytest-template: &run-pytest
stage: test
<<: *prepare-env
script:
- poetry install
- poetry run poe test --cov --junitxml=report.xml
artifacts:
when: always
reports:
junit: report.xml # for Gitlab integration of test results
# Tests, instantiated with different Python versions:
run-pytest-3.8:
image: python:3.8
<<: *run-pytest
run-pytest-3.9:
image: python:3.9
<<: *run-pytest
run-pytest-3.10:
image: python:3.10
<<: *run-pytest