Skip to content

Commit b91697c

Browse files
authored
feat: add support for restore-only input (#76)
Adds a `restore-only` input to the root action that skips the save (post) step dynamically, similar to actions-cache/restore but toggleable via an expression. Closes #76
1 parent d5372f7 commit b91697c

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ To restore from the cache only:
8787
node_modules
8888
```
8989

90+
To restore from the cache only (dynamically):
91+
92+
```yaml
93+
- uses: tespkg/actions-cache@v1
94+
with:
95+
accessKey: "Q3AM3UQ867SPQQA43P2F" # required
96+
secretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" # required
97+
bucket: actions-cache # required
98+
restore-only: true
99+
# actions/cache compatible properties: https://github.com/actions/cache
100+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
101+
path: |
102+
node_modules
103+
```
104+
90105
To check if cache hits and size is not zero without downloading:
91106

92107
```yaml

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ inputs:
4444
description: "Check if a restore is successfull but dont download/extract cache."
4545
required: false
4646
default: "false"
47+
restore-only:
48+
description: "Restore a cache but don't attempt to save it"
49+
required: false
50+
default: "false"
4751
retry:
4852
description: "Enable retry on failure for S3 operations"
4953
required: false

src/save.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import * as core from "@actions/core";
22
import {
3+
getInputAsBoolean,
34
saveCache,
45
} from "./utils";
56

67
process.on("uncaughtException", (e) => core.info("warning: " + e.message));
78

8-
saveCache(false);
9+
const restoreOnly = getInputAsBoolean("restore-only");
10+
11+
if (!restoreOnly) {
12+
saveCache(false);
13+
}

0 commit comments

Comments
 (0)