Skip to content

Commit 65c8cbb

Browse files
authored
Merge pull request #86 from potiuk/add-optional-overwrite-input-for-restore
Add optional "clean" parameter to input of stash/restore action
2 parents 3762d30 + 4400ad7 commit 65c8cbb

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

stash/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ Each action (restore and save) has specific inputs tailored to its functionality
7272
they are specifically modeled after `actions/cache` and `actions/upload-artifact` to provide a drop in replacement.
7373
Please refer to the action metadata (`action.yml`) for a comprehensive list of inputs, including descriptions and default values.
7474

75-
Additionally the `restore` action has an output `stash-hit` which is set to `true` if the cache was restored successfully,
75+
The `restore` action has an optional "overwrite" input which defaults to `false` - when set to "true", it
76+
will delete the existing contents of the target directory before restoring the stash.
77+
78+
Additionally, the `restore` action has an output `stash-hit` which is set to `true` if the cache was restored successfully,
7679
`false` if no cache was restored and '' if the action failed (an error will be thrown unless `continue-on-error` is set).
7780
A technical limitation of composite actions like `Stash` is that all outputs are **strings**.
78-
Therefore an explicit comparison has to be used when using the output:
81+
Therefore, an explicit comparison has to be used when using the output:
7982
`if: ${{ steps.restore-stash.outputs.stash-hit == 'true' }}`

stash/restore/action.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ inputs:
2828
To reduce amount of api calls (1000/h/repo limit) the name of the
2929
current branch will be appended to the key. Key and branchname will be normalized.
3030
required: true
31-
3231
path:
3332
description: 'The directory the stash will be restored in.'
3433
default: ${{ github.workspace }}
@@ -37,6 +36,10 @@ inputs:
3736
description: 'GITHUB_TOKEN to use to authenticate against the artifacts api.'
3837
default: ${{ github.token }}
3938

39+
clean:
40+
description: 'Whether the stash_directory should be removed before downloading the stash.'
41+
default: 'false'
42+
4043
only-current-branch:
4144
description: >
4245
If true, only the current branch will be searched for the stash.
@@ -148,6 +151,12 @@ runs:
148151
run: |
149152
# Catch errors in the download with || to avoid the whole workflow failing
150153
# when the download times out
154+
if [[ "${{ inputs.clean }}" == "true" ]]; then
155+
if [[ -d "$STASH_DIR" ]]; then
156+
echo "Removing existing stash directory: $STASH_DIR"
157+
rm -rf "$STASH_DIR"
158+
fi
159+
fi
151160
gh run download "$STASH_RUN_ID" \
152161
--name "$STASH_NAME" \
153162
--dir "$STASH_DIR" \

0 commit comments

Comments
 (0)