mirror of
				https://github.com/actions/cache.git
				synced 2025-11-04 10:14:02 +00:00 
			
		
		
		
	Saving state early to take care of all cases
This commit is contained in:
		
							parent
							
								
									8c4782cf33
								
							
						
					
					
						commit
						91d3f2deb0
					
				
							
								
								
									
										11
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							@ -48987,6 +48987,12 @@ function run() {
 | 
				
			|||||||
                required: true
 | 
					                required: true
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys);
 | 
					            const cacheKey = yield cache.restoreCache(cachePaths, primaryKey, restoreKeys);
 | 
				
			||||||
 | 
					            //Check if user wants to save cache despite of failure in any previous job
 | 
				
			||||||
 | 
					            const saveCache = core.getInput(constants_1.Inputs.SaveCacheOnAnyFailure);
 | 
				
			||||||
 | 
					            if (saveCache === "yes") {
 | 
				
			||||||
 | 
					                core.saveState(constants_1.State.SaveCache, saveCache);
 | 
				
			||||||
 | 
					                core.info(`Input save-cache-on-any-failure is set to yes, the cache will be saved despite of any failure in the build.`);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            if (!cacheKey) {
 | 
					            if (!cacheKey) {
 | 
				
			||||||
                if (core.getInput(constants_1.Inputs.StrictRestore) == "true") {
 | 
					                if (core.getInput(constants_1.Inputs.StrictRestore) == "true") {
 | 
				
			||||||
                    throw new Error(`Cache with the given input key ${primaryKey} is not found, hence exiting the workflow as the strict-restore requirement is not met.`);
 | 
					                    throw new Error(`Cache with the given input key ${primaryKey} is not found, hence exiting the workflow as the strict-restore requirement is not met.`);
 | 
				
			||||||
@ -49005,11 +49011,6 @@ function run() {
 | 
				
			|||||||
                throw new Error(`Restored cache key doesn't match the given input key ${primaryKey}, hence exiting the workflow as the strict-restore requirement is not met.`);
 | 
					                throw new Error(`Restored cache key doesn't match the given input key ${primaryKey}, hence exiting the workflow as the strict-restore requirement is not met.`);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            core.info(`Cache restored from key: ${cacheKey}`);
 | 
					            core.info(`Cache restored from key: ${cacheKey}`);
 | 
				
			||||||
            const saveCache = core.getInput(constants_1.Inputs.SaveCacheOnAnyFailure);
 | 
					 | 
				
			||||||
            if (saveCache === "yes") {
 | 
					 | 
				
			||||||
                core.saveState(constants_1.State.SaveCache, saveCache);
 | 
					 | 
				
			||||||
                core.info(`Input save-cache-on-any-failure is set to yes, the cache will be saved despite of any failure in the build.`);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        catch (error) {
 | 
					        catch (error) {
 | 
				
			||||||
            core.setFailed(error.message);
 | 
					            core.setFailed(error.message);
 | 
				
			||||||
 | 
				
			|||||||
@ -35,6 +35,15 @@ async function run(): Promise<void> {
 | 
				
			|||||||
            restoreKeys
 | 
					            restoreKeys
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Check if user wants to save cache despite of failure in any previous job
 | 
				
			||||||
 | 
					        const saveCache = core.getInput(Inputs.SaveCacheOnAnyFailure);
 | 
				
			||||||
 | 
					        if (saveCache === "yes") {
 | 
				
			||||||
 | 
					            core.saveState(State.SaveCache, saveCache);
 | 
				
			||||||
 | 
					            core.info(
 | 
				
			||||||
 | 
					                `Input save-cache-on-any-failure is set to yes, the cache will be saved despite of any failure in the build.`
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!cacheKey) {
 | 
					        if (!cacheKey) {
 | 
				
			||||||
            if (core.getInput(Inputs.StrictRestore) == "true") {
 | 
					            if (core.getInput(Inputs.StrictRestore) == "true") {
 | 
				
			||||||
                throw new Error(
 | 
					                throw new Error(
 | 
				
			||||||
@ -63,15 +72,6 @@ async function run(): Promise<void> {
 | 
				
			|||||||
            );
 | 
					            );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        core.info(`Cache restored from key: ${cacheKey}`);
 | 
					        core.info(`Cache restored from key: ${cacheKey}`);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        const saveCache = core.getInput(Inputs.SaveCacheOnAnyFailure);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (saveCache === "yes") {
 | 
					 | 
				
			||||||
            core.saveState(State.SaveCache, saveCache);
 | 
					 | 
				
			||||||
            core.info(
 | 
					 | 
				
			||||||
                `Input save-cache-on-any-failure is set to yes, the cache will be saved despite of any failure in the build.`
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    } catch (error: unknown) {
 | 
					    } catch (error: unknown) {
 | 
				
			||||||
        core.setFailed((error as Error).message);
 | 
					        core.setFailed((error as Error).message);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user