|
1 | 1 | import * as crypto from "node:crypto";
|
2 | 2 | import * as path from "node:path";
|
3 | 3 | import * as cache from "@actions/cache";
|
| 4 | +import type { DownloadOptions } from "@actions/cache/lib/options.js"; |
4 | 5 | import * as core from "@actions/core";
|
5 | 6 | import { exec } from "@actions/exec";
|
6 | 7 | import * as github from "@actions/github";
|
@@ -108,13 +109,14 @@ async function restoreCache(
|
108 | 109 | key: string,
|
109 | 110 | restoreKeys: string[],
|
110 | 111 | paths: string[],
|
| 112 | + options?: DownloadOptions, |
111 | 113 | ) {
|
112 | 114 | if (!cache.isFeatureAvailable()) {
|
113 | 115 | core.info("Actions cache service feature is unavailable");
|
114 | 116 | return;
|
115 | 117 | }
|
116 | 118 | try {
|
117 |
| - const cacheKey = await cache.restoreCache(paths, key, restoreKeys); |
| 119 | + const cacheKey = await cache.restoreCache(paths, key, restoreKeys, options); |
118 | 120 | if (cacheKey) {
|
119 | 121 | core.info(`Cache restored from key: ${cacheKey}`);
|
120 | 122 | } else {
|
@@ -212,8 +214,13 @@ export async function saveOpamCache() {
|
212 | 214 | "--untracked",
|
213 | 215 | "--unused-repositories",
|
214 | 216 | ]);
|
215 |
| - const { key } = await composeOpamCacheKeys(); |
| 217 | + const { key, restoreKeys } = await composeOpamCacheKeys(); |
216 | 218 | 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 | + } |
218 | 225 | });
|
219 | 226 | }
|
0 commit comments