mirror of
https://github.com/gradle/actions.git
synced 2026-06-01 09:31:59 +00:00
0b8fa27eb1
This is necessary to avoid loading a cache entry from a different test, where the allowed wrapper checksums might have been cached, causing the wrapper validation to unexpectedly succeed.
42 lines
1.6 KiB
TypeScript
42 lines
1.6 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,
|
|
config.allowSnapshotWrappers(),
|
|
allowedChecksums,
|
|
previouslyValidatedChecksums
|
|
)
|
|
if (result.isValid()) {
|
|
await core.group('All Gradle Wrapper jars are valid', async () => {
|
|
core.debug(`Loaded previously validated checksums from cache: ${previouslyValidatedChecksums.join(', ')}`)
|
|
core.info(result.toDisplayString())
|
|
})
|
|
} else {
|
|
core.info(result.toDisplayString())
|
|
throw new JobFailure(
|
|
`At least one Gradle Wrapper Jar failed validation!\n See https://github.com/gradle/actions/blob/main/docs/wrapper-validation.md#validation-failures\n${result.toDisplayString()}`
|
|
)
|
|
}
|
|
|
|
// TODO: Should not be caching the ALLOWED_GRADLE_WRAPPER_CHECKSUMS as they should only apply to the present run
|
|
checksumCache.save(result.valid.map(wrapper => wrapper.checksum))
|
|
}
|