2121 - name : Run Tox Check
2222 run : tox -e check
2323
24- build :
24+ data-cache :
2525 needs : check
2626 runs-on : ubuntu-latest
27+ outputs :
28+ cache_hash : ${{ steps.compute-cache-hash.outputs.cache_hash }}
29+ steps :
30+ - uses : actions/checkout@v4
31+ - name : Setup Python
32+ uses : actions/setup-python@v5
33+ with :
34+ python-version : ' 3.9'
35+ - name : Install Dependencies
36+ run : |
37+ python -m pip install --upgrade pip
38+ pip install -e ".[dev]"
39+ - name : Restore Cache
40+ uses : actions/cache@v4
41+ with :
42+ key : cached-data-${{ hashFiles('**/registry.py', '**/*workflow.yml') }}
43+ restore-keys : |
44+ cached-data-
45+ path : .github_cache/ASPIRE-data
46+ enableCrossOsArchive : true
47+ - name : Create Cache Directory
48+ run : |
49+ # Create cache and config directories
50+ mkdir -p .github_cache/ASPIRE-data
51+ chmod -R 777 .github_cache/ASPIRE-data
52+ echo "cache:" > config.yaml
53+ echo " cache_dir: .github_cache/ASPIRE-data" >> config.yaml
54+ echo "Logging config.yaml for verification:"
55+ cat config.yaml
56+ - name : Download Cache Files
57+ run : |
58+ export ASPIREDIR=.
59+ python -c "
60+ from aspire.downloader import emdb_2660, simulated_channelspin
61+ emdb_2660()
62+ simulated_channelspin()
63+ "
64+ - name : Compute Cache Directory Hash
65+ id : compute-cache-hash
66+ run : |
67+ echo "Computing hash for .github_cache/ASPIRE-data..."
68+ # Compute a hash on the sorted file listing.
69+ cache_hash=$(ls -1 .github_cache/ASPIRE-data/** | md5sum)
70+ echo "Computed cache hash: $cache_hash"
71+ # Expose the computed hash to subsequent steps/jobs.
72+ echo "cache_hash=${cache_hash}" >> $GITHUB_OUTPUT
73+ - name : Verify Cache Directory Before Saving
74+ run : |
75+ ls -lhR .github_cache/ASPIRE-data
76+ [ -f config.yaml ]
77+ - name : Save Cache
78+ uses : actions/cache@v4
79+ with :
80+ key : cached-data-${{ hashFiles('**/registry.py', '**/*workflow.yml') }}
81+ path : .github_cache/ASPIRE-data
82+ enableCrossOsArchive : true
83+
84+ build :
85+ needs : [check, data-cache]
86+ runs-on : ubuntu-latest
2787 # Run on every code push, but only on review ready PRs
2888 if : ${{ github.event_name == 'push' || github.event.pull_request.draft == false }}
2989 strategy :
3999 - python-version : ' 3.9'
40100 pyenv : pip,docs
41101
42-
43102 steps :
44103 - uses : actions/checkout@v4
45104 - name : Set up Python ${{ matrix.python-version }} ${{ matrix.pyenv }}
@@ -51,15 +110,44 @@ jobs:
51110 pip install tox tox-gh-actions
52111 # Optional packages
53112 pip install pyfftw # `test_fft` runs for pyfftw when installed
113+ - name : Restore Cache
114+ uses : actions/cache@v4
115+ with :
116+ key : cached-data-${{ hashFiles('**/registry.py', '**/*workflow.yml') }}
117+ restore-keys : |
118+ cached-data-
119+ path : .github_cache/ASPIRE-data
120+ enableCrossOsArchive : true
121+ - name : Set Cache Directory
122+ run : |
123+ echo "cache:" > config.yaml
124+ echo " cache_dir: .github_cache/ASPIRE-data" >> config.yaml
125+ - name : Verify Restored Cache Directory
126+ run : |
127+ ls -lhR .github_cache/ASPIRE-data
128+ [ -f config.yaml ]
54129 - name : Test with tox
55- run : tox --skip-missing-interpreters false -e py${{ matrix.python-version }}-${{ matrix.pyenv }}
130+ run : |
131+ tox --override testenv.set_env=ASPIREDIR=${{ github.workspace }} \
132+ --skip-missing-interpreters false \
133+ -e py${{ matrix.python-version }}-${{ matrix.pyenv }}
134+ - name : Validate Cache Directory Hash
135+ run : |
136+ echo "Computing hash for .github_cache/ASPIRE-data..."
137+ new_hash=$(ls -1 .github_cache/ASPIRE-data/** | md5sum)
138+ echo "Hash from data-cache job: ${{ needs.data-cache.outputs.cache_hash }}"
139+ echo "Computed hash now: $new_hash"
140+ if [ "${{ needs.data-cache.outputs.cache_hash }}" != "$new_hash" ]; then
141+ echo "Error: Cache directory hash has changed!"
142+ exit 1
143+ fi
56144 - name : Upload Coverage to CodeCov
57145 uses : codecov/codecov-action@v4
58146 with :
59147 token : ${{ secrets.CODECOV_TOKEN }}
60148
61149 conda-build :
62- needs : check
150+ needs : [ check, data-cache]
63151 runs-on : ${{ matrix.os }}
64152 # Only run on review ready pull_requests
65153 if : ${{ github.event_name == 'pull_request' && github.event.pull_request.draft == false }}
@@ -97,8 +185,21 @@ jobs:
97185 pip install -e ".[dev]"
98186 pip freeze
99187 python -c "import numpy; numpy.show_config()"
188+ - name : Restore Cache
189+ uses : actions/cache@v4
190+ with :
191+ key : cached-data-${{ hashFiles('**/registry.py', '**/*workflow.yml') }}
192+ restore-keys : |
193+ cached-data-
194+ path : .github_cache/ASPIRE-data
195+ enableCrossOsArchive : true
196+ - name : Set Cache Directory
197+ run : |
198+ echo "cache:" > config.yaml
199+ echo " cache_dir: .github_cache/ASPIRE-data" >> config.yaml
100200 - name : Execute Pytest Conda ${{ matrix.os }} Python ${{ matrix.python-version }}
101201 run : |
202+ export ASPIREDIR=.
102203 export OMP_NUM_THREADS=2
103204 # -n runs test in parallel using pytest-xdist
104205 pytest -n2 --durations=50 -s
@@ -149,15 +250,16 @@ jobs:
149250 echo "Stash the WORK_DIR to GitHub env so we can clean it up later."
150251 echo "WORK_DIR=${WORK_DIR}" >> $GITHUB_ENV
151252 echo -e "common:" >> ${WORK_DIR}/config.yaml
152- echo -e " cache_dir: ${CI_CACHE_DIR}" >> ${WORK_DIR}/config.yaml
153253 echo -e " numeric: cupy" >> ${WORK_DIR}/config.yaml
154254 echo -e " fft: cupy\n" >> ${WORK_DIR}/config.yaml
255+ echo -e "cache:" >> ${WORK_DIR}/config.yaml
256+ echo -e " cache_dir: ${CI_CACHE_DIR}" >> ${WORK_DIR}/config.yaml
155257 echo "Log the config: ${WORK_DIR}/config.yaml"
156258 cat ${WORK_DIR}/config.yaml
157259 - name : Cache Data
158260 run : |
159261 ASPIREDIR=${{ env.WORK_DIR }} python -c \
160- "import aspire; print(aspire.config['common ']['cache_dir']); import aspire.downloader; aspire.downloader.emdb_2660()"
262+ "import aspire; print(aspire.config['cache ']['cache_dir']); import aspire.downloader; aspire.downloader.emdb_2660()"
161263 - name : Run
162264 run : |
163265 ASPIREDIR=${{ env.WORK_DIR }} PYTHONWARNINGS=error python -m pytest --durations=50 --cov=aspire --cov-report=xml
@@ -168,30 +270,6 @@ jobs:
168270 - name : Cleanup
169271 run : rm -rf ${{ env.WORK_DIR }}
170272
171- # Create cache and download data for Github Actions CI.
172- data-cache :
173- needs : check
174- runs-on : ubuntu-latest
175- steps :
176- - uses : actions/checkout@v4
177- - name : Setup Python
178- uses : actions/setup-python@v5
179- with :
180- python-version : ' 3.9'
181- - name : Install Dependencies
182- run : |
183- python -m pip install --upgrade pip
184- pip install -e ".[dev]"
185- - name : Create Cache
186- uses : actions/cache@v4
187- with :
188- path : ~/.cache/ASPIRE-data
189- key : ${{ runner.os }}-cached-data
190- - name : Download EMDB 2660
191- run : |
192- python -c \
193- "from aspire.downloader import emdb_2660; emdb_2660()"
194-
195273 # Build branch's docs and gallery.
196274 docs :
197275 needs : [check, data-cache]
@@ -209,10 +287,18 @@ jobs:
209287 - name : Restore Cache
210288 uses : actions/cache@v4
211289 with :
212- path : ~/.cache/ASPIRE-data
213- key : ${{ runner.os }}-cached-data
290+ key : cached-data-${{ hashFiles('**/registry.py', '**/*workflow.yml') }}
291+ restore-keys : |
292+ cached-data-
293+ path : .github_cache/ASPIRE-data
294+ enableCrossOsArchive : true
295+ - name : Set Cache Directory
296+ run : |
297+ echo "cache:" > config.yaml
298+ echo " cache_dir: .github_cache/ASPIRE-data" >> config.yaml
214299 - name : Build Sphinx docs
215300 run : |
301+ export ASPIREDIR=${{ github.workspace }}
216302 make distclean
217303 sphinx-apidoc -f -o ./source ../src -H Modules
218304 make html
@@ -223,9 +309,19 @@ jobs:
223309 name : sphinx-docs
224310 path : docs/build
225311 retention-days : 7
312+ - name : Validate Cache Directory Hash
313+ run : |
314+ echo "Computing hash for .github_cache/ASPIRE-data..."
315+ new_hash=$(ls -1 .github_cache/ASPIRE-data/** | md5sum)
316+ echo "Hash from data-cache job: ${{ needs.data-cache.outputs.cache_hash }}"
317+ echo "Computed hash now: $new_hash"
318+ if [ "${{ needs.data-cache.outputs.cache_hash }}" != "$new_hash" ]; then
319+ echo "Error: Cache directory hash has changed!"
320+ exit 1
321+ fi
226322
227323 osx_arm :
228- needs : check
324+ needs : [ check, data-cache]
229325 runs-on : macos-14
230326 # Run on every code push, but only on review ready PRs
231327 if : ${{ github.event_name == 'push' || github.event.pull_request.draft == false }}
@@ -239,5 +335,23 @@ jobs:
239335 python --version
240336 pip install -e ".[dev]" # install aspire
241337 pip freeze
338+ - name : Restore Cache
339+ uses : actions/cache@v4
340+ with :
341+ key : cached-data-${{ hashFiles('**/registry.py', '**/*workflow.yml') }}
342+ restore-keys : |
343+ cached-data-
344+ path : .github_cache/ASPIRE-data
345+ enableCrossOsArchive : true
346+ - name : Set Cache Directory
347+ run : |
348+ echo "cache:" > config.yaml
349+ echo " cache_dir: .github_cache/ASPIRE-data" >> config.yaml
350+ - name : Verify Restored Cache Directory
351+ run : |
352+ ls -lhR .github_cache/ASPIRE-data
353+ [ -f config.yaml ]
242354 - name : Test
243- run : python -m pytest -n3 --durations=50
355+ run : |
356+ export ASPIREDIR=.
357+ python -m pytest -n3 --durations=50
0 commit comments