-
Notifications
You must be signed in to change notification settings - Fork 7
285 lines (251 loc) · 9.7 KB
/
python-conda-test.yml
File metadata and controls
285 lines (251 loc) · 9.7 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
name: Conda Build
on:
workflow_call:
inputs:
package-name:
description: "The Python-importable package name to be tested"
required: true
type: string
python-version:
description: "The Python version to build and test with"
required: true
type: string
experimental:
description: "Mark this version as experimental and not required to pass"
required: false
default: false
type: boolean
deploy-on-success:
description: "Deploy to pcds-tag/pcds-dev on success and when appropriate"
required: false
default: false
type: boolean
recipe-folder:
default: "conda-recipe/"
description: "The conda recipe folder"
required: false
type: string
testing-extras:
default: ""
description: "Extra packages to be installed for testing"
required: false
type: string
ci-extras:
default: "pip"
description: "CI-specific packages to be installed"
required: false
type: string
use-setuptools-scm:
description: "Install and configure setuptools-scm prior to conda-build"
required: false
default: false
type: boolean
requirements-file:
default: ""
description: "Development requirements filename"
required: false
type: string
system-packages:
default: ""
description: "CI-specific system packages required for installation"
required: false
type: string
outputs: {}
env:
MPLBACKEND: "agg"
QT_QPA_PLATFORM: "offscreen"
MAMBA_ROOT_PREFIX: "~/micromamba"
CONDARC_SOURCE: |
notify_outdated_conda: false
pkgs_dirs:
- ~/conda_pkgs_dir
channels:
- conda-forge
- pcds-tag
add_pip_as_python_dependency: true
auto_activate_base: true
auto_update_conda: false
channel_priority: strict
always_yes: true
changeps1: false
jobs:
build-and-test:
name: "Python ${{ inputs.python-version }}: conda"
runs-on: ubuntu-latest
continue-on-error: ${{ inputs.experimental }}
defaults:
run:
# The following allows for each run step to utilize ~/.bash_profile
# for setting up the per-step initial state.
# --login: a login shell. Source ~/.bash_profile
# -e: exit on first error
# -o pipefail: piped processes are important; fail if they fail
shell: bash --login -eo pipefail {0}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
token: ${{ secrets.CHECKOUT_TOKEN || github.token }}
- name: Check version to be built
run: |
# NOTE: If you run CI on your own fork, you may not have the right version
# number for the package. Synchronize your tags with the upstream,
# otherwise cross-dependencies may result in confusing build failure.
(echo "Package version: $(git describe --tags)" | tee "$GITHUB_STEP_SUMMARY") || \
echo "::warning::Git tags not found in repository. Build may fail!"
- name: Check environment variables for issues
run: |
echo "* Conda package to be built: ${{ inputs.package-name }}"
echo "* Conda 'extras' for CI testing: ${{ inputs.testing-extras }}"
echo "* General conda packages required for CI testing: ${{ inputs.ci-extras }}"
echo "* Conda recipe folder: ${{ inputs.recipe-folder }}"
echo "* Conda requirements file for development: ${{ inputs.requirements-file }}"
echo "* Micromamba environment root: ${MAMBA_ROOT_PREFIX}"
- name: Install required system packages
if: inputs.system-packages != ''
run: |
sudo apt-get update
sudo apt-get -y install ${{ inputs.system-packages }}
- name: Set up micromamba and environment
run: |
cd "$HOME"
mkdir logs
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj "bin/micromamba"
mkdir micromamba
echo "Micromamba version: $(bin/micromamba --version)" | tee "$GITHUB_STEP_SUMMARY"
bin/micromamba shell hook --shell=bash >> ~/.bash_profile
echo "micromamba activate" >> ~/.bash_profile
- name: Configure conda for building
run: |
echo "${CONDARC_SOURCE}" > ~/.condarc
echo "Contents of ~/.condarc:"
echo "---------------------------"
cat ~/.condarc
echo "---------------------------"
- name: Install boa for mambabuild
run: |
micromamba install boa "python=${{ inputs.python-version }}"
micromamba info
- name: Check condarc
run: |
cat ~/.condarc
- name: Check the conda recipe
run: |
echo "Conda Recipe Folder':' ${{ inputs.recipe-folder }}"
echo "The recipe to be built is as follows:"
cat "${{ inputs.recipe-folder }}/meta.yaml"
- name: Configure setuptools-scm
if: ${{ inputs.use-setuptools-scm }}
run: |
# In v8.0.0, write_to was removed as a config option with no deprecation period
# write_to makes the _version.py file get written when you check the version
# we used it here to write out the file via "python -m setuptools_scm"
# it was replaced with version_file, which only writes during the build
micromamba install "setuptools-scm<8.0.0"
python -m setuptools_scm
- name: Build the conda package and create the test environment
run: |
conda mambabuild "${{ inputs.recipe-folder }}" \
--quiet \
--output-folder "$HOME/conda-bld" \
--no-anaconda-upload \
--python "${{ inputs.python-version }}" \
--extra-deps "python==${{ inputs.python-version }}" \
--keep-old-work \
2>&1 | tee $HOME/logs/mambabuild.txt
- name: Upload the built package as an artifact
uses: actions/upload-artifact@v4
with:
name: Python ${{ inputs.python-version }} - conda - package
path: ~/conda-bld
- name: Use the pre-built test environment
run: |
TEST_ENV_PATH=$(ls -d ${MAMBA_ROOT_PREFIX/#\~/$HOME}/conda-bld/*/*_test_env*)
echo "The test path should be: ${TEST_ENV_PATH}"
if [ ! -d "${TEST_ENV_PATH}" ]; then
echo "Something went wrong finding the test environment path. :("
find ${MAMBA_ROOT_PREFIX/#\~/$HOME}/conda-bld -type d
exit 1
fi
echo "micromamba activate ${TEST_ENV_PATH}" >> ~/.bash_profile
- name: Check the conda packages in the test env
run: |
conda list
- name: Install additional test dependencies
run: |
# 1. escape '<' so the user doesn't have to
# 2. escape '>' so the user doesn't have to
input_requirements=$(
echo "${{ inputs.ci-extras }} ${{ inputs.testing-extras }}" |
sed -e "s/</\</g" |
sed -e "s/>/\>/g"
)
declare -a test_requirements=()
for req in $input_requirements; do
test_requirements+=( "$req" )
done
if [[ ${#test_requirements[@]} -gt 0 ]]; then
echo "CI extras: ${{ inputs.ci-extras }}"
echo "Testing extras: ${{ inputs.testing-extras }}"
echo "In summary: ${test_requirements[@]}"
set -x
micromamba install "${test_requirements[@]}"
fi
if [ -n "${{ inputs.requirements-file }}" ]; then
echo "Installing from requirements file: ${{ inputs.requirements-file }}"
set -x
micromamba install --file="${{ inputs.requirements-file }}"
fi
- name: Run tests
run: |
pytest -v \
--log-file="$HOME/logs/debug_log.txt" \
--log-format='%(asctime)s.%(msecs)03d %(module)-15s %(levelname)-8s %(threadName)-10s %(message)s' \
--log-file-date-format='%H:%M:%S' \
--log-level=DEBUG \
2>&1 | tee "$HOME/logs/pytest_log.txt"
- name: pcds-dev deployment
if: inputs.deploy-on-success && github.event_name == 'push' && github.ref == 'refs/heads/master'
env:
ANACONDA_API_TOKEN: ${{ secrets.CONDA_UPLOAD_TOKEN_DEV }}
run: |
micromamba create --name upload python=3.11 anaconda-client
micromamba activate upload
anaconda upload "${HOME}"/conda-bld/noarch/*.tar.bz2
- name: pcds-tag deployment
if: inputs.deploy-on-success && github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
env:
ANACONDA_API_TOKEN: ${{ secrets.CONDA_UPLOAD_TOKEN_TAG }}
run: |
micromamba create --name upload python=3.11 anaconda-client
micromamba activate upload
anaconda upload "${HOME}"/conda-bld/noarch/*.tar.bz2
- name: After failure
if: ${{ failure() }}
run: |
# On failure:
# * Include the conda environment details
# * Include the pytest log in the step summary (but not in the step output as it's available in the previous step)
# * Include the debug log in the step output (but not the step summary as it's too verbose)
(
echo "### Conda environment"
echo "<details>"
echo ""
echo '```'
conda list | grep -v -e "^#"
echo '```'
echo "</details>"
echo ""
echo "### Pytest log"
echo '```python'
cat "$HOME/logs/pytest_log.txt" || echo "# Pytest log not found?"
echo '```'
) | tee -a "$GITHUB_STEP_SUMMARY"
echo "## Debug log"
cat "$HOME/logs/debug_log.txt" || echo "Debug logfile not found?"
- name: Upload log file artifacts
uses: actions/upload-artifact@v4
with:
name: Python ${{ inputs.python-version }} - conda - testing log
path: "~/logs"