Skip to content

Commit 052b995

Browse files
authored
Merge pull request #936 from ocaml/do-not-create-cache-if-already-exists
Do not create cache if cache already exists
2 parents 71b1213 + 6bd61de commit 052b995

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

dist/index.js

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/post/index.js

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/setup-ocaml/src/cache.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as crypto from "node:crypto";
22
import * as path from "node:path";
33
import * as cache from "@actions/cache";
4+
import type { DownloadOptions } from "@actions/cache/lib/options.js";
45
import * as core from "@actions/core";
56
import { exec } from "@actions/exec";
67
import * as github from "@actions/github";
@@ -108,13 +109,14 @@ async function restoreCache(
108109
key: string,
109110
restoreKeys: string[],
110111
paths: string[],
112+
options?: DownloadOptions,
111113
) {
112114
if (!cache.isFeatureAvailable()) {
113115
core.info("Actions cache service feature is unavailable");
114116
return;
115117
}
116118
try {
117-
const cacheKey = await cache.restoreCache(paths, key, restoreKeys);
119+
const cacheKey = await cache.restoreCache(paths, key, restoreKeys, options);
118120
if (cacheKey) {
119121
core.info(`Cache restored from key: ${cacheKey}`);
120122
} else {
@@ -212,8 +214,17 @@ export async function saveOpamCache() {
212214
"--untracked",
213215
"--unused-repositories",
214216
]);
215-
const { key } = await composeOpamCacheKeys();
217+
const { key, restoreKeys } = await composeOpamCacheKeys();
216218
const paths = composeOpamCachePaths();
217-
await saveCache(key, paths);
219+
const cacheHit = await restoreCache(key, restoreKeys, paths, {
220+
lookupOnly: true,
221+
});
222+
if (cacheHit) {
223+
core.info(
224+
"Cache entry with the same key, version, and scope already exists",
225+
);
226+
} else {
227+
await saveCache(key, paths);
228+
}
218229
});
219230
}

0 commit comments

Comments
 (0)