Truncate Gradle args when constructing cache key (#71)

Cache keys have a hard limit of 512 characters, so we need to ensure that we don't generate a key longer than this.

- Remove excess whitespace
- Truncate to 400 characters

Fixes #70
This commit is contained in:
Daz DeBoer 2021-08-24 12:46:48 -06:00 committed by GitHub
parent e0c2736e35
commit b3afdc78a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 13 deletions

17
src/cache-utils.ts Normal file
View file

@ -0,0 +1,17 @@
import * as path from 'path'
import * as glob from '@actions/glob'
export async function hashFiles(
baseDir: string,
patterns: string[] = ['**'],
followSymbolicLinks = false
): Promise<string | null> {
const combinedPatterns = patterns
.map(pattern => `${baseDir}${path.sep}${pattern}`)
.join('\n')
return glob.hashFiles(combinedPatterns, {followSymbolicLinks})
}
export function truncateArgs(args: string): string {
return args.trim().replace(/\s+/g, ' ').substr(0, 400)
}