Skip to content

Commit

Permalink
Add an option to disable dependency caching on demand (#34)
Browse files Browse the repository at this point in the history
fixes #24
  • Loading branch information
mkaput authored Dec 4, 2024
1 parent 767b3f7 commit 22f50f6
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ jobs:
with:
scarb-lock: ./subdir/Scarb.lock

- name: "Setup Scarb with caching disabled"
uses: ./
with:
cache: false

- name: "Create .tool-versions file"
run: echo "scarb 0.7.0" >> .tool-versions
- name: "Setup Scarb using `.tool-versions` file"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- `scarb-lock` - **Optional**. String.
- Stating a relative or absolute path to the `Scarb.lock` file used for caching dependencies.
- Empty/not specified: `Scarb.lock` in the working directory will be used.
- `cache` - **Optional**. Boolean.
- Enables caching Scarb dependencies.
- Empty/not specified: `true`.

## Outputs

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
scarb-lock:
description: Path to Scarb.lock file
required: false
cache:
description: Enable dependency caching
required: false
default: "true"
outputs:
scarb-prefix:
description: The prefix of the installed Scarb
Expand Down
7 changes: 7 additions & 0 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73723,6 +73723,13 @@ async function getScarbLockPath(scarbLockPath) {


async function saveCache() {
const enableCache = core.getBooleanInput("cache");

if (!enableCache) {
core.info(`Caching disabled, not saving cache.`);
return;
}

try {
const primaryKey = core.getState(State.CachePrimaryKey);
const matchedKey = core.getState(State.CacheMatchedKey);
Expand Down
2 changes: 1 addition & 1 deletion dist/cache-save/index.js.map

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74854,6 +74854,7 @@ async function main() {
const scarbVersionInput = core.getInput("scarb-version");
const toolVersionsPathInput = core.getInput("tool-versions");
const scarbLockPathInput = core.getInput("scarb-lock");
const enableCache = core.getBooleanInput("cache");

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

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

await restoreCache(scarbLockPathInput).catch((e) => {
core.error(
`There was an error when restoring cache: ${
e instanceof Error ? e.message : e
}`,
);
});
if (enableCache) {
await restoreCache(scarbLockPathInput).catch((e) => {
core.error(
`There was an error when restoring cache: ${
e instanceof Error ? e.message : e
}`,
);
});
} else {
core.info(`Caching disabled, not restoring cache.`);
}
} catch (e) {
core.setFailed(e);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/setup/index.js.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions lib/cache-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import * as cache from "@actions/cache";
import { getCacheDirectory, State } from "./cache-utils";

async function saveCache() {
const enableCache = core.getBooleanInput("cache");

if (!enableCache) {
core.info(`Caching disabled, not saving cache.`);
return;
}

try {
const primaryKey = core.getState(State.CachePrimaryKey);
const matchedKey = core.getState(State.CacheMatchedKey);
Expand Down
19 changes: 12 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default async function main() {
const scarbVersionInput = core.getInput("scarb-version");
const toolVersionsPathInput = core.getInput("tool-versions");
const scarbLockPathInput = core.getInput("scarb-lock");
const enableCache = core.getBooleanInput("cache");

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

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

await restoreCache(scarbLockPathInput).catch((e) => {
core.error(
`There was an error when restoring cache: ${
e instanceof Error ? e.message : e
}`,
);
});
if (enableCache) {
await restoreCache(scarbLockPathInput).catch((e) => {
core.error(
`There was an error when restoring cache: ${
e instanceof Error ? e.message : e
}`,
);
});
} else {
core.info(`Caching disabled, not restoring cache.`);
}
} catch (e) {
core.setFailed(e);
}
Expand Down

0 comments on commit 22f50f6

Please sign in to comment.