-
Notifications
You must be signed in to change notification settings - Fork 165
103 lines (90 loc) · 3.5 KB
/
ci-pytest.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
name: ci-pytest
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
env:
# Updates or changes to this, or the runner OS or arch will invalidate the cache
python_version: '3.10' # Python version to use for testing - update when needed
jobs:
test:
runs-on: ubuntu-20.04
# Default shell needs to be bash for conda
# https://github.com/conda-incubator/setup-miniconda?tab=readme-ov-file#important
defaults:
run:
shell: bash -el {0}
steps:
- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@030178870c779d9e5e1b4e563269f3aa69b04081 # v3.0.3, devs recommend using hash
with:
miniconda-version: "latest"
python-version: ${{ env.python_version }}
auto-update-conda: true
activate-environment: "test-env"
- name: Configure Conda to use only .tar.bz2
run: |
conda config --set use_only_tar_bz2 true
- name: Checkout code
uses: actions/checkout@v4 # Checkout PR code to 'antspy-pr'
with:
path: antspy-pr
- name: Load conda environment from cache if available
id: cache-env
uses: actions/cache@v4
with:
path: ~/conda-env.tar.bz2
key: >-
${{ runner.os }}-conda-${{ env.python_version }}-${{ hashFiles('antspy-pr/ants/environment.yml',
'antspy-pr/ants/requirements.txt', 'antspy-pr/ants/setup.py', 'antspy-pr/scripts/configure_ITK.sh',
'antspy-pr/scripts/configure_ANTsPy.sh', 'antspy-pr/ants/lib/*') }}
- name: Unpack cached environment
if: steps.cache-env.outputs.cache-hit == 'true'
run: |
mkdir -p ${CONDA}/envs/antspy-env
tar -xjf ~/conda-env.tar.bz2 -C ${CONDA}/envs/antspy-env
conda activate antspy-env
conda-unpack
- name: Install dependencies and ANTsPy from PR
if: steps.cache-env.outputs.cache-hit != 'true'
run: |
conda create -n antspy-env python=${{ env.python_version }} -y
conda activate antspy-env
conda install -c conda-forge conda-pack coverage
conda info
pip install ./antspy-pr
conda list
antspy-pr/tests/run_tests.sh -c
conda pack -n antspy-env -o ~/conda-env.tar.bz2
- name: Cache Conda environment
if: steps.cache-env.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ~/conda-env.tar.bz2
key: >-
${{ runner.os }}-conda-${{ env.python_version }}-${{ hashFiles('antspy-pr/ants/environment.yml',
'antspy-pr/ants/requirements.txt', 'antspy-pr/ants/setup.py', 'antspy-pr/scripts/configure_ITK.sh',
'antspy-pr/scripts/configure_ANTsPy.sh', 'antspy-pr/ants/lib/*') }}) }}
- name: Replace installed ANTsPy with PR code
if: steps.cache-env.outputs.cache-hit == 'true'
run: |
conda activate antspy-env
ANTS_SITE_PACKAGES="${CONDA}/envs/antspy-env/lib/python${{ env.python_version }}/site-packages/ants"
for d in contrib core learn registration segmentation utils viz; do
rm -rf $ANTS_SITE_PACKAGES/$d;
cp -r antspy-pr/ants/$d $ANTS_SITE_PACKAGES/$d;
done
find $ANTS_SITE_PACKAGES -name '__pycache__' -exec rm -rf {} +
- name: Run tests
if: steps.cache-env.outputs.cache-hit == 'true'
run: |
conda activate antspy-env
bash antspy-pr/tests/run_tests.sh -c
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
files: antspy-pr/tests/coverage.xml