MCPcopy Index your code
hub / github.com/actions/setup-node / cachePackages

Function cachePackages

src/cache-save.ts:35–70  ·  view source on GitHub ↗
(packageManager: string)

Source from the content-addressed store, hash-verified

33}
34
35const cachePackages = async (packageManager: string) => {
36 const state = core.getState(State.CacheMatchedKey);
37 const primaryKey = core.getState(State.CachePrimaryKey);
38 const cachePaths = JSON.parse(
39 core.getState(State.CachePaths) || '[]'
40 ) as string[];
41
42 const packageManagerInfo = await getPackageManagerInfo(packageManager);
43 if (!packageManagerInfo) {
44 core.debug(`Caching for '${packageManager}' is not supported`);
45 return;
46 }
47
48 if (!cachePaths.length) {
49 // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
50 // export declare function getInput(name: string, options?: InputOptions): string;
51 const cacheDependencyPath = core.getInput('cache-dependency-path') || '';
52 throw new Error(
53 `Cache folder paths are not retrieved for ${packageManager} with cache-dependency-path = ${cacheDependencyPath}`
54 );
55 }
56
57 if (primaryKey === state) {
58 core.info(
59 `Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
60 );
61 return;
62 }
63
64 const cacheId = await cache.saveCache(cachePaths, primaryKey);
65 if (cacheId == -1) {
66 return;
67 }
68
69 core.info(`Cache saved with the key: ${primaryKey}`);
70};
71
72run(true);

Callers 1

runFunction · 0.85

Calls 1

getPackageManagerInfoFunction · 0.90

Tested by

no test coverage detected