mirror of
				https://github.com/actions/cache.git
				synced 2025-11-04 10:14:02 +00:00 
			
		
		
		
	Merge 82f8348041534f80365ba1e8df5d06c3404f26b8 into 515d10b4fd9bb4858066bd5769f55bd498dcdd27
This commit is contained in:
		
						commit
						da55325b54
					
				@ -118,6 +118,44 @@ test("save with exact match returns early", async () => {
 | 
				
			|||||||
    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
					    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test("save with exact match and updates enabled updates the cache", async () => {
 | 
				
			||||||
 | 
					    const infoMock = jest.spyOn(core, "info");
 | 
				
			||||||
 | 
					    const failedMock = jest.spyOn(core, "setFailed");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
 | 
				
			||||||
 | 
					    const savedCacheKey = primaryKey;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    jest.spyOn(core, "getState")
 | 
				
			||||||
 | 
					        // Cache Entry State
 | 
				
			||||||
 | 
					        .mockImplementationOnce(() => {
 | 
				
			||||||
 | 
					            return savedCacheKey;
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					        // Cache Key State
 | 
				
			||||||
 | 
					        .mockImplementationOnce(() => {
 | 
				
			||||||
 | 
					            return primaryKey;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const inputPath = "node_modules";
 | 
				
			||||||
 | 
					    testUtils.setInput(Inputs.Path, inputPath);
 | 
				
			||||||
 | 
					    testUtils.setInput(Inputs.Update, "true");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const cacheId = 4;
 | 
				
			||||||
 | 
					    const saveCacheMock = jest
 | 
				
			||||||
 | 
					        .spyOn(cache, "saveCache")
 | 
				
			||||||
 | 
					        .mockImplementationOnce(() => {
 | 
				
			||||||
 | 
					            return Promise.resolve(cacheId);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    await run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    expect(infoMock).toHaveBeenCalledWith(
 | 
				
			||||||
 | 
					        `Cache hit occurred on the primary key ${primaryKey}, but updates were enabled, so updating cache.`
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    expect(saveCacheMock).toHaveBeenCalledTimes(1);
 | 
				
			||||||
 | 
					    expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey);
 | 
				
			||||||
 | 
					    expect(failedMock).toHaveBeenCalledTimes(0);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test("save with missing input outputs warning", async () => {
 | 
					test("save with missing input outputs warning", async () => {
 | 
				
			||||||
    const logWarningMock = jest.spyOn(actionUtils, "logWarning");
 | 
					    const logWarningMock = jest.spyOn(actionUtils, "logWarning");
 | 
				
			||||||
    const failedMock = jest.spyOn(core, "setFailed");
 | 
					    const failedMock = jest.spyOn(core, "setFailed");
 | 
				
			||||||
 | 
				
			|||||||
@ -11,6 +11,9 @@ inputs:
 | 
				
			|||||||
  restore-keys:
 | 
					  restore-keys:
 | 
				
			||||||
    description: 'An ordered list of keys to use for restoring the cache if no cache hit occurred for key'
 | 
					    description: 'An ordered list of keys to use for restoring the cache if no cache hit occurred for key'
 | 
				
			||||||
    required: false
 | 
					    required: false
 | 
				
			||||||
 | 
					  update:
 | 
				
			||||||
 | 
					    description: 'If true, the cache will be updated if the key already exists'
 | 
				
			||||||
 | 
					    required: false
 | 
				
			||||||
outputs:
 | 
					outputs:
 | 
				
			||||||
  cache-hit:
 | 
					  cache-hit:
 | 
				
			||||||
    description: 'A boolean value to indicate an exact match was found for the primary key'
 | 
					    description: 'A boolean value to indicate an exact match was found for the primary key'
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							@ -6717,6 +6717,7 @@ var Inputs;
 | 
				
			|||||||
    Inputs["Key"] = "key";
 | 
					    Inputs["Key"] = "key";
 | 
				
			||||||
    Inputs["Path"] = "path";
 | 
					    Inputs["Path"] = "path";
 | 
				
			||||||
    Inputs["RestoreKeys"] = "restore-keys";
 | 
					    Inputs["RestoreKeys"] = "restore-keys";
 | 
				
			||||||
 | 
					    Inputs["Update"] = "update";
 | 
				
			||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
 | 
					})(Inputs = exports.Inputs || (exports.Inputs = {}));
 | 
				
			||||||
var Outputs;
 | 
					var Outputs;
 | 
				
			||||||
(function (Outputs) {
 | 
					(function (Outputs) {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										6
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							@ -6605,9 +6605,14 @@ function run() {
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (utils.isExactKeyMatch(primaryKey, state)) {
 | 
					            if (utils.isExactKeyMatch(primaryKey, state)) {
 | 
				
			||||||
 | 
					                if (core.getInput(constants_1.Inputs.Update) === "true") {
 | 
				
			||||||
 | 
					                    core.info(`Cache hit occurred on the primary key ${primaryKey}, but updates were enabled, so updating cache.`);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
                    core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
 | 
					                    core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
 | 
					            const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
 | 
				
			||||||
                required: true
 | 
					                required: true
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
@ -6802,6 +6807,7 @@ var Inputs;
 | 
				
			|||||||
    Inputs["Key"] = "key";
 | 
					    Inputs["Key"] = "key";
 | 
				
			||||||
    Inputs["Path"] = "path";
 | 
					    Inputs["Path"] = "path";
 | 
				
			||||||
    Inputs["RestoreKeys"] = "restore-keys";
 | 
					    Inputs["RestoreKeys"] = "restore-keys";
 | 
				
			||||||
 | 
					    Inputs["Update"] = "update";
 | 
				
			||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
 | 
					})(Inputs = exports.Inputs || (exports.Inputs = {}));
 | 
				
			||||||
var Outputs;
 | 
					var Outputs;
 | 
				
			||||||
(function (Outputs) {
 | 
					(function (Outputs) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,8 @@
 | 
				
			|||||||
export enum Inputs {
 | 
					export enum Inputs {
 | 
				
			||||||
    Key = "key",
 | 
					    Key = "key",
 | 
				
			||||||
    Path = "path",
 | 
					    Path = "path",
 | 
				
			||||||
    RestoreKeys = "restore-keys"
 | 
					    RestoreKeys = "restore-keys",
 | 
				
			||||||
 | 
					    Update = "update"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export enum Outputs {
 | 
					export enum Outputs {
 | 
				
			||||||
 | 
				
			|||||||
@ -25,11 +25,17 @@ async function run(): Promise<void> {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (utils.isExactKeyMatch(primaryKey, state)) {
 | 
					        if (utils.isExactKeyMatch(primaryKey, state)) {
 | 
				
			||||||
 | 
					            if (core.getInput(Inputs.Update) === "true") {
 | 
				
			||||||
 | 
					                core.info(
 | 
				
			||||||
 | 
					                    `Cache hit occurred on the primary key ${primaryKey}, but updates were enabled, so updating cache.`
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
                core.info(
 | 
					                core.info(
 | 
				
			||||||
                    `Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
 | 
					                    `Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const cachePaths = utils.getInputAsArray(Inputs.Path, {
 | 
					        const cachePaths = utils.getInputAsArray(Inputs.Path, {
 | 
				
			||||||
            required: true
 | 
					            required: true
 | 
				
			||||||
 | 
				
			|||||||
@ -13,11 +13,15 @@ interface CacheInput {
 | 
				
			|||||||
    path: string;
 | 
					    path: string;
 | 
				
			||||||
    key: string;
 | 
					    key: string;
 | 
				
			||||||
    restoreKeys?: string[];
 | 
					    restoreKeys?: string[];
 | 
				
			||||||
 | 
					    update?: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function setInputs(input: CacheInput): void {
 | 
					export function setInputs(input: CacheInput): void {
 | 
				
			||||||
    setInput(Inputs.Path, input.path);
 | 
					    setInput(Inputs.Path, input.path);
 | 
				
			||||||
    setInput(Inputs.Key, input.key);
 | 
					    setInput(Inputs.Key, input.key);
 | 
				
			||||||
 | 
					    input.update
 | 
				
			||||||
 | 
					        ? setInput(Inputs.Update, input.update)
 | 
				
			||||||
 | 
					        : setInput(Inputs.Update, "false");
 | 
				
			||||||
    input.restoreKeys &&
 | 
					    input.restoreKeys &&
 | 
				
			||||||
        setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
 | 
					        setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -25,5 +29,6 @@ export function setInputs(input: CacheInput): void {
 | 
				
			|||||||
export function clearInputs(): void {
 | 
					export function clearInputs(): void {
 | 
				
			||||||
    delete process.env[getInputName(Inputs.Path)];
 | 
					    delete process.env[getInputName(Inputs.Path)];
 | 
				
			||||||
    delete process.env[getInputName(Inputs.Key)];
 | 
					    delete process.env[getInputName(Inputs.Key)];
 | 
				
			||||||
 | 
					    delete process.env[getInputName(Inputs.Update)];
 | 
				
			||||||
    delete process.env[getInputName(Inputs.RestoreKeys)];
 | 
					    delete process.env[getInputName(Inputs.RestoreKeys)];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user