Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit adb4836

Browse files
author
William McLendon
committed
Bring CI in line with CPE's CI
1 parent 8d257a1 commit adb4836

File tree

1 file changed

+97
-36
lines changed

1 file changed

+97
-36
lines changed

.gitlab-ci.yml

Lines changed: 97 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
#
2+
#
3+
# Useful Links:
4+
# - CI/CD Lint : https://gitlab-ex.sandia.gov/trilinos-devops-consolidation/code/SetProgramOptions/-/ci/lint
5+
# - Gitlab YAML: https://docs.gitlab.com/ee/ci/yaml/
6+
7+
8+
# Set up a global cache to pass info across stages
9+
cache: &global_cache
10+
key: "${CI_COMMIT_REF_SLUG}_${CI_COMMIT_SHORT_SHA}"
11+
paths:
12+
- tests/htmlcov/
13+
- venv-clean-python/
14+
policy: pull-push
15+
16+
17+
# Set up pipeline stages
118
stages:
219
- prepare
320
- test
@@ -8,50 +25,75 @@ stages:
825
- cleanup
926

1027

28+
# Script to run before every job
1129
before_script:
12-
# display centos version
13-
- cat /etc/issue
14-
15-
30+
- |-
31+
export LSB_RELEASE=$(which lsb_release)
32+
if [ -x ${LSB_RELEASE} ]; then
33+
${LSB_RELEASE} -a
34+
fi
35+
- |-
36+
if [ -d "venv-clean-python" ]; then
37+
source venv-clean-python/bin/activate
38+
else
39+
echo "Virtual Environment 'venv-clean-python' was not found"
40+
exit 1
41+
fi
42+
echo "-----"
43+
echo "VIRTUAL_ENV = ${VIRTUAL_ENV:?}"
44+
echo "-----"
45+
46+
47+
# Script to run after every job
48+
after_script:
49+
- |-
50+
if [ ! -z ${VIRTUAL_ENV} ]; then
51+
deactivate
52+
fi
53+
54+
55+
# Create venv, install requirements, save cache
1656
install_requirements:
1757
stage: prepare
58+
timeout: 10m
59+
#artifacts:
60+
# untracked: true
61+
before_script:
62+
- python3 -m venv venv-clean-python
63+
cache:
64+
<<: *global_cache
65+
when: on_success
1866
script:
67+
#- echo "CI_COMMIT_REF_SLUG = ${CI_COMMIT_REF_SLUG}_${CI_COMMIT_SHORT_SHA}"
68+
- source venv-clean-python/bin/activate
69+
1970
# Remove setprogramoptions if it's been installed
2071
- python3 -m pip uninstall -y setprogramoptions
2172

2273
# Pull required packages
23-
- python3 -m pip install -r requirements.txt -r requirements-test.txt -r doc/requirements.txt
74+
- python3 -m pip install wheel -r requirements.txt -r requirements-test.txt -r doc/requirements.txt
2475

25-
# Get ConfigParserEnhanced
26-
# See https://pip.pypa.io/en/stable/reference/pip_install/#git : useful data on how to format this link
27-
# https://stackoverflow.com/a/35998253/2059999 : also useful for some info on how to write the target
28-
#- python3 -m pip uninstall -y configparserenhanced
29-
#- python3 -m pip install --user git+https://gitlab+deploy-token-CI:${CI_GROUP_READ_TOKEN}@gitlab-ex.sandia.gov/trilinos-devops-consolidation/code/ConfigParserEnhanced.git@master#egg=configparserenhanced
30-
# Methods that work on the command line but not in CI.
31-
# - python3 -m pip install --user -r requirements.txt
3276

33-
#after_script:
34-
# - python3 -m pip uninstall -y setprogramoptions
35-
# - python3 -m pip uninstall -y -r requirements.txt
3677

37-
38-
unit_tests:
78+
# Execute unit tests
79+
pytest:
3980
stage: test
40-
timeout: 10m
81+
timeout: 5m
4182
script:
4283
- python3 -m pytest --cov=setprogramoptions --cov-report=term --cov-report=html --cov-config=.coveragerc
4384
coverage: '/TOTAL\s*\d+\s+\d+\s+\d+\s+\d+\s+(\d+%)/'
4485
cache:
45-
key: coverage-cache
46-
paths:
47-
- tests/htmlcov/
86+
<<: *global_cache
4887

4988

89+
# Test distribution building
5090
build_dist:
5191
stage: deploy
52-
needs: [unit_tests]
92+
timeout: 5m
93+
cache:
94+
<<: *global_cache
95+
policy: pull
5396
script:
54-
- python3 -m pip install wheel
5597
- python3 -m pip wheel --no-deps -w dist .
5698
artifacts:
5799
name: "setprogramoptions-dist"
@@ -60,66 +102,85 @@ build_dist:
60102
expire_in: 6 weeks
61103

62104

105+
# Test installation of package
63106
install:
64107
stage: deploy
108+
timeout: 5m
109+
cache:
110+
<<: *global_cache
65111
script:
66112
- python3 -m pip install .
67113

68114

115+
# Test example(s)
69116
examples:
70117
stage: examples
71-
timeout: 10m
118+
timeout: 5m
119+
cache:
120+
<<: *global_cache
121+
policy: pull
72122
script:
73123
- cd examples
74124
- python3 ./example-01.py
75125
- python3 ./example-02.py
76126
- python3 ./example-03.py
77127

78128

129+
# Generate documentation
79130
sphinx-documentation:
80131
stage: documentation
81-
timeout: 20m
132+
timeout: 5m
133+
cache:
134+
<<: *global_cache
82135
script:
83136
- cd doc/
84-
- python3 -m pip install -r requirements.txt
85137
- bash make_html_docs.sh
86138

87139

140+
# Publish coverage data (if on main branch)
88141
publish coverage:
89142
stage: publish
90-
needs: [unit_tests]
91-
timeout: 20m
143+
timeout: 5m
92144
rules:
93145
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
94146
cache:
95-
key: coverage-cache
96-
paths:
97-
- tests/htmlcov/
147+
<<: *global_cache
148+
policy: pull
98149
script:
99-
#- python3 -m pytest --cov=setprogramoptions --cov-report=term --cov-report=html --cov-config=.coveragerc
100150
- rm -rf /home/josbrau/html_files/SetProgramOptions/coverage
101151
- mkdir -p /home/josbrau/html_files/SetProgramOptions/coverage
102152
- mv tests/htmlcov/* /home/josbrau/html_files/SetProgramOptions/coverage/
103153

154+
155+
# Publish documentation (if on main branch)
104156
publish docs:
105157
stage: publish
106-
timeout: 20m
158+
timeout: 5m
107159
rules:
108160
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
161+
cache:
162+
<<: *global_cache
163+
policy: pull
109164
script:
110165
- cd doc/
111-
- python3 -m pip install -r requirements.txt
112166
- bash make_html_docs.sh
113167
- rm -rf /home/josbrau/html_files/SetProgramOptions/doc
114168
- mkdir -p /home/josbrau/html_files/SetProgramOptions/doc
115169
- mv html/* /home/josbrau/html_files/SetProgramOptions/doc/
116170

117171

172+
# Test uninstall from venv works
118173
uninstall:
119174
stage: cleanup
120-
timeout: 20m
175+
timeout: 5m
176+
cache:
177+
<<: *global_cache
121178
script:
122179
- python3 -m pip uninstall -y setprogramoptions
123-
- python3 -m pip uninstall -y -r requirements.txt
180+
181+
# - python3 -m pip uninstall -y -r requirements.txt
182+
# >>> In a virtual environment, this won't work if there are no entries in
183+
# >>> the requirements.txt file.
184+
124185

125186

0 commit comments

Comments
 (0)