Skip to content

Commit 69adbef

Browse files
seismanmichaelgrundyvonnefroehlich
authored
CI: Trigger the cache_data workflow in PRs if cache files are added/deleted/updated (#2939)
Co-authored-by: Michael Grund <[email protected]> Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent 0e8bc15 commit 69adbef

File tree

3 files changed

+96
-89
lines changed

3 files changed

+96
-89
lines changed

.github/workflows/cache_data.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
# Cache GMT remote data files and uploads as artifacts
1+
# Cache GMT remote data files and upload as artifacts
22
#
33
# This workflow downloads data files needed by PyGMT tests/documentation from
44
# the GMT data server and uploads as workflow artifacts which can be accessed
55
# by other GitHub Actions workflows.
66
#
77
# It is scheduled to run every Sunday at 12:00 (UTC). If new remote files are
8-
# needed urgently, maintainers can manually uncomment the 'pull_request:' line
9-
# below to refresh the cache.
8+
# needed urgently, maintainers can update the workflow file or
9+
# 'pygmt/helpers/caching.py' file to refresh the cache.
1010
#
1111
name: Cache data
1212

1313
on:
14-
# Uncomment the 'pull_request' line below to manually re-cache data artifacts
15-
# pull_request:
14+
pull_request:
15+
# Make any changes to the following files to refresh the cache
16+
paths:
17+
- 'pygmt/helpers/caching.py'
18+
- '.github/workflows/cache_data.yaml'
1619
# Schedule runs on 12 noon every Sunday
1720
schedule:
1821
- cron: '0 12 * * 0'
@@ -61,7 +64,7 @@ jobs:
6164
# Download remote files
6265
- name: Download remote data
6366
run: |
64-
python -c "from pygmt.helpers.testing import download_test_data; download_test_data()"
67+
python -c "from pygmt.helpers.caching import cache_data; cache_data()"
6568
6669
# Upload the downloaded files as artifacts to GitHub
6770
- name: Upload artifacts to GitHub

pygmt/helpers/caching.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""
2+
Functions for download remote data files as cache.
3+
"""
4+
from pygmt.src import which
5+
6+
7+
def cache_data():
8+
"""
9+
Download GMT remote data files used in PyGMT tests and docs as cache files.
10+
"""
11+
# List of datasets to download
12+
datasets = [
13+
# Earth relief grids
14+
"@earth_gebco_01d_g",
15+
"@earth_gebcosi_01d_g",
16+
"@earth_gebcosi_15m_p",
17+
"@earth_relief_01d_p",
18+
"@earth_relief_01d_g",
19+
"@earth_relief_30m_p",
20+
"@earth_relief_30m_g",
21+
"@earth_relief_10m_p",
22+
"@earth_relief_10m_g",
23+
"@earth_relief_05m_p",
24+
"@earth_relief_05m_g",
25+
"@earth_synbath_01d_g",
26+
# List of tiles of 03s srtm data.
27+
# Names like @N35E135.earth_relief_03s_g.nc are for internal use only.
28+
# The naming scheme may change. DO NOT USE IT IN YOUR SCRIPTS.
29+
"@N30W120.earth_relief_15s_p.nc",
30+
"@N35E135.earth_relief_03s_g.nc",
31+
"@N37W120.earth_relief_03s_g.nc",
32+
"@N00W090.earth_relief_03m_p.nc",
33+
"@N00E135.earth_relief_30s_g.nc",
34+
"@N00W010.earth_relief_15s_p.nc", # Specific grid for 15s test
35+
"@N04W010.earth_relief_03s_g.nc", # Specific grid for 03s test
36+
# Earth synbath relief grid
37+
"@S15W105.earth_synbath_30s_p.nc",
38+
# Earth seafloor age grids
39+
"@earth_age_01d_g",
40+
"@N00W030.earth_age_01m_g.nc", # Specific grid for 01m test
41+
# Earth geoid grids
42+
"@earth_geoid_01d_g",
43+
"@N00W030.earth_geoid_01m_g.nc", # Specific grid for 01m test
44+
# Earth magnetic anomaly grids
45+
"@earth_mag_01d_g",
46+
"@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test
47+
"@earth_mag4km_01d_g",
48+
"@S30W120.earth_mag4km_02m_p.nc", # Specific grid for 02m test
49+
# Earth mask grid
50+
"@earth_mask_01d_g",
51+
# Earth free-air anomaly grids
52+
"@earth_faa_01d_g",
53+
"@N00W030.earth_faa_01m_p.nc", # Specific grid for 01m test
54+
# Earth vertical gravity gradient grids
55+
"@earth_vgg_01d_g",
56+
"@N00W030.earth_vgg_01m_p.nc", # Specific grid for 01m test
57+
# Earth WDMAM grids
58+
"@earth_wdmam_01d_g",
59+
"@S90E000.earth_wdmam_03m_g.nc", # Specific grid for 03m test
60+
# Earth day/night grids
61+
"@earth_day_01d_p",
62+
# Other cache files
63+
"@capitals.gmt",
64+
"@circuit.png",
65+
"@earth_relief_20m_holes.grd",
66+
"@EGM96_to_36.txt",
67+
"@MaunaLoa_CO2.txt",
68+
"@RidgeTest.shp",
69+
"@RidgeTest.shx",
70+
"@RidgeTest.dbf",
71+
"@RidgeTest.prj",
72+
"@Table_5_11.txt",
73+
"@Table_5_11_mean.xyz",
74+
"@fractures_06.txt",
75+
"@hotspots.txt",
76+
"@ridge.txt",
77+
"@mars370d.txt",
78+
"@srtm_tiles.nc", # needed for 03s and 01s relief data
79+
"@static_earth_relief.nc",
80+
"@ternary.txt",
81+
"@test.dat.nc",
82+
"@tut_bathy.nc",
83+
"@tut_quakes.ngdc",
84+
"@tut_ship.xyz",
85+
"@usgs_quakes_22.txt",
86+
]
87+
which(fname=datasets, download="a")

pygmt/helpers/testing.py

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -142,89 +142,6 @@ def wrapper(*args, ext="png", request=None, **kwargs):
142142
return decorator
143143

144144

145-
def download_test_data():
146-
"""
147-
Convenience function to download remote data files used in PyGMT tests and docs.
148-
"""
149-
# List of datasets to download
150-
datasets = [
151-
# Earth relief grids
152-
"@earth_gebco_01d_g",
153-
"@earth_gebcosi_01d_g",
154-
"@earth_gebcosi_15m_p",
155-
"@earth_relief_01d_p",
156-
"@earth_relief_01d_g",
157-
"@earth_relief_30m_p",
158-
"@earth_relief_30m_g",
159-
"@earth_relief_10m_p",
160-
"@earth_relief_10m_g",
161-
"@earth_relief_05m_p",
162-
"@earth_relief_05m_g",
163-
"@earth_synbath_01d_g",
164-
# List of tiles of 03s srtm data.
165-
# Names like @N35E135.earth_relief_03s_g.nc is for internal use only.
166-
# The naming scheme may change. DO NOT USE IT IN YOUR SCRIPTS.
167-
"@N30W120.earth_relief_15s_p.nc",
168-
"@N35E135.earth_relief_03s_g.nc",
169-
"@N37W120.earth_relief_03s_g.nc",
170-
"@N00W090.earth_relief_03m_p.nc",
171-
"@N00E135.earth_relief_30s_g.nc",
172-
"@N00W010.earth_relief_15s_p.nc", # Specific grid for 15s test
173-
"@N04W010.earth_relief_03s_g.nc", # Specific grid for 03s test
174-
# Earth synbath relief grids
175-
"@S15W105.earth_synbath_30s_p.nc",
176-
# Earth seafloor age grids
177-
"@earth_age_01d_g",
178-
"@N00W030.earth_age_01m_g.nc", # Specific grid for 01m test
179-
# Earth geoid grids
180-
"@earth_geoid_01d_g",
181-
"@N00W030.earth_geoid_01m_g.nc", # Specific grid for 01m test
182-
# Earth magnetic anomaly grids
183-
"@earth_mag_01d_g",
184-
"@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test
185-
"@earth_mag4km_01d_g",
186-
"@S30W120.earth_mag4km_02m_p.nc", # Specific grid for 02m test
187-
# Earth mask grid
188-
"@earth_mask_01d_g",
189-
# Earth free-air anomaly grids
190-
"@earth_faa_01d_g",
191-
"@N00W030.earth_faa_01m_p.nc", # Specific grid for 01m test
192-
# Earth vertical gravity gradient grids
193-
"@earth_vgg_01d_g",
194-
"@N00W030.earth_vgg_01m_p.nc", # Specific grid for 01m test
195-
# Earth WDMAM grids
196-
"@earth_wdmam_01d_g",
197-
"@S90E000.earth_wdmam_03m_g.nc", # Specific grid for 03m test
198-
# Earth day/night grids
199-
"@earth_day_01d_p",
200-
# Other cache files
201-
"@capitals.gmt",
202-
"@circuit.png",
203-
"@earth_relief_20m_holes.grd",
204-
"@EGM96_to_36.txt",
205-
"@MaunaLoa_CO2.txt",
206-
"@RidgeTest.shp",
207-
"@RidgeTest.shx",
208-
"@RidgeTest.dbf",
209-
"@RidgeTest.prj",
210-
"@Table_5_11.txt",
211-
"@Table_5_11_mean.xyz",
212-
"@fractures_06.txt",
213-
"@hotspots.txt",
214-
"@ridge.txt",
215-
"@mars370d.txt",
216-
"@srtm_tiles.nc", # needed for 03s and 01s relief data
217-
"@static_earth_relief.nc",
218-
"@ternary.txt",
219-
"@test.dat.nc",
220-
"@tut_bathy.nc",
221-
"@tut_quakes.ngdc",
222-
"@tut_ship.xyz",
223-
"@usgs_quakes_22.txt",
224-
]
225-
which(fname=datasets, download="a")
226-
227-
228145
def load_static_earth_relief():
229146
"""
230147
Load the static_earth_relief file for internal testing.

0 commit comments

Comments
 (0)