mirror of
				https://github.com/gradle/gradle-build-action.git
				synced 2025-11-04 09:58:56 +08:00 
			
		
		
		
	Avoid failing job on any failure in post-action
Failures to store cache entries should not fail the action or the Job. This fix attempts to catch and log any unexpected errors that occur when saving cache entries. Fixes: #119 Fixes: #120
This commit is contained in:
		
							
								
								
									
										2
									
								
								dist/post/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/post/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										2
									
								
								dist/post/index.js.map
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/post/index.js.map
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										13
									
								
								src/post.ts
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/post.ts
									
									
									
									
									
								
							@@ -1,16 +1,25 @@
 | 
			
		||||
import * as core from '@actions/core'
 | 
			
		||||
import * as caches from './caches'
 | 
			
		||||
 | 
			
		||||
// Catch and log any unhandled exceptions.  These exceptions can leak out of the uploadChunk method in
 | 
			
		||||
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
 | 
			
		||||
// throw an uncaught exception.  Instead of failing this action, just warn.
 | 
			
		||||
process.on('uncaughtException', e => handleFailure(e))
 | 
			
		||||
 | 
			
		||||
// Invoked by GitHub Actions
 | 
			
		||||
export async function run(): Promise<void> {
 | 
			
		||||
    try {
 | 
			
		||||
        await caches.save()
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
        core.setFailed(String(error))
 | 
			
		||||
        handleFailure(error)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function handleFailure(error: unknown): void {
 | 
			
		||||
    core.warning(`Unhandled error saving cache - job will continue: ${error}`)
 | 
			
		||||
    if (error instanceof Error && error.stack) {
 | 
			
		||||
        core.info(error.stack)
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
run()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user