mirror of
				https://github.com/actions/cache.git
				synced 2025-10-31 07:16:24 +07:00 
			
		
		
		
	Apply workaround for earlyExit
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/save.ts
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/save.ts
									
									
									
									
									
								
							| @ -1,10 +1,3 @@ | ||||
| import saveImpl from "./saveImpl"; | ||||
| import { StateProvider } from "./stateProvider"; | ||||
| import { saveRun } from "./saveImpl"; | ||||
|  | ||||
| async function run(): Promise<void> { | ||||
|     await saveImpl(new StateProvider()); | ||||
| } | ||||
|  | ||||
| run(); | ||||
|  | ||||
| export default run; | ||||
| saveRun(true); | ||||
|  | ||||
| @ -2,7 +2,11 @@ import * as cache from "@actions/cache"; | ||||
| import * as core from "@actions/core"; | ||||
|  | ||||
| import { Events, Inputs, State } from "./constants"; | ||||
| import { IStateProvider } from "./stateProvider"; | ||||
| import { | ||||
|     IStateProvider, | ||||
|     NullStateProvider, | ||||
|     StateProvider | ||||
| } from "./stateProvider"; | ||||
| import * as utils from "./utils/actionUtils"; | ||||
|  | ||||
| // Catch and log any unhandled exceptions.  These exceptions can leak out of the uploadChunk method in | ||||
| @ -10,7 +14,7 @@ import * as utils from "./utils/actionUtils"; | ||||
| // throw an uncaught exception.  Instead of failing this action, just warn. | ||||
| process.on("uncaughtException", e => utils.logWarning(e.message)); | ||||
|  | ||||
| async function saveImpl(stateProvider: IStateProvider): Promise<number | void> { | ||||
| export async function saveImpl(stateProvider: IStateProvider): Promise<number | void> { | ||||
|     let cacheId = -1; | ||||
|     try { | ||||
|         if (!utils.isCacheFeatureAvailable()) { | ||||
| @ -72,4 +76,46 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> { | ||||
|     return cacheId; | ||||
| } | ||||
|  | ||||
| export default saveImpl; | ||||
| export async function saveOnlyRun(earlyExit?: boolean | undefined): Promise<void> { | ||||
|     try { | ||||
|         const cacheId = await saveImpl(new NullStateProvider()); | ||||
|         if (cacheId === -1) { | ||||
|             core.warning(`Cache save failed.`); | ||||
|         } | ||||
|     } catch (err) { | ||||
|         console.error(err); | ||||
|         if (earlyExit) { | ||||
|             process.exit(1); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // node will stay alive if any promises are not resolved, | ||||
|     // which is a possibility if HTTP requests are dangling | ||||
|     // due to retries or timeouts. We know that if we got here | ||||
|     // that all promises that we care about have successfully | ||||
|     // resolved, so simply exit with success. | ||||
|     if (earlyExit) { | ||||
|         process.exit(0); | ||||
|     } | ||||
| } | ||||
|  | ||||
| export async function saveRun(earlyExit?: boolean | undefined): Promise<void> { | ||||
|     try { | ||||
|         await saveImpl(new StateProvider()); | ||||
|     } catch (err) { | ||||
|         console.error(err); | ||||
|         if (earlyExit) { | ||||
|             process.exit(1); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // node will stay alive if any promises are not resolved, | ||||
|     // which is a possibility if HTTP requests are dangling | ||||
|     // due to retries or timeouts. We know that if we got here | ||||
|     // that all promises that we care about have successfully | ||||
|     // resolved, so simply exit with success. | ||||
|     if (earlyExit) { | ||||
|         process.exit(0); | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -1,15 +1,3 @@ | ||||
| import * as core from "@actions/core"; | ||||
| import { saveOnlyRun } from "./saveImpl"; | ||||
|  | ||||
| import saveImpl from "./saveImpl"; | ||||
| import { NullStateProvider } from "./stateProvider"; | ||||
|  | ||||
| async function run(): Promise<void> { | ||||
|     const cacheId = await saveImpl(new NullStateProvider()); | ||||
|     if (cacheId === -1) { | ||||
|         core.warning(`Cache save failed.`); | ||||
|     } | ||||
| } | ||||
|  | ||||
| run(); | ||||
|  | ||||
| export default run; | ||||
| saveOnlyRun(true); | ||||
		Reference in New Issue
	
	Block a user
	 Tatyana Kostromskaya
					Tatyana Kostromskaya