Skip to content

Commit 4ce4b72

Browse files
committed
Add download RosettaSciIO test data reusable workflow
1 parent b44c371 commit 4ce4b72

2 files changed

Lines changed: 92 additions & 24 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Download eXSpy GOS
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
VERSION:
7+
description: The version of RosettaSciIO test data to download. It can be "release" or "main". Default is "release".
8+
default: "release"
9+
type: string
10+
outputs:
11+
VERSION:
12+
description: The resolved version of RosettaSciIO test data (e.g. "v0.13").
13+
value: ${{ jobs.download_cache_RosettaSciIO_tests_data.outputs.VERSION }}
14+
15+
jobs:
16+
download_cache_RosettaSciIO_tests_data:
17+
name: Download & cache RosettaSciIO test data
18+
runs-on: ubuntu-latest
19+
outputs:
20+
VERSION: ${{ steps.resolve_version.outputs.VERSION }}
21+
env:
22+
VERSION: ${{ inputs.VERSION }}
23+
steps:
24+
25+
- name: Get latest RosettaSciIO version
26+
id: resolve_version
27+
if: ${{ env.VERSION == 'release' }}
28+
run: |
29+
LATEST_VERSION=$(curl -s https://pypi.org/pypi/rosettasciio/json | jq -r '.info.version')
30+
echo "Latest RosettaSciIO version: $LATEST_VERSION"
31+
echo "VERSION=v$LATEST_VERSION" >> $GITHUB_ENV
32+
echo "VERSION=v$LATEST_VERSION" >> $GITHUB_OUTPUT
33+
34+
- name: Download registry.txt
35+
run: |
36+
wget https://github.com/hyperspy/rosettasciio/raw/${{ env.VERSION }}/rsciio/tests/registry.txt
37+
38+
- uses: ssciwr/pooch-cache@v1
39+
with:
40+
name: rsciio-${{ env.VERSION }}
41+
base-urls: |
42+
https://github.com/hyperspy/rosettasciio/raw/${{ env.VERSION }}/rsciio/tests/data/
43+
registry-files: |
44+
registry.txt

.github/workflows/integration_tests.yml

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ on:
6363
description: 'A label to add to the pooch cache key.'
6464
default: 'pooch'
6565
type: string
66+
RSCIIO_CACHE_POOCH_LABEL:
67+
description: |
68+
'The label to retrieve the RosettaSciIO test data cache - only used when `ROSETTASCIIO_VERSION` is "release".'
69+
'The output of the `download_rsciio_test_data.yml` reusable workflow should be passed to this input to get the correct cache.'
70+
default: ''
71+
type: string
6672
PYTEST_ARGS:
6773
description: 'Additional arguments to pass to pytest.
6874
If not provided, defaults to "--reruns 3 -n <number_of_cpus>".'
@@ -96,6 +102,7 @@ jobs:
96102
env:
97103
MPLBACKEND: agg
98104
PYTEST_ARGS: ${{ inputs.PYTEST_ARGS }}
105+
RSCIIO_CACHE_POOCH_LABEL: ${{ inputs.RSCIIO_CACHE_POOCH_LABEL }}
99106
steps:
100107
- uses: actions/checkout@v6
101108
with:
@@ -112,13 +119,6 @@ jobs:
112119
git remote add upstream https://github.com/hyperspy/${{ env.REPOSITORY_NAME }}.git
113120
git fetch upstream --tags
114121
115-
- uses: ssciwr/pooch-cache@v1
116-
if: ${{ contains(inputs.EXTENSIONS, 'exspy')}}
117-
with:
118-
# to restore the pooch cache use for eXSpy for example
119-
name: pooch
120-
fail-on-cache-miss: true
121-
122122
- uses: conda-incubator/setup-miniconda@v3
123123
with:
124124
miniforge-version: latest
@@ -346,27 +346,51 @@ jobs:
346346
restore-keys: |
347347
${{ runner.os }}-${{ inputs.CACHE_POOCH_LABEL }}-${{ env.CACHE_NUMBER }}
348348
349-
- name: Conda list
349+
- uses: ssciwr/pooch-cache@v1
350+
if: ${{ contains(inputs.EXTENSIONS, 'exspy')}}
351+
with:
352+
# to restore the pooch cache use for eXSpy for example
353+
name: pooch
354+
fail-on-cache-miss: true
355+
356+
- name: Set RSCIIO_CACHE_POOCH_LABEL environment variable
357+
if: ${{ env.REPOSITORY_NAME != 'rosettasciio' && inputs.ROSETTASCIIO_VERSION == 'dev' }}
350358
run: |
351-
conda list
359+
# overwrite the RSCIIO_CACHE_POOCH_LABEL to "main" to get the latest test data cache for the dev version of RosettaSciIO
360+
echo "RSCIIO_CACHE_POOCH_LABEL=main" >> $GITHUB_ENV
361+
362+
- uses: ssciwr/pooch-cache@v1
363+
if: ${{ env.REPOSITORY_NAME != 'rosettasciio' }}
364+
with:
365+
# to restore the RosettaSciIO test data cache
366+
name: rsciio-${{ env.RSCIIO_CACHE_POOCH_LABEL }}
367+
fail-on-cache-miss: true
352368

353-
- name: Get rosettasciio tests data location
354-
if: ${{ env.REPOSITORY_NAME != 'rosettasciio' }} # only for repositories that are not rosettasciio
369+
# Need https://github.com/hyperspy/rosettasciio/pull/482 to be released
370+
# and remove the next step
371+
# - name: Set RSCIIO_TEST_DATA_SOURCE environment variable
372+
# if: ${{ env.REPOSITORY_NAME != 'rosettasciio' }}
373+
# run: |
374+
# # Get the value `RSCIIO_TEST_DATA_SOURCE` from the pooch cache path
375+
# python -c "import pooch; print(f'RSCIIO_TEST_DATA_SOURCE={str(pooch.os_cache(\"rsciio-${{ env.RSCIIO_CACHE_POOCH_LABEL }}\"))}')" >> $GITHUB_ENV
376+
377+
- name: Copy RosettaSciIO test data from pooch cache
378+
if: ${{ env.REPOSITORY_NAME != 'rosettasciio' }}
355379
run: |
356-
python -c "from rsciio.tests import registry; print(f'ROSETTASCIIO_TEST_DATA={str(registry.TESTS_PATH / \"data\") }')" >> $GITHUB_ENV
380+
python -c "
381+
import importlib.util, os, shutil, sys
382+
from pathlib import Path
383+
import pooch
384+
src = pooch.os_cache('rsciio-${{ env.RSCIIO_CACHE_POOCH_LABEL }}')
385+
dest = Path(importlib.util.find_spec('rsciio').origin).parent / 'tests' / 'data'
386+
print(f'Copying from {src} to {dest}')
387+
shutil.copytree(str(src), str(dest), dirs_exist_ok=True)
388+
print(os.listdir(dest))
389+
"
357390
358-
- name: Cache rosettasciio data
359-
if: ${{ always() && env.REPOSITORY_NAME != 'rosettasciio' }} # only for repositories that are not rosettasciio
360-
uses: actions/cache@v5
361-
env:
362-
# Increase this value to reset cache
363-
CACHE_NUMBER: 0
364-
with:
365-
path: ${{ env.ROSETTASCIIO_TEST_DATA }}
366-
key:
367-
${{ runner.os }}-integration-rosettasciio-${{ env.CACHE_NUMBER }}
368-
restore-keys: |
369-
${{ runner.os }}-integration-rosettasciio-${{ env.CACHE_NUMBER }}
391+
- name: Conda list
392+
run: |
393+
conda list
370394
371395
- name: Run HyperSpy Test Suite
372396
if: ${{ always() }}

0 commit comments

Comments
 (0)