MCPcopy Index your code
hub / github.com/actions/setup-python / saveCache

Function saveCache

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

Source from the content-addressed store, hash-verified

24}
25
26async function saveCache(packageManager: string) {
27 const cachePathState = core.getState(State.CACHE_PATHS);
28
29 if (!cachePathState) {
30 core.warning(
31 'Cache paths are empty. Please check the previous logs and make sure that the python version is specified'
32 );
33 return;
34 }
35
36 const cachePaths = JSON.parse(cachePathState) as string[];
37
38 core.debug(`paths for caching are ${cachePaths.join(', ')}`);
39
40 if (!isCacheDirectoryExists(cachePaths)) {
41 core.warning(
42 `Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePaths.join(
43 ', '
44 )}. This likely indicates that there are no dependencies to cache. Consider removing the cache step if it is not needed.`
45 );
46 return;
47 }
48
49 const primaryKey = core.getState(State.STATE_CACHE_PRIMARY_KEY);
50 const matchedKey = core.getState(State.CACHE_MATCHED_KEY);
51
52 if (!primaryKey) {
53 core.warning('Error retrieving key from state.');
54 return;
55 } else if (matchedKey === primaryKey) {
56 // no change in target directories
57 core.info(
58 `Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
59 );
60 return;
61 }
62
63 let cacheId = 0;
64
65 try {
66 cacheId = await cache.saveCache(cachePaths, primaryKey);
67 } catch (err) {
68 const message = (err as Error).message;
69 core.info(`[warning]${message}`);
70 return;
71 }
72
73 if (cacheId === -1) {
74 // saveCache returns -1 without throwing when the cache was not saved, e.g.
75 // a reserve collision or a read-only token (fork PR). @actions/cache has
76 // already logged the reason at the appropriate severity, so just trace it.
77 core.debug(`Cache was not saved for the key: ${primaryKey}`);
78 return;
79 }
80 core.info(`Cache saved with the key: ${primaryKey}`);
81}
82
83function isCacheDirectoryExists(cacheDirectory: string[]) {

Callers 1

runFunction · 0.85

Calls 1

isCacheDirectoryExistsFunction · 0.85

Tested by

no test coverage detected