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:
Daz DeBoer 2021-11-05 06:54:31 -06:00
parent 3812292b26
commit 4e899835b3
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
7 changed files with 37 additions and 31 deletions

View file

@ -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
*/