mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-07 16:56:12 +02:00
Extract cache key generation into common function
This commit is contained in:
parent
0ecbac99f3
commit
d7ed6d7e8d
3 changed files with 42 additions and 34 deletions
|
@ -1,8 +1,5 @@
|
|||
import * as core from '@actions/core'
|
||||
|
||||
export function truncateArgs(args: string): string {
|
||||
return args.trim().replace(/\s+/g, ' ').substr(0, 400)
|
||||
}
|
||||
import * as github from '@actions/github'
|
||||
|
||||
export function isCacheReadEnabled(cacheName: string): boolean {
|
||||
const configValue = getCacheEnabledValue(cacheName)
|
||||
|
@ -26,3 +23,29 @@ function getCacheEnabledValue(cacheName: string): string {
|
|||
`Invalid cache-enabled parameter '${configValue}'. Valid values are ['true', 'false', 'read-only']`
|
||||
)
|
||||
}
|
||||
|
||||
export function generateCacheKey(cacheName: string): CacheKey {
|
||||
const cacheKeySeed = process.env[`CACHE_KEY_SEED`] || ''
|
||||
const runnerOs = process.env[`RUNNER_OS`] || ''
|
||||
const cacheKeyPrefix = `${cacheKeySeed}${runnerOs}|${cacheName}|`
|
||||
|
||||
const args = truncateArgs(core.getInput('arguments'))
|
||||
const cacheKeyWithArgs = `${cacheKeyPrefix}${args}|`
|
||||
|
||||
const cacheKey = `${cacheKeyWithArgs}${github.context.sha}`
|
||||
return new CacheKey(cacheKey, [cacheKeyWithArgs, cacheKeyPrefix])
|
||||
}
|
||||
|
||||
function truncateArgs(args: string): string {
|
||||
return args.trim().replace(/\s+/g, ' ').substr(0, 400)
|
||||
}
|
||||
|
||||
export class CacheKey {
|
||||
key: string
|
||||
restoreKeys: string[]
|
||||
|
||||
constructor(key: string, restoreKeys: string[]) {
|
||||
this.key = key
|
||||
this.restoreKeys = restoreKeys
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue