-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
59 lines (57 loc) · 1.61 KB
/
action.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
name: Sync and cache an S3 bucket
author: Data Intuitive
description: >
Sync an S3 bucket to a folder and create a cache.
inputs:
s3_bucket:
required: true
description: 'Path to an S3 bucket.'
dest_path:
required: true
description: 'Where to store the data.'
cache_key_prefix:
required: false
description: A prefix for the cache hash key. Prefix is also used for restoring stale cache if no cache hit occurred for key.
default: cachekey__
outputs:
cache_key:
description: Caching key.
value: ${{ steps.cache_hash.outputs.cache_hash }}
runs:
using: 'composite'
steps:
# create cache_hash key
- name: Create hash key
shell: bash
id: cache_hash
run: |
hash=$(
AWS_EC2_METADATA_DISABLED=true \
aws s3 ls \
${{ inputs.s3_bucket }} \
--recursive \
--no-sign-request | \
md5sum | \
awk '{ print $1 }'
)
echo "cache_hash=${{ inputs.cache_key_prefix}}$hash" >> $GITHUB_OUTPUT
# initialize cache
- name: Cache resources
uses: actions/cache@v4
with:
path: ${{ inputs.dest_path }}
key: ${{ steps.cache_hash.outputs.cache_hash }}
restore-keys: ${{ inputs.cache_key_prefix}}
# sync if need be
- name: Sync resources
shell: bash
run: |
AWS_EC2_METADATA_DISABLED=true \
aws s3 sync \
${{ inputs.s3_bucket }} \
${{ inputs.dest_path }} \
--delete --no-sign-request
- name: List resources
shell: bash
run: |
tree ${{ inputs.dest_path }} -L 3