forked from ANTsX/ANTsPy
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (67 loc) · 2.66 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
name: ci-pytest
on: pull_request
env:
# Changing either of these two things will invalidate the cache and cause a full re-install
# of ANTsPy and its dependencies
# Update this hash whenever there is a change that affects ANTsPy libraries or dependencies
# Updates or changes to the runner OS or arch will also invalidate the cache
antspy_ref_hash: 'ff7413a5e7685b94ad7fc9a9b2553656f3bd005e'
python_version: '3.9' # Python version to use for testing - update when needed
jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ env.python_version }}
activate-environment: antspy-env
- name: Load conda environment from cache if available
id: cache-env
uses: actions/cache@v4
with:
path: ~/conda-env.tar.gz
key: ${{ runner.os }}-${{ runner.arch }}-conda-${{ env.python_version }}-${{ env.antspy_ref_hash }}
- name: Unpack cached environment
if: steps.cache-env.outputs.cache-hit == 'true'
run: |
tar -xzf ~/conda-env.tar.gz -C ${CONDA}/envs/antspy-env
- name: Checkout ANTsPy at specific commit
if: steps.cache-env.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: ANTsX/ANTsPy
ref: ${{ env.antspy_ref_hash }}
token: ${{ secrets.GITHUB_TOKEN }}
path: antspy-temp
- name: Install dependencies and ANTsPy from commit
if: steps.cache-env.outputs.cache-hit != 'true'
run: |
source $CONDA/etc/profile.d/conda.sh
conda install -c conda-forge conda-pack
conda create -n antspy-env python=${{ env.python_version }} -y
conda activate antspy-env
pip install ./antspy-temp
# Pack the environment
conda deactivate
conda pack -n antspy-env -o ~/conda-env.tar.gz
- name: Cache Conda environment
if: steps.cache-env.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ~/conda-env.tar.gz
key: ${{ runner.os }}-${{ runner.arch }}-conda-${{ env.python_version }}-${{ env.antspy_ref_hash }}
- uses: actions/checkout@v4 # Checkout PR code to 'antspy-pr'
with:
path: antspy-pr
- name: Replace installed ANTsPy with PR code
run: |
ANTS_SITE_PACKAGES=$(python -c "import os, ants; print(os.path.dirname(ants.__file__))")
rm -rf $ANTS_SITE_PACKAGES/ants
cp -r antspy-pr/ants $ANTS_SITE_PACKAGES/ants
- name: Run tests
run: |
source $CONDA/etc/profile.d/conda.sh
conda activate antspy-env
bash antspy-pr/tests/run_tests.sh