mirror of
				https://github.com/actions/cache.git
				synced 2025-11-04 03:04:01 +00:00 
			
		
		
		
	Add check-only mode
This commit is contained in:
		
							parent
							
								
									d33b5077b5
								
							
						
					
					
						commit
						4f2da0b64b
					
				
							
								
								
									
										19934
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19934
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										19916
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19916
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -1,7 +1,8 @@
 | 
				
			|||||||
export enum Inputs {
 | 
					export enum Inputs {
 | 
				
			||||||
    Key = "key",
 | 
					    Key = "key",
 | 
				
			||||||
    Path = "path",
 | 
					    Path = "path",
 | 
				
			||||||
    RestoreKeys = "restore-keys"
 | 
					    RestoreKeys = "restore-keys",
 | 
				
			||||||
 | 
					    OnlyCheckKey = "only-check-key"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export enum Outputs {
 | 
					export enum Outputs {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,6 @@
 | 
				
			|||||||
import * as cache from "@actions/cache";
 | 
					import * as cache from "@actions/cache";
 | 
				
			||||||
 | 
					import { getCacheEntry } from "@actions/cache/lib/internal/cacheHttpClient";
 | 
				
			||||||
 | 
					import { getCompressionMethod } from "@actions/cache/lib/internal/cacheUtils";
 | 
				
			||||||
import * as core from "@actions/core";
 | 
					import * as core from "@actions/core";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Events, Inputs, State } from "./constants";
 | 
					import { Events, Inputs, State } from "./constants";
 | 
				
			||||||
@ -23,8 +25,22 @@ async function run(): Promise<void> {
 | 
				
			|||||||
        const cachePaths = utils.getInputAsArray(Inputs.Path, {
 | 
					        const cachePaths = utils.getInputAsArray(Inputs.Path, {
 | 
				
			||||||
            required: true
 | 
					            required: true
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					        const onlyCheck = utils.getInputAsBool(Inputs.OnlyCheckKey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					            if (onlyCheck) {
 | 
				
			||||||
 | 
					                const entry = await getCacheEntry([primaryKey], cachePaths, {
 | 
				
			||||||
 | 
					                    compressionMethod: await getCompressionMethod()
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (entry && entry.archiveLocation) {
 | 
				
			||||||
 | 
					                    core.info(`Cache found for key: ${primaryKey}`);
 | 
				
			||||||
 | 
					                    utils.setCacheHitOutput(true);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    core.info(`Cache not found for key: ${primaryKey}`);
 | 
				
			||||||
 | 
					                    utils.setCacheHitOutput(false);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
                const cacheKey = await cache.restoreCache(
 | 
					                const cacheKey = await cache.restoreCache(
 | 
				
			||||||
                    cachePaths,
 | 
					                    cachePaths,
 | 
				
			||||||
                    primaryKey,
 | 
					                    primaryKey,
 | 
				
			||||||
@ -43,10 +59,14 @@ async function run(): Promise<void> {
 | 
				
			|||||||
                // Store the matched cache key
 | 
					                // Store the matched cache key
 | 
				
			||||||
                utils.setCacheState(cacheKey);
 | 
					                utils.setCacheState(cacheKey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
 | 
					                const isExactKeyMatch = utils.isExactKeyMatch(
 | 
				
			||||||
 | 
					                    primaryKey,
 | 
				
			||||||
 | 
					                    cacheKey
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
                utils.setCacheHitOutput(isExactKeyMatch);
 | 
					                utils.setCacheHitOutput(isExactKeyMatch);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                core.info(`Cache restored from key: ${cacheKey}`);
 | 
					                core.info(`Cache restored from key: ${cacheKey}`);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
            if (error.name === cache.ValidationError.name) {
 | 
					            if (error.name === cache.ValidationError.name) {
 | 
				
			||||||
                throw error;
 | 
					                throw error;
 | 
				
			||||||
 | 
				
			|||||||
@ -56,3 +56,10 @@ export function getInputAsArray(
 | 
				
			|||||||
        .map(s => s.trim())
 | 
					        .map(s => s.trim())
 | 
				
			||||||
        .filter(x => x !== "");
 | 
					        .filter(x => x !== "");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function getInputAsBool(
 | 
				
			||||||
 | 
					    name: string,
 | 
				
			||||||
 | 
					    options?: core.InputOptions
 | 
				
			||||||
 | 
					): boolean {
 | 
				
			||||||
 | 
					    return core.getInput(name, options) === "true";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user