mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-05 07:46:11 +02:00
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:
parent
e0c2736e35
commit
b3afdc78a7
6 changed files with 45 additions and 13 deletions
|
@ -4,7 +4,7 @@ import * as fs from 'fs'
|
|||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
|
||||
import * as crypto from './crypto-utils'
|
||||
import * as cacheUtils from './cache-utils'
|
||||
|
||||
import {
|
||||
inputCacheKeyGlobs,
|
||||
|
@ -35,10 +35,11 @@ export async function restoreCachedConfiguration(
|
|||
const cacheKeyPrefix = 'configuration|'
|
||||
|
||||
const args = core.getInput('arguments')
|
||||
const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|`
|
||||
const argsKey = cacheUtils.truncateArgs(args)
|
||||
const cacheKeyWithArgs = `${cacheKeyPrefix}${argsKey}|`
|
||||
|
||||
const cacheKeyGlobs = inputCacheKeyGlobs('configuration-cache-key')
|
||||
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
|
||||
const hash = await cacheUtils.hashFiles(rootDir, cacheKeyGlobs)
|
||||
const cacheKey = `${cacheKeyWithArgs}${hash}`
|
||||
|
||||
core.saveState(CONFIGURATION_CACHE_KEY, cacheKey)
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as os from 'os'
|
|||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
|
||||
import * as crypto from './crypto-utils'
|
||||
import * as cacheUtils from './cache-utils'
|
||||
|
||||
const DEPENDENCIES_CACHE_PATH = 'DEPENDENCIES_CACHE_PATH'
|
||||
const DEPENDENCIES_CACHE_KEY = 'DEPENDENCIES_CACHE_KEY'
|
||||
|
@ -24,10 +24,11 @@ export async function restoreCachedDependencies(
|
|||
const cacheKeyPrefix = 'dependencies|'
|
||||
|
||||
const args = core.getInput('arguments')
|
||||
const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|`
|
||||
const argsKey = cacheUtils.truncateArgs(args)
|
||||
const cacheKeyWithArgs = `${cacheKeyPrefix}${argsKey}|`
|
||||
|
||||
const cacheKeyGlobs = inputCacheKeyGlobs('dependencies-cache-key')
|
||||
const hash = await crypto.hashFiles(rootDir, cacheKeyGlobs)
|
||||
const hash = await cacheUtils.hashFiles(rootDir, cacheKeyGlobs)
|
||||
const cacheKey = `${cacheKeyWithArgs}${hash}`
|
||||
|
||||
core.saveState(DEPENDENCIES_CACHE_KEY, cacheKey)
|
||||
|
|
|
@ -11,3 +11,7 @@ export async function hashFiles(
|
|||
.join('\n')
|
||||
return glob.hashFiles(combinedPatterns, {followSymbolicLinks})
|
||||
}
|
||||
|
||||
export function truncateArgs(args: string): string {
|
||||
return args.trim().replace(/\s+/g, ' ').substr(0, 400)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue