Skip to content

Commit

Permalink
Skip caching steps in action if no test resources are found (#37)
Browse files Browse the repository at this point in the history
* Skip caching steps in action if no test resources are found

* return empty cachekey and dest_paths if no test resources are detected

* update changelog

* update md
  • Loading branch information
rcannood authored Jul 5, 2024
1 parent 2fe08a7 commit 9f7c35f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# viash-actions v6.3.1

## Bug fixes

* `project/sync-and-cache`: Skip caching steps in action if no test resources are found (PR #37).

# viash-actions v6.3.0

## New functionality
Expand Down
6 changes: 4 additions & 2 deletions project/sync-and-cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ info:

### Outputs

- `cache_key`: Caching key.
- `dest_paths`: Paths to the synced resources.
- `cache_key`: Caching key to use to restore the cache. If no test
resources are detected, this will be an empty string.
- `dest_paths`: Paths to the synced resources. If no test resources are
detected, this will be an empty string.

## Examples

Expand Down
19 changes: 16 additions & 3 deletions project/sync-and-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,26 @@ inputs:
default: cachekey__
outputs:
cache_key:
description: Caching key.
description: Caching key to use to restore the cache. If no test resources are detected, this will be an empty string.
value: ${{ steps.cache_key.outputs.cache_key }}
dest_paths:
description: Paths to the synced resources.
description: Paths to the synced resources. If no test resources are detected, this will be an empty string.
value: ${{ steps.test_resources.outputs.dest_paths }}
runs:
using: 'composite'
steps:
- name: Test resources
- name: Detect test resources
id: test_resources
shell: bash
run: |
resources_detected=$(yq e '.info | has("test_resources")' "${{ inputs.project_config }}")
if [ "$resources_detected" == "false" ]; then
echo "No test resources detected."
echo "cache_key=" >> $GITHUB_OUTPUT
echo "dest_paths=" >> $GITHUB_OUTPUT
exit 0
fi
# reformat the test resources into a pseudo-json that can be read line-by-line by bash
test_resources=$(
yq e \
Expand Down Expand Up @@ -70,6 +78,7 @@ runs:
- name: Create hash key
shell: bash
id: cache_key
if: ${{ steps.test_resources.outputs.cache_key != '' }}
run: |
function hash_s3() {
local s3_path="$1"
Expand Down Expand Up @@ -102,6 +111,7 @@ runs:
- name: Print resources
shell: bash
if: ${{ steps.test_resources.outputs.cache_key != '' }}
run: |
echo "### Cache key: ${{ steps.cache_key.outputs.cache_key }}"
echo
Expand All @@ -119,6 +129,7 @@ runs:
# initialize cache
- name: Cache resources
uses: actions/cache@v4
if: ${{ steps.test_resources.outputs.cache_key != '' }}
with:
path: ${{ steps.test_resources.outputs.dest_paths }}
key: ${{ steps.cache_key.outputs.cache_key }}
Expand All @@ -127,6 +138,7 @@ runs:
# sync if need be
- name: Sync resources
shell: bash
if: ${{ steps.test_resources.outputs.cache_key != '' }}
run: |
function sync_s3() {
local s3_path="$1"
Expand All @@ -153,6 +165,7 @@ runs:
- name: List resources
shell: bash
if: ${{ steps.test_resources.outputs.cache_key != '' }}
run: |
echo "${{ steps.test_resources.outputs.test_resources }}" | \
while read -r line; do
Expand Down

0 comments on commit 9f7c35f

Please sign in to comment.