Some checks are pending
Verify generated outputs / check (push) Waiting to run
Test different action inputs / action-inputs (macos-latest) (push) Waiting to run
Test different action inputs / action-inputs (ubuntu-latest) (push) Waiting to run
Test different action inputs / action-inputs (windows-latest) (push) Waiting to run
Test caching configuration / seed-build (macos-latest) (push) Waiting to run
Test caching configuration / seed-build (ubuntu-latest) (push) Waiting to run
Test caching configuration / seed-build (windows-latest) (push) Waiting to run
Test caching configuration / verify-build (macos-latest) (push) Blocked by required conditions
Test caching configuration / verify-build (ubuntu-latest) (push) Blocked by required conditions
Test caching configuration / verify-build (windows-latest) (push) Blocked by required conditions
Test caching configuration / cache-disabled (macos-latest) (push) Waiting to run
Test caching configuration / cache-disabled (ubuntu-latest) (push) Waiting to run
Test caching configuration / cache-disabled (windows-latest) (push) Waiting to run
Test caching configuration / cache-disabled-pre-existing-gradle-home (push) Waiting to run
Test caching configuration / seed-build-write-only (macos-latest) (push) Waiting to run
Test caching configuration / seed-build-write-only (ubuntu-latest) (push) Waiting to run
Test caching configuration / seed-build-write-only (windows-latest) (push) Waiting to run
Test caching configuration / verify-write-only-build (macos-latest) (push) Blocked by required conditions
Test caching configuration / verify-write-only-build (ubuntu-latest) (push) Blocked by required conditions
Test caching configuration / verify-write-only-build (windows-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / seed-build-groovy (macos-latest) (push) Waiting to run
Test save/restore configuration-cache state / seed-build-groovy (ubuntu-latest) (push) Waiting to run
Test save/restore configuration-cache state / seed-build-groovy (windows-latest) (push) Waiting to run
Test save/restore configuration-cache state / configuration-cache-groovy (macos-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / configuration-cache-groovy (ubuntu-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / configuration-cache-groovy (windows-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / no-extracted-cache-entries-restored (macos-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / no-extracted-cache-entries-restored (ubuntu-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / no-extracted-cache-entries-restored (windows-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / seed-build-kotlin (macos-latest) (push) Waiting to run
Test save/restore configuration-cache state / seed-build-kotlin (ubuntu-latest) (push) Waiting to run
Test save/restore configuration-cache state / seed-build-kotlin (windows-latest) (push) Waiting to run
Test save/restore configuration-cache state / modify-build-kotlin (macos-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / modify-build-kotlin (ubuntu-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / modify-build-kotlin (windows-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / configuration-cache-kotlin (macos-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / configuration-cache-kotlin (ubuntu-latest) (push) Blocked by required conditions
Test save/restore configuration-cache state / configuration-cache-kotlin (windows-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / seed-build (macos-latest) (push) Waiting to run
Test save/restore Gradle Home directory / seed-build (ubuntu-latest) (push) Waiting to run
Test save/restore Gradle Home directory / seed-build (windows-latest) (push) Waiting to run
Test save/restore Gradle Home directory / dependencies-cache (macos-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / dependencies-cache (ubuntu-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / dependencies-cache (windows-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / build-cache (macos-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / build-cache (ubuntu-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / build-cache (windows-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / no-extracted-cache-entries-restored (macos-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / no-extracted-cache-entries-restored (ubuntu-latest) (push) Blocked by required conditions
Test save/restore Gradle Home directory / no-extracted-cache-entries-restored (windows-latest) (push) Blocked by required conditions
Test save/restore java toolchains / seed-build (macos-latest) (push) Waiting to run
Test save/restore java toolchains / seed-build (ubuntu-latest) (push) Waiting to run
Test save/restore java toolchains / seed-build (windows-latest) (push) Waiting to run
Test save/restore java toolchains / toolchain-cache (macos-latest) (push) Blocked by required conditions
Test save/restore java toolchains / toolchain-cache (ubuntu-latest) (push) Blocked by required conditions
Test save/restore java toolchains / toolchain-cache (windows-latest) (push) Blocked by required conditions
Test save/restore Gradle state with direct execution / seed-build (macos-latest) (push) Waiting to run
Test save/restore Gradle state with direct execution / seed-build (ubuntu-latest) (push) Waiting to run
Test save/restore Gradle state with direct execution / seed-build (windows-latest) (push) Waiting to run
Test save/restore Gradle state with direct execution / verify-build (macos-latest) (push) Blocked by required conditions
Test save/restore Gradle state with direct execution / verify-build (ubuntu-latest) (push) Blocked by required conditions
Test save/restore Gradle state with direct execution / verify-build (windows-latest) (push) Blocked by required conditions
Test Gradle execution / gradle-execution (macos-latest) (push) Waiting to run
Test Gradle execution / gradle-execution (ubuntu-latest) (push) Waiting to run
Test Gradle execution / gradle-execution (windows-latest, .bat) (push) Waiting to run
Test Gradle execution / gradle-versions (-gradle-4, 4.10.3, macos-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (-gradle-4, 4.10.3, ubuntu-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (-gradle-4, 4.10.3, windows-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (-gradle-5, 5.6.4, macos-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (-gradle-5, 5.6.4, ubuntu-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (-gradle-5, 5.6.4, windows-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (6.9, macos-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (6.9, ubuntu-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (6.9, windows-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (7.3, macos-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (7.3, ubuntu-latest) (push) Waiting to run
Test Gradle execution / gradle-versions (7.3, windows-latest) (push) Waiting to run
Test caching with a custom GRADLE_USER_HOME / seed-build (macos-latest) (push) Waiting to run
Test caching with a custom GRADLE_USER_HOME / seed-build (ubuntu-latest) (push) Waiting to run
Test caching with a custom GRADLE_USER_HOME / seed-build (windows-latest) (push) Waiting to run
Test caching with a custom GRADLE_USER_HOME / dependencies-cache (macos-latest) (push) Blocked by required conditions
Test caching with a custom GRADLE_USER_HOME / dependencies-cache (ubuntu-latest) (push) Blocked by required conditions
Test caching with a custom GRADLE_USER_HOME / dependencies-cache (windows-latest) (push) Blocked by required conditions
Test caching with a custom GRADLE_USER_HOME / build-cache (macos-latest) (push) Blocked by required conditions
Test caching with a custom GRADLE_USER_HOME / build-cache (ubuntu-latest) (push) Blocked by required conditions
Test caching with a custom GRADLE_USER_HOME / build-cache (windows-latest) (push) Blocked by required conditions
Test provision different Gradle versions / provision-gradle (macos-latest) (push) Waiting to run
Test provision different Gradle versions / provision-gradle (ubuntu-latest) (push) Waiting to run
Test provision different Gradle versions / provision-gradle (windows-latest, .bat) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (-gradle-4, 4.10.3, macos-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (-gradle-4, 4.10.3, ubuntu-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (-gradle-4, 4.10.3, windows-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (-gradle-5, 5.6.4, macos-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (-gradle-5, 5.6.4, ubuntu-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (-gradle-5, 5.6.4, windows-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (6.9, macos-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (6.9, ubuntu-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (6.9, windows-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (7.3, macos-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (7.3, ubuntu-latest) (push) Waiting to run
Test provision different Gradle versions / gradle-versions (7.3, windows-latest) (push) Waiting to run
Test caching with Gradle Plugin project using TestKit / seed-build (macos-latest) (push) Waiting to run
Test caching with Gradle Plugin project using TestKit / seed-build (ubuntu-latest) (push) Waiting to run
Test caching with Gradle Plugin project using TestKit / seed-build (windows-latest) (push) Waiting to run
Test caching with Gradle Plugin project using TestKit / verify-build (macos-latest) (push) Blocked by required conditions
Test caching with Gradle Plugin project using TestKit / verify-build (ubuntu-latest) (push) Blocked by required conditions
Test caching with Gradle Plugin project using TestKit / verify-build (windows-latest) (push) Blocked by required conditions
Test caching with Kotlin DSL / seed-build (macos-latest) (push) Waiting to run
Test caching with Kotlin DSL / seed-build (ubuntu-latest) (push) Waiting to run
Test caching with Kotlin DSL / seed-build (windows-latest) (push) Waiting to run
Test caching with Kotlin DSL / verify-build (macos-latest) (push) Blocked by required conditions
Test caching with Kotlin DSL / verify-build (ubuntu-latest) (push) Blocked by required conditions
Test caching with Kotlin DSL / verify-build (windows-latest) (push) Blocked by required conditions
139 lines
4.4 KiB
TypeScript
139 lines
4.4 KiB
TypeScript
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'
|
|
|
|
import {CacheEntryListener} from './cache-reporting'
|
|
|
|
const JOB_CONTEXT_PARAMETER = 'workflow-job-context'
|
|
const CACHE_DISABLED_PARAMETER = 'cache-disabled'
|
|
const CACHE_READONLY_PARAMETER = 'cache-read-only'
|
|
const CACHE_WRITEONLY_PARAMETER = 'cache-write-only'
|
|
const CACHE_DEBUG_VAR = 'GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED'
|
|
const CACHE_PREFIX_VAR = 'GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX'
|
|
|
|
export function isCacheDisabled(): boolean {
|
|
return core.getBooleanInput(CACHE_DISABLED_PARAMETER)
|
|
}
|
|
|
|
export function isCacheReadOnly(): boolean {
|
|
return core.getBooleanInput(CACHE_READONLY_PARAMETER)
|
|
}
|
|
|
|
export function isCacheWriteOnly(): boolean {
|
|
return core.getBooleanInput(CACHE_WRITEONLY_PARAMETER)
|
|
}
|
|
|
|
export function isCacheDebuggingEnabled(): boolean {
|
|
return process.env[CACHE_DEBUG_VAR] ? true : false
|
|
}
|
|
|
|
export function getCacheKeyPrefix(): string {
|
|
// Prefix can be used to force change all cache keys (defaults to cache protocol version)
|
|
return process.env[CACHE_PREFIX_VAR] || ''
|
|
}
|
|
|
|
export function determineJobContext(): string {
|
|
// By default, we hash the full `matrix` data for the run, to uniquely identify this job invocation
|
|
// The only way we can obtain the `matrix` data is via the `workflow-job-context` parameter in action.yml.
|
|
const workflowJobContext = core.getInput(JOB_CONTEXT_PARAMETER)
|
|
return hashStrings([workflowJobContext])
|
|
}
|
|
|
|
export function hashFileNames(fileNames: string[]): string {
|
|
return hashStrings(fileNames.map(x => x.replace(new RegExp(`\\${path.sep}`, 'g'), '/')))
|
|
}
|
|
|
|
export function hashStrings(values: string[]): string {
|
|
const hash = crypto.createHash('md5')
|
|
for (const value of values) {
|
|
hash.update(value)
|
|
}
|
|
return hash.digest('hex')
|
|
}
|
|
|
|
export async function restoreCache(
|
|
cachePath: string[],
|
|
cacheKey: string,
|
|
cacheRestoreKeys: string[],
|
|
listener: CacheEntryListener
|
|
): Promise<cache.CacheEntry | undefined> {
|
|
listener.markRequested(cacheKey, cacheRestoreKeys)
|
|
try {
|
|
const restoredEntry = await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys)
|
|
if (restoredEntry !== undefined) {
|
|
listener.markRestored(restoredEntry.key, restoredEntry.size)
|
|
}
|
|
return restoredEntry
|
|
} catch (error) {
|
|
handleCacheFailure(error, `Failed to restore ${cacheKey}`)
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
export async function saveCache(cachePath: string[], cacheKey: string, listener: CacheEntryListener): Promise<void> {
|
|
try {
|
|
const savedEntry = await cache.saveCache(cachePath, cacheKey)
|
|
listener.markSaved(savedEntry.key, savedEntry.size)
|
|
} catch (error) {
|
|
if (error instanceof cache.ReserveCacheError) {
|
|
listener.markAlreadyExists(cacheKey)
|
|
}
|
|
handleCacheFailure(error, `Failed to save cache entry ${cacheKey}`)
|
|
}
|
|
}
|
|
|
|
export function cacheDebug(message: string): void {
|
|
if (isCacheDebuggingEnabled()) {
|
|
core.info(message)
|
|
} else {
|
|
core.debug(message)
|
|
}
|
|
}
|
|
|
|
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
|
|
core.info(`${message}: ${error}`)
|
|
} else {
|
|
// Warn on all other errors
|
|
core.warning(`${message}: ${error}`)
|
|
if (error instanceof Error && error.stack) {
|
|
cacheDebug(error.stack)
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Attempt to delete a file or directory, waiting to allow locks to be released
|
|
*/
|
|
export async function tryDelete(file: string): Promise<void> {
|
|
const stat = fs.lstatSync(file)
|
|
for (let count = 0; count < 3; count++) {
|
|
try {
|
|
if (stat.isDirectory()) {
|
|
fs.rmdirSync(file, {recursive: true})
|
|
} else {
|
|
fs.unlinkSync(file)
|
|
}
|
|
return
|
|
} catch (error) {
|
|
if (count === 2) {
|
|
throw error
|
|
} else {
|
|
core.warning(String(error))
|
|
await delay(1000)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async function delay(ms: number): Promise<void> {
|
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
}
|