-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
135 lines (119 loc) · 3.63 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# This file is a template, and might need editing before it works on your project.
stages:
- prepare
- test
- finalize
- release
variables:
# Change cache dirs to be inside the project (can only cache local items)
PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache/pip
PIPX_HOME: $CI_PROJECT_DIR/.cache/pipx
PRE_COMMIT_HOME: $CI_PROJECT_DIR/.cache/pre-commit
# Coveralls configuration
CI_NAME: gitlab-ci
CI_BRANCH: $CI_COMMIT_REF_NAME
CI_BUILD_NUMBER: $CI_PIPELINE_ID
CI_BUILD_URL: $CI_PIPELINE_URL
# TODO: You will also need to set `COVERALLS_REPO_TOKEN` to work with coveralls.
# We recommend that you do that via GitLab CI web interface.
# - https://coveralls-python.readthedocs.io/en/latest/usage/index.html
# - https://docs.gitlab.com/ee/ci/variables/
workflow:
rules:
# Restrict the number of times the pipeline runs to save resources/limits
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
variables:
# Specific merge request configurations for coveralls
CI_BRANCH: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
CI_PULL_REQUEST: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == 'push'
when: never # Avoid running the pipeline twice (push + merge request)
- if: $CI_COMMIT_BRANCH || $CI_COMMIT_TAG
# You can also set recurring execution of the pipeline, see:
# https://docs.gitlab.com/ee/ci/pipelines/schedules.html
cache:
key: pip-pipx-pre-commit-$CI_JOB_IMAGE
paths:
- .cache/pip
- .cache/pipx
- .cache/pre-commit
default:
before_script:
- python --version # useful for debugging
# Setup git (used for setuptools-scm)
- git config --global user.email "[email protected]"
- git config --global user.name "Your Name"
# Install dependencies for the testing environment
- pip install -U pip tox pipx
check:
stage: prepare
image: "python:3.12"
script:
- pipx run pre-commit run --all-files --show-diff-on-failure
build:
stage: prepare
image: "python:3.12"
script:
- tox -e clean,build
variables:
GIT_DEPTH: "0" # deep-clone
artifacts:
expire_in: 1 day
paths: [dist]
.test_script: &test_script
dependencies: [build]
variables:
COVERALLS_PARALLEL: "true"
COVERALLS_FLAG_NAME: $CI_JOB_NAME
script:
- tox --installpkg dist/*.whl -- -rFEx --durations 10 --color yes
- pipx run coverage lcov -o coverage.lcov
- pipx run 'coveralls<4' --submit coverage.lcov
# ^-- https://github.com/TheKevJames/coveralls-python/issues/434
py38:
stage: test
image: "python:3.8"
<<: *test_script
py39:
stage: test
image: "python:3.9"
<<: *test_script
py310:
stage: test
image: "python:3.10"
<<: *test_script
py311:
stage: test
image: "python:3.11"
<<: *test_script
py312:
stage: test
image: "python:3.12"
<<: *test_script
mamba:
stage: test
image: "condaforge/mambaforge"
before_script:
- mamba install -y pip pipx 'tox!=4.0.*,!=4.1.*'
<<: *test_script
upload-coverage:
stage: finalize
image: "python:3.12"
script:
- pipx run 'coveralls<4' --finish
# ^-- https://github.com/TheKevJames/coveralls-python/issues/434
publish:
stage: release
dependencies: [build]
image: "python:3.12"
rules: [if: $CI_COMMIT_TAG]
variables:
# See: https://pypi.org/help/#apitoken
# Needs a PYPI_TOKEN protected variable to be configured for `v*` tags, see:
# https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-project
# https://docs.gitlab.com/ee/user/project/protected_tags.html
TWINE_REPOSITORY: testpypi
TWINE_USERNAME: __token__
TWINE_PASSWORD: $PYPI_TOKEN
script:
- tox -e publish