Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not create cache if cache already exists #936

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions dist/post/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions packages/setup-ocaml/src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as crypto from "node:crypto";
import * as path from "node:path";
import * as cache from "@actions/cache";
import type { DownloadOptions } from "@actions/cache/lib/options.js";
import * as core from "@actions/core";
import { exec } from "@actions/exec";
import * as github from "@actions/github";
Expand Down Expand Up @@ -108,13 +109,14 @@ async function restoreCache(
key: string,
restoreKeys: string[],
paths: string[],
options?: DownloadOptions,
) {
if (!cache.isFeatureAvailable()) {
core.info("Actions cache service feature is unavailable");
return;
}
try {
const cacheKey = await cache.restoreCache(paths, key, restoreKeys);
const cacheKey = await cache.restoreCache(paths, key, restoreKeys, options);
if (cacheKey) {
core.info(`Cache restored from key: ${cacheKey}`);
} else {
Expand Down Expand Up @@ -212,8 +214,17 @@ export async function saveOpamCache() {
"--untracked",
"--unused-repositories",
]);
const { key } = await composeOpamCacheKeys();
const { key, restoreKeys } = await composeOpamCacheKeys();
const paths = composeOpamCachePaths();
await saveCache(key, paths);
const cacheHit = await restoreCache(key, restoreKeys, paths, {
lookupOnly: true,
});
if (cacheHit) {
core.info(
"Cache entry with the same key, version, and scope already exists",
);
} else {
await saveCache(key, paths);
}
});
}
Loading