forked from spacetelescope/webbpsf
-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (66 loc) · 2.4 KB
/
retrieve_cache.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
# retrieves the latest cache key for WebbPSF data;
# the cache key is in the form `webbpsf-data-mini-1.3.0`,
# `webbpsf-data-full-1.2.6`, etc.
#
# to retrieve the WebbPSF data cache in your test workflow,
# first create a cache of the dataset in your repository
# (see `download_data.yml` for instructions), then
# call this workflow as a needed job and use `actions/cache/restore`
# to place the data in your test job:
#
# # .github/workflows/tests.yml
# name: run tests
# ...
# jobs:
# webbpsf_data_cache_key:
# uses: spacetelescope/webbpsf/.github/workflows/retrieve_cache.yml@develop
# with:
# minimal: true
# tests:
# needs: [ webbpsf_data_cache_key ]
# steps:
# ...
# - name: retrieve WebbPSF data cache
# uses: actions/cache/restore@v4
# with:
# path: ${{ runner.temp }}/webbpsf-data
# key: ${{ needs.webbpsf_data_cache_key.outputs.cache_key }}
# ...
name: retrieve latest data cache key
on:
workflow_call:
inputs:
minimal:
description: minimal dataset
type: boolean
required: false
default: true
outputs:
version:
value: ${{ jobs.retrieve_latest_cache_key.outputs.version }}
cache_path:
value: ${{ jobs.retrieve_latest_cache_key.outputs.cache_path }}
cache_key:
value: ${{ jobs.retrieve_latest_cache_key.outputs.cache_key }}
jobs:
retrieve_latest_cache_key:
name: retrieve latest WebbPSF data cache key
runs-on: ubuntu-latest
steps:
- name: retrieve latest data cache key
id: latest_cache_key
run: |
# use actions/gh-actions-cache to allow filtering by key
gh extension install actions/gh-actions-cache
CACHE_KEY=$(gh actions-cache list -R ${{ github.repository }} --key webbpsf-data-${{ inputs.minimal && 'mini' || 'full' }}- --sort created-at | cut -f 1 | head -n 1)
if [ "$CACHE_KEY" == '' ]; then exit 1; fi
echo cache_key=$CACHE_KEY >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
- run: echo ${{ steps.latest_cache_key.outputs.cache_key }}
- id: version
run: echo "version=$(echo ${{ steps.latest_cache_key.outputs.cache_key }} | awk -F '-' '{print $4}')" >> $GITHUB_OUTPUT
outputs:
version: ${{ steps.version.outputs.version }}
cache_path: ${{ runner.temp }}/data/
cache_key: ${{ steps.latest_cache_key.outputs.cache_key }}