MCPcopy
hub / github.com/actions/cache / saveImpl

Function saveImpl

src/saveImpl.ts:17–79  ·  view source on GitHub ↗
(
    stateProvider: IStateProvider
)

Source from the content-addressed store, hash-verified

15process.on("uncaughtException", e => utils.logWarning(e.message));
16
17export async function saveImpl(
18 stateProvider: IStateProvider
19): Promise<number | void> {
20 let cacheId = -1;
21 try {
22 if (!utils.isCacheFeatureAvailable()) {
23 return;
24 }
25
26 if (!utils.isValidEvent()) {
27 utils.logWarning(
28 `Event Validation Error: The event type ${
29 process.env[Events.Key]
30 } is not supported because it's not tied to a branch or tag ref.`
31 );
32 return;
33 }
34
35 // If restore has stored a primary key in state, reuse that
36 // Else re-evaluate from inputs
37 const primaryKey =
38 stateProvider.getState(State.CachePrimaryKey) ||
39 core.getInput(Inputs.Key);
40
41 if (!primaryKey) {
42 utils.logWarning(`Key is not specified.`);
43 return;
44 }
45
46 // If matched restore key is same as primary key, then do not save cache
47 // NO-OP in case of SaveOnly action
48 const restoredKey = stateProvider.getCacheState();
49
50 if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
51 core.info(
52 `Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
53 );
54 return;
55 }
56
57 const cachePaths = utils.getInputAsArray(Inputs.Path, {
58 required: true
59 });
60
61 const enableCrossOsArchive = utils.getInputAsBool(
62 Inputs.EnableCrossOsArchive
63 );
64
65 cacheId = await cache.saveCache(
66 cachePaths,
67 primaryKey,
68 { uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize) },
69 enableCrossOsArchive
70 );
71
72 if (cacheId != -1) {
73 core.info(`Cache saved with key: ${primaryKey}`);
74 }

Callers 3

saveOnlyRunFunction · 0.85
saveRunFunction · 0.85
saveImpl.test.tsFile · 0.85

Calls 2

getStateMethod · 0.80
getCacheStateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…