Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip caching steps in action if no test resources are found #37

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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