Skip to content

Commit e74e959

Browse files
committed
Add an option to disable dependency caching on demand
fixes #24
1 parent 9b449c3 commit e74e959

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
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

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ inputs:
1414
scarb-lock:
1515
description: Path to Scarb.lock file
1616
required: false
17+
cache:
18+
description: Enable dependency caching
19+
required: false
1720
outputs:
1821
scarb-prefix:
1922
description: The prefix of the installed Scarb

lib/cache-save.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import * as core from "@actions/core";
22
import * as cache from "@actions/cache";
33

4-
import { getCacheDirectory, State } from "./cache-utils";
4+
import { getCacheDirectory, isCacheEnabled, State } from "./cache-utils";
55

66
async function saveCache() {
7+
const cacheInput = core.getInput("cache");
8+
9+
if (!isCacheEnabled(cacheInput)) {
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/cache-utils.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export const State = {
1111
CacheMatchedKey: "matched_key",
1212
};
1313

14+
export function isCacheEnabled(cacheInput) {
15+
cacheInput = cacheInput || "true";
16+
return cacheInput === "true";
17+
}
18+
1419
export async function getCacheDirectory() {
1520
// NOTE: The `cache path` command was introduced in Scarb 0.7.0. We do not want to break compatibility with older
1621
// versions yet, so we fall back to a well-known cache path if this command is not available.

lib/main.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import {
99
import { downloadScarb } from "./download";
1010
import { getOsTriplet } from "./platform";
1111
import { restoreCache } from "./cache-restore";
12+
import { isCacheEnabled } from "./cache-utils";
1213

1314
export default async function main() {
1415
try {
1516
const scarbVersionInput = core.getInput("scarb-version");
1617
const toolVersionsPathInput = core.getInput("tool-versions");
1718
const scarbLockPathInput = core.getInput("scarb-lock");
19+
const cacheInput = core.getInput("cache");
1820

1921
const { repo: scarbRepo, version: scarbVersion } = await determineVersion(
2022
scarbVersionInput,
@@ -48,13 +50,17 @@ export default async function main() {
4850

4951
core.setOutput("scarb-version", await getFullVersionFromScarb());
5052

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-
});
53+
if (isCacheEnabled(cacheInput)) {
54+
await restoreCache(scarbLockPathInput).catch((e) => {
55+
core.error(
56+
`There was an error when restoring cache: ${
57+
e instanceof Error ? e.message : e
58+
}`,
59+
);
60+
});
61+
} else {
62+
core.info(`Caching disabled, not restoring cache.`);
63+
}
5864
} catch (e) {
5965
core.setFailed(e);
6066
}

0 commit comments

Comments
 (0)