mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-07 16:56:12 +02:00
Avoid failing build on distributions cache errors
- Warn and continue on failure to restore a Gradle distribution from cache - Warn and continue on failure to save a Gradle distribution to cache - Extract common functionality for consistent handling of cache failures Fixes #116
This commit is contained in:
parent
3812292b26
commit
4e899835b3
7 changed files with 37 additions and 31 deletions
|
@ -1,4 +1,5 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
import * as crypto from 'crypto'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
@ -39,6 +40,24 @@ export function hashFileNames(fileNames: string[]): string {
|
|||
return hashStrings(fileNames.map(x => x.replace(new RegExp(`\\${path.sep}`, 'g'), '/')))
|
||||
}
|
||||
|
||||
export function handleCacheFailure(error: unknown, message: string): void {
|
||||
if (error instanceof cache.ValidationError) {
|
||||
// Fail on cache validation errors
|
||||
throw error
|
||||
}
|
||||
if (error instanceof cache.ReserveCacheError) {
|
||||
// Reserve cache errors are expected if the artifact has been previously cached
|
||||
if (isCacheDebuggingEnabled()) {
|
||||
core.info(message)
|
||||
} else {
|
||||
core.debug(message)
|
||||
}
|
||||
} else {
|
||||
// Warn on all other errors
|
||||
core.warning(`${message}: ${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to delete a file or directory, waiting to allow locks to be released
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue