mirror of
https://github.com/gradle/actions.git
synced 2025-12-08 17:15:46 +08:00
Cache validated checksums for later executions
The most common case for validation will be that the wrapper jars are unchanged from a previous workflow run. In this case, we cache the validated wrapper checksums to minimise the work required on a subsequent run. Fixes #172
This commit is contained in:
@@ -1,17 +1,33 @@
|
||||
import * as core from '@actions/core'
|
||||
|
||||
import {WrapperValidationConfig} from '../configuration'
|
||||
import {ChecksumCache} from './cache'
|
||||
import {findInvalidWrapperJars} from './validate'
|
||||
import {JobFailure} from '../errors'
|
||||
|
||||
export async function validateWrappers(config: WrapperValidationConfig, workspaceRoot: string): Promise<void> {
|
||||
export async function validateWrappers(
|
||||
config: WrapperValidationConfig,
|
||||
workspaceRoot: string,
|
||||
gradleUserHome: string
|
||||
): Promise<void> {
|
||||
if (!config.doValidateWrappers()) {
|
||||
return // Wrapper validation is disabled
|
||||
}
|
||||
const checksumCache = new ChecksumCache(gradleUserHome)
|
||||
|
||||
const allowedChecksums = process.env['ALLOWED_GRADLE_WRAPPER_CHECKSUMS']?.split(',') || []
|
||||
const result = await findInvalidWrapperJars(workspaceRoot, 0, config.allowSnapshotWrappers(), allowedChecksums)
|
||||
const previouslyValidatedChecksums = checksumCache.load()
|
||||
|
||||
const result = await findInvalidWrapperJars(
|
||||
workspaceRoot,
|
||||
0,
|
||||
config.allowSnapshotWrappers(),
|
||||
allowedChecksums,
|
||||
previouslyValidatedChecksums
|
||||
)
|
||||
if (result.isValid()) {
|
||||
await core.group('All Gradle Wrapper jars are valid', async () => {
|
||||
core.info(`Loaded previously validated checksums from cache: ${previouslyValidatedChecksums.join(', ')}`)
|
||||
core.info(result.toDisplayString())
|
||||
})
|
||||
} else {
|
||||
@@ -20,4 +36,6 @@ export async function validateWrappers(config: WrapperValidationConfig, workspac
|
||||
`Gradle Wrapper Validation Failed!\n See https://github.com/gradle/actions/blob/main/docs/wrapper-validation.md#reporting-failures\n${result.toDisplayString()}`
|
||||
)
|
||||
}
|
||||
|
||||
checksumCache.save(result.valid.map(wrapper => wrapper.checksum))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user