Skip to content

Commit 202cd8c

Browse files
Cache from lockfile instead of manifest (#22)
Closes #9
1 parent 8f4082f commit 202cd8c

File tree

6 files changed

+46
-35
lines changed

6 files changed

+46
-35
lines changed

dist/cache-save/index.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -59390,7 +59390,7 @@ var core = __nccwpck_require__(2186);
5939059390
// EXTERNAL MODULE: ./node_modules/@actions/cache/lib/cache.js
5939159391
var cache = __nccwpck_require__(7799);
5939259392
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
59393-
var lib_exec = __nccwpck_require__(1514);
59393+
var exec = __nccwpck_require__(1514);
5939459394
// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js
5939559395
var lib_glob = __nccwpck_require__(8090);
5939659396
// EXTERNAL MODULE: external "os"
@@ -59399,6 +59399,8 @@ var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
5939959399
// EXTERNAL MODULE: external "path"
5940059400
var external_path_ = __nccwpck_require__(1017);
5940159401
var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_);
59402+
;// CONCATENATED MODULE: external "fs/promises"
59403+
const promises_namespaceObject = require("fs/promises");
5940259404
;// CONCATENATED MODULE: ./lib/cache-utils.js
5940359405

5940459406

@@ -59407,6 +59409,7 @@ var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_);
5940759409

5940859410

5940959411

59412+
5941059413
const State = {
5941159414
CachePrimaryKey: "primary_key",
5941259415
CacheMatchedKey: "matched_key",
@@ -59423,7 +59426,7 @@ async function getCacheDirectory() {
5942359426
core.debug(`scarb cache path fallback failed: ${e.message}`);
5942459427
}
5942559428

59426-
const { stdout, exitCode } = await lib_exec.getExecOutput("scarb cache path");
59429+
const { stdout, exitCode } = await exec.getExecOutput("scarb cache path");
5942759430

5942859431
if (exitCode > 0) {
5942959432
throw new Error(
@@ -59435,7 +59438,7 @@ async function getCacheDirectory() {
5943559438
}
5943659439

5943759440
async function isScarbMissingCachePathCommand() {
59438-
const { stdout } = await lib_exec.getExecOutput("scarb -V");
59441+
const { stdout } = await exec.getExecOutput("scarb -V");
5943959442
return stdout.match(/^scarb 0\.[0-6]\./) != null;
5944059443
}
5944159444

@@ -59457,27 +59460,25 @@ function wellKnownCachePath() {
5945759460

5945859461
async function getCacheKey() {
5945959462
const platform = process.env.RUNNER_OS;
59460-
const fileHash = await glob.hashFiles(await getScarbManifestPath());
59463+
const fileHash = await glob.hashFiles(await getScarbLockfilePath());
5946159464

5946259465
if (!fileHash) {
5946359466
throw new Error(
59464-
"failed to cache dependencies: unable to hash Scarb.toml file",
59467+
"failed to cache dependencies: unable to hash Scarb.lock file",
5946559468
);
5946659469
}
5946759470

5946859471
return `scarb-cache-${platform}-${fileHash}`.toLowerCase();
5946959472
}
5947059473

59471-
async function getScarbManifestPath() {
59472-
const { stdout, exitCode } = await exec.getExecOutput("scarb manifest-path");
59474+
async function getScarbLockfilePath() {
59475+
const lockfilePath = path.join(process.env.GITHUB_WORKSPACE, "Scarb.lock");
5947359476

59474-
if (exitCode > 0) {
59475-
throw new Error(
59476-
"failed to find Scarb.toml: command `scarb manifest-path` failed",
59477-
);
59478-
}
59477+
await fs.access(lockfilePath).catch((_) => {
59478+
throw new Error("failed to find Scarb.lock");
59479+
});
5947959480

59480-
return stdout.trim();
59481+
return lockfilePath;
5948159482
}
5948259483

5948359484
;// CONCATENATED MODULE: ./lib/cache-save.js
@@ -59493,6 +59494,12 @@ async function saveCache() {
5949359494

5949459495
if (primaryKey !== matchedKey) {
5949559496
await cache.saveCache([await getCacheDirectory()], primaryKey);
59497+
} else if (primaryKey === "" && matchedKey === "") {
59498+
// When using action for the first time and the project doesn't have Scarb.lock,
59499+
// `restoreCache()` returns an error during `getCacheKey()` method.
59500+
// As a result, primaryKey and matchedKey (by default) are empty strings,
59501+
// which would satisfy `else` branch, even though no cache would be found.
59502+
core.info(`Cache entry not found, not saving cache.`);
5949659503
} else {
5949759504
core.info(`Cache hit occurred, not saving cache.`);
5949859505
}

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -60590,6 +60590,7 @@ var glob = __nccwpck_require__(8090);
6059060590

6059160591

6059260592

60593+
6059360594
const State = {
6059460595
CachePrimaryKey: "primary_key",
6059560596
CacheMatchedKey: "matched_key",
@@ -60640,27 +60641,25 @@ function wellKnownCachePath() {
6064060641

6064160642
async function getCacheKey() {
6064260643
const platform = process.env.RUNNER_OS;
60643-
const fileHash = await glob.hashFiles(await getScarbManifestPath());
60644+
const fileHash = await glob.hashFiles(await getScarbLockfilePath());
6064460645

6064560646
if (!fileHash) {
6064660647
throw new Error(
60647-
"failed to cache dependencies: unable to hash Scarb.toml file",
60648+
"failed to cache dependencies: unable to hash Scarb.lock file",
6064860649
);
6064960650
}
6065060651

6065160652
return `scarb-cache-${platform}-${fileHash}`.toLowerCase();
6065260653
}
6065360654

60654-
async function getScarbManifestPath() {
60655-
const { stdout, exitCode } = await exec.getExecOutput("scarb manifest-path");
60655+
async function getScarbLockfilePath() {
60656+
const lockfilePath = external_path_default().join(process.env.GITHUB_WORKSPACE, "Scarb.lock");
6065660657

60657-
if (exitCode > 0) {
60658-
throw new Error(
60659-
"failed to find Scarb.toml: command `scarb manifest-path` failed",
60660-
);
60661-
}
60658+
await promises_default().access(lockfilePath).catch((_) => {
60659+
throw new Error("failed to find Scarb.lock");
60660+
});
6066260661

60663-
return stdout.trim();
60662+
return lockfilePath;
6066460663
}
6066560664

6066660665
;// CONCATENATED MODULE: ./lib/cache-restore.js

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

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ async function saveCache() {
1010

1111
if (primaryKey !== matchedKey) {
1212
await cache.saveCache([await getCacheDirectory()], primaryKey);
13+
} else if (primaryKey === "" && matchedKey === "") {
14+
// When using action for the first time and the project doesn't have Scarb.lock,
15+
// `restoreCache()` returns an error during `getCacheKey()` method.
16+
// As a result, primaryKey and matchedKey (by default) are empty strings,
17+
// which would satisfy `else` branch, even though no cache would be found.
18+
core.info(`Cache entry not found, not saving cache.`);
1319
} else {
1420
core.info(`Cache hit occurred, not saving cache.`);
1521
}

lib/cache-utils.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as glob from "@actions/glob";
44

55
import os from "os";
66
import path from "path";
7+
import fs from "fs/promises";
78

89
export const State = {
910
CachePrimaryKey: "primary_key",
@@ -55,25 +56,23 @@ function wellKnownCachePath() {
5556

5657
export async function getCacheKey() {
5758
const platform = process.env.RUNNER_OS;
58-
const fileHash = await glob.hashFiles(await getScarbManifestPath());
59+
const fileHash = await glob.hashFiles(await getScarbLockfilePath());
5960

6061
if (!fileHash) {
6162
throw new Error(
62-
"failed to cache dependencies: unable to hash Scarb.toml file",
63+
"failed to cache dependencies: unable to hash Scarb.lock file",
6364
);
6465
}
6566

6667
return `scarb-cache-${platform}-${fileHash}`.toLowerCase();
6768
}
6869

69-
async function getScarbManifestPath() {
70-
const { stdout, exitCode } = await exec.getExecOutput("scarb manifest-path");
70+
async function getScarbLockfilePath() {
71+
const lockfilePath = path.join(process.env.GITHUB_WORKSPACE, "Scarb.lock");
7172

72-
if (exitCode > 0) {
73-
throw new Error(
74-
"failed to find Scarb.toml: command `scarb manifest-path` failed",
75-
);
76-
}
73+
await fs.access(lockfilePath).catch((_) => {
74+
throw new Error("failed to find Scarb.lock");
75+
});
7776

78-
return stdout.trim();
77+
return lockfilePath;
7978
}

0 commit comments

Comments
 (0)