Skip to content

Commit ce51ff4

Browse files
committed
Do not create cache if cache already exists
Signed-off-by: Sora Morimoto <sora@morimoto.io>
1 parent 71b1213 commit ce51ff4

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

dist/index.js

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

dist/post/index.js

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

packages/setup-ocaml/src/cache.ts

+10-3
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,13 @@ 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+
await saveCache(key, paths);
224+
}
218225
});
219226
}

0 commit comments

Comments
 (0)