mirror of
https://github.com/gradle/actions.git
synced 2026-06-04 02:42:20 +00:00
b6395da67c
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
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
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,
|
|
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 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 {
|
|
core.info(result.toDisplayString())
|
|
throw new JobFailure(
|
|
`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))
|
|
}
|