Skip to content

Commit 22f50f6

Browse files
authored
Add an option to disable dependency caching on demand (#34)
fixes #24
1 parent 767b3f7 commit 22f50f6

File tree

9 files changed

+52
-16
lines changed

9 files changed

+52
-16
lines changed

.github/workflows/ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ jobs:
9494
with:
9595
scarb-lock: ./subdir/Scarb.lock
9696

97+
- name: "Setup Scarb with caching disabled"
98+
uses: ./
99+
with:
100+
cache: false
101+
97102
- name: "Create .tool-versions file"
98103
run: echo "scarb 0.7.0" >> .tool-versions
99104
- name: "Setup Scarb using `.tool-versions` file"

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
- `scarb-lock` - **Optional**. String.
3737
- Stating a relative or absolute path to the `Scarb.lock` file used for caching dependencies.
3838
- Empty/not specified: `Scarb.lock` in the working directory will be used.
39+
- `cache` - **Optional**. Boolean.
40+
- Enables caching Scarb dependencies.
41+
- Empty/not specified: `true`.
3942

4043
## Outputs
4144

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ inputs:
1414
scarb-lock:
1515
description: Path to Scarb.lock file
1616
required: false
17+
cache:
18+
description: Enable dependency caching
19+
required: false
20+
default: "true"
1721
outputs:
1822
scarb-prefix:
1923
description: The prefix of the installed Scarb

dist/cache-save/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -73723,6 +73723,13 @@ async function getScarbLockPath(scarbLockPath) {
7372373723

7372473724

7372573725
async function saveCache() {
73726+
const enableCache = core.getBooleanInput("cache");
73727+
73728+
if (!enableCache) {
73729+
core.info(`Caching disabled, not saving cache.`);
73730+
return;
73731+
}
73732+
7372673733
try {
7372773734
const primaryKey = core.getState(State.CachePrimaryKey);
7372873735
const matchedKey = core.getState(State.CacheMatchedKey);

dist/cache-save/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup/index.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -74854,6 +74854,7 @@ async function main() {
7485474854
const scarbVersionInput = core.getInput("scarb-version");
7485574855
const toolVersionsPathInput = core.getInput("tool-versions");
7485674856
const scarbLockPathInput = core.getInput("scarb-lock");
74857+
const enableCache = core.getBooleanInput("cache");
7485774858

7485874859
const { repo: scarbRepo, version: scarbVersion } = await determineVersion(
7485974860
scarbVersionInput,
@@ -74887,13 +74888,17 @@ async function main() {
7488774888

7488874889
core.setOutput("scarb-version", await getFullVersionFromScarb());
7488974890

74890-
await restoreCache(scarbLockPathInput).catch((e) => {
74891-
core.error(
74892-
`There was an error when restoring cache: ${
74893-
e instanceof Error ? e.message : e
74894-
}`,
74895-
);
74896-
});
74891+
if (enableCache) {
74892+
await restoreCache(scarbLockPathInput).catch((e) => {
74893+
core.error(
74894+
`There was an error when restoring cache: ${
74895+
e instanceof Error ? e.message : e
74896+
}`,
74897+
);
74898+
});
74899+
} else {
74900+
core.info(`Caching disabled, not restoring cache.`);
74901+
}
7489774902
} catch (e) {
7489874903
core.setFailed(e);
7489974904
}

dist/setup/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/cache-save.js

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import * as cache from "@actions/cache";
44
import { getCacheDirectory, State } from "./cache-utils";
55

66
async function saveCache() {
7+
const enableCache = core.getBooleanInput("cache");
8+
9+
if (!enableCache) {
10+
core.info(`Caching disabled, not saving cache.`);
11+
return;
12+
}
13+
714
try {
815
const primaryKey = core.getState(State.CachePrimaryKey);
916
const matchedKey = core.getState(State.CacheMatchedKey);

lib/main.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default async function main() {
1515
const scarbVersionInput = core.getInput("scarb-version");
1616
const toolVersionsPathInput = core.getInput("tool-versions");
1717
const scarbLockPathInput = core.getInput("scarb-lock");
18+
const enableCache = core.getBooleanInput("cache");
1819

1920
const { repo: scarbRepo, version: scarbVersion } = await determineVersion(
2021
scarbVersionInput,
@@ -48,13 +49,17 @@ export default async function main() {
4849

4950
core.setOutput("scarb-version", await getFullVersionFromScarb());
5051

51-
await restoreCache(scarbLockPathInput).catch((e) => {
52-
core.error(
53-
`There was an error when restoring cache: ${
54-
e instanceof Error ? e.message : e
55-
}`,
56-
);
57-
});
52+
if (enableCache) {
53+
await restoreCache(scarbLockPathInput).catch((e) => {
54+
core.error(
55+
`There was an error when restoring cache: ${
56+
e instanceof Error ? e.message : e
57+
}`,
58+
);
59+
});
60+
} else {
61+
core.info(`Caching disabled, not restoring cache.`);
62+
}
5863
} catch (e) {
5964
core.setFailed(e);
6065
}

0 commit comments

Comments
 (0)