Skip to content

Commit f4e6c94

Browse files
authored
Support specifying custom Scarb.lock path (#27)
- Allow specifying path to `Scarb.lock` via optional `scarb-lock` argument - If not specified, default to `Scarb.lock` in cwd for consistency with `toolVersionsPath` - Fix caching test steps Closes #25
1 parent faa9d47 commit f4e6c94

File tree

10 files changed

+52
-23
lines changed

10 files changed

+52
-23
lines changed

.github/workflows/ci.yml

+24-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,31 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v3
2323

24-
- name: "Create bare bones Scarb.toml for cache testing"
24+
- name: "Create bare bones Scarb.lock for cache testing"
2525
shell: bash
2626
run: |
27-
cat <<EOF > Scarb.toml
28-
[package]
27+
cat <<EOF > Scarb.lock
28+
# Code generated by scarb DO NOT EDIT.
29+
version = 1
30+
31+
[[package]]
2932
name = "example_package"
3033
version = "1.0.0"
3134
EOF
3235
36+
- name: "Create Scarb.lock in subfolder for cache testing"
37+
shell: bash
38+
run: |
39+
mkdir ./subdir
40+
cat <<EOF > ./subdir/Scarb.lock
41+
# Code generated by scarb DO NOT EDIT.
42+
version = 1
43+
44+
[[package]]
45+
name = "example_package"
46+
version = "1.1.0"
47+
EOF
48+
3349
- name: "Fetch latest Scarb version from GitHub releases"
3450
id: version
3551
shell: pwsh
@@ -73,6 +89,11 @@ jobs:
7389
scarb-version: nightly
7490
- run: scarb --version | grep "${{ steps.version.outputs.LATEST_NIGHTLY_VERSION }}"
7591

92+
- name: "Setup Scarb with `scarb-lock` file in subfolder"
93+
uses: ./
94+
with:
95+
scarb-lock: ./subdir/Scarb.lock
96+
7697
- name: "Create .tool-versions file"
7798
run: echo "scarb 0.7.0" >> .tool-versions
7899
- name: "Setup Scarb using `.tool-versions` file"

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
- `tool-versions` - **Optional**. String.
3434
- Stating a relative or absolute path to the `.tool-versions` file.
3535
- Should be used only if `scarb-version` is not specified.
36+
- `scarb-lock` - **Optional**. String.
37+
- Stating a relative or absolute path to the `Scarb.lock` file used for caching dependencies.
38+
- Empty/not specified: `Scarb.lock` in the working directory will be used.
3639

3740
## Outputs
3841

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
tool-versions:
1212
description: Path to .tool-versions file
1313
required: false
14+
scarb-lock:
15+
description: Path to Scarb.lock file
16+
required: false
1417
outputs:
1518
scarb-prefix:
1619
description: The prefix of the installed Scarb

dist/cache-save/index.js

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

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

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

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-restore.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import fs from "fs/promises";
55

66
import { getCacheDirectory, getCacheKey, State } from "./cache-utils";
77

8-
export async function restoreCache() {
8+
export async function restoreCache(scarbLockPath) {
99
const cacheDir = await getCacheDirectory();
1010
await fs.mkdir(cacheDir, { recursive: true });
1111

1212
core.info(`Restoring Scarb cache into ${cacheDir}`);
1313

14-
const primaryKey = await getCacheKey();
14+
const primaryKey = await getCacheKey(scarbLockPath);
1515
core.info(`Cache primary key is ${primaryKey}`);
1616
core.saveState(State.CachePrimaryKey, primaryKey);
1717

lib/cache-utils.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ function wellKnownCachePath() {
5454
}
5555
}
5656

57-
export async function getCacheKey() {
57+
export async function getCacheKey(scarbLockPath) {
5858
const platform = process.env.RUNNER_OS;
59-
const fileHash = await glob.hashFiles(await getScarbLockfilePath());
59+
const fileHash = await glob.hashFiles(await getScarbLockPath(scarbLockPath));
6060

6161
if (!fileHash) {
6262
throw new Error(
@@ -67,8 +67,8 @@ export async function getCacheKey() {
6767
return `scarb-cache-${platform}-${fileHash}`.toLowerCase();
6868
}
6969

70-
async function getScarbLockfilePath() {
71-
const lockfilePath = path.join(process.env.GITHUB_WORKSPACE, "Scarb.lock");
70+
async function getScarbLockPath(scarbLockPath) {
71+
const lockfilePath = scarbLockPath || "Scarb.lock";
7272

7373
await fs.access(lockfilePath).catch((_) => {
7474
throw new Error("failed to find Scarb.lock");

lib/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default async function main() {
1414
try {
1515
const scarbVersionInput = core.getInput("scarb-version");
1616
const toolVersionsPathInput = core.getInput("tool-versions");
17+
const scarbLockPathInput = core.getInput("scarb-lock");
1718

1819
const { repo: scarbRepo, version: scarbVersion } = await determineVersion(
1920
scarbVersionInput,
@@ -47,7 +48,7 @@ export default async function main() {
4748

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

50-
await restoreCache().catch((e) => {
51+
await restoreCache(scarbLockPathInput).catch((e) => {
5152
core.error(
5253
`There was an error when restoring cache: ${
5354
e instanceof Error ? e.message : e

0 commit comments

Comments
 (0)