-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
128 lines (114 loc) · 3.76 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
### Overall configuration
# Define conditions under which pipelines may be run,
# and create custom variables for jobs to re-use.
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
IS_MERGE_REQ: "true"
BRANCH_NAME: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- if: ($CI_PIPELINE_SOURCE == "push") &&
(($CI_COMMIT_BRANCH == "develop") ||
($CI_COMMIT_BRANCH =~ "/^r\d\.\d+/"))
variables:
IS_CORE_PUSH: "true"
BRANCH_NAME: $CI_COMMIT_BRANCH
# Pipeline stages: clean-up cached files, then run tests.
stages:
- clean
- test
# Use environment variables to;
# - keep pip cache files between runs (on the Docker executor)
# - keep tox cache files, but make them branch-specific
# - keep the small venv where pip and tox are installed
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.pip"
TOX_CACHE_DIR: "$CI_PROJECT_DIR/.tox"
GIT_CLEAN_FLAGS: -ffdx -e .pip -e .tox -e venv
# Shared configuration elements between all jobs.
default:
image: python:3.8
tags:
- magnet
- gpu
### Clean stage
# Automatic job to remove the tox cache for a merged branch.
clean-tox-cache-merged-branch:
stage: clean
script:
- MERGED_BRANCH=$(echo $CI_COMMIT_TITLE | grep -P "'.*?'(?= into)" -o)
- echo "Removing tox venv for merged branch $MERGED_BRANCH"
- rm -rf $TOX_CACHE_DIR/${MERGED_BRANCH:1:-1}
rules:
- if: $IS_CORE_PUSH && ($CI_COMMIT_TITLE =~ /Merge branch '.*?' into '.*?'/)
# Manual job to remove the tox cache for the current branch.
# Also called when a merge commit is detected on a main branch.
clean-tox-cache-current-branch:
stage: clean
variables:
TOX_WORKDIR: $TOX_CACHE_DIR/$BRANCH_NAME
script:
- echo "Removing tox venv for current branch at $TOX_WORKDIR"
- rm -rf $TOX_WORKDIR
rules:
- if: $IS_CORE_PUSH && ($CI_COMMIT_TITLE =~ /Merge branch '.*?' into '.*?'/)
when: always
- when: manual
allow_failure: true
# Manual job to remove the tox cache for the all branches.
clean-tox-cache-full:
stage: clean
script:
- echo "Removing the entire tox cache at $TOX_CACHE_DIR"
- rm -rf $TOX_CACHE_DIR
when: manual
allow_failure: true
### Test stage
# Shared configuration elements between test jobs.
.test_cfg:
stage: test
# Set up a virtual environment, with latest pip and tox installed.
before_script:
- python -m venv venv
- source venv/bin/activate
- pip install -U pip
- pip install -U tox
# Configure coverage export and collection.
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
# Define the preserved-across-jobs, branch-dependent tox workdir.
variables:
TOX_WORKDIR: $TOX_CACHE_DIR/$BRANCH_NAME
# Basic test suite: skip GPU use and a few extra integration tests scenarios.
# This job is called when commits are pushed to a non-draft MR branch.
# It may also be called manually on commits to draft MR branches.
test-minimal:
extends:
.test_cfg
script:
- tox -e py38-ci --workdir=$TOX_WORKDIR -- --cpu-only
rules:
- if: $IS_MERGE_REQ && ($CI_MERGE_REQUEST_TITLE !~ /^Draft:.*/)
- if: $IS_MERGE_REQ && ($CI_MERGE_REQUEST_TITLE =~ /^Draft:.*/)
when: manual
allow_failure: true
# Exhaustive test suite: lint the code, run all tests, use GPU when available.
# This job is called when commits are pushed to a main branch.
# It may also be called manually on commits to MR branches.
test-maximal:
extends:
.test_cfg
script:
- tox -e py38-ci --workdir=$TOX_WORKDIR -- --fulltest
rules:
- if: $IS_CORE_PUSH
- if: $IS_MERGE_REQ
when: manual
allow_failure: true # do not block the base "test" pipeline
tags:
- gpu
- magnet