Enable wrapper validation by default

- Add 'allow-snapshot-wrappers' input parameter
- Default 'validate-wrappers' to 'true'

Fixes #12
This commit is contained in:
daz
2024-07-31 20:38:10 -06:00
parent 7179909719
commit b644be617f
10 changed files with 85 additions and 23 deletions

View File

@@ -6,7 +6,7 @@ import {
CacheConfig,
DependencyGraphConfig,
GradleExecutionConfig,
doValidateWrappers,
WrapperValidationConfig,
getActionId,
setActionId
} from '../../configuration'
@@ -26,10 +26,7 @@ export async function run(): Promise<void> {
setActionId('gradle/actions/setup-gradle')
// Check for invalid wrapper JARs if requested
if (doValidateWrappers()) {
await setupGradle.checkNoInvalidWrapperJars()
}
await setupGradle.validateWrappers(new WrapperValidationConfig())
// Configure Gradle environment (Gradle User Home)
await setupGradle.setup(new CacheConfig(), new BuildScanConfig())

View File

@@ -357,8 +357,14 @@ export class GradleExecutionConfig {
}
}
export function doValidateWrappers(): boolean {
return getBooleanInput('validate-wrappers')
export class WrapperValidationConfig {
doValidateWrappers(): boolean {
return getBooleanInput('validate-wrappers')
}
allowSnapshotWrappers(): boolean {
return getBooleanInput('allow-snapshot-wrappers')
}
}
// Internal parameters

View File

@@ -10,7 +10,13 @@ import * as buildScan from './develocity/build-scan'
import {loadBuildResults, markBuildResultsProcessed} from './build-results'
import {CacheListener, generateCachingReport} from './caching/cache-reporting'
import {DaemonController} from './daemon-controller'
import {BuildScanConfig, CacheConfig, SummaryConfig, getWorkspaceDirectory} from './configuration'
import {
BuildScanConfig,
CacheConfig,
SummaryConfig,
WrapperValidationConfig,
getWorkspaceDirectory
} from './configuration'
import {findInvalidWrapperJars} from './wrapper-validation/validate'
import {JobFailure} from './errors'
@@ -117,9 +123,16 @@ async function determineUserHome(): Promise<string> {
return userHome
}
export async function checkNoInvalidWrapperJars(rootDir = getWorkspaceDirectory()): Promise<void> {
export async function validateWrappers(
config: WrapperValidationConfig,
rootDir = getWorkspaceDirectory()
): Promise<void> {
if (!config.doValidateWrappers()) {
return // Wrapper validation is disabled
}
const allowedChecksums = process.env['ALLOWED_GRADLE_WRAPPER_CHECKSUMS']?.split(',') || []
const result = await findInvalidWrapperJars(rootDir, 1, false, allowedChecksums)
const result = await findInvalidWrapperJars(rootDir, 0, config.allowSnapshotWrappers(), allowedChecksums)
if (result.isValid()) {
core.info(result.toDisplayString())
} else {

View File

@@ -55,15 +55,15 @@ export async function fetchUnknownChecksums(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(entry: any) => entry.wrapperChecksumUrl as string
)
console.log(`Fetching checksums for ${checksumUrls.length} versions`)
if (allowSnapshots) {
await addDistributionSnapshotChecksums(checksumUrls)
}
console.log(`Fetching checksums for ${checksumUrls.length} versions after snapshot check`)
const checksums = await Promise.all(checksumUrls.map(async (url: string) => {
// console.log(`Fetching checksum from ${url}`)
return httpGetText(url)
}))
const checksums = await Promise.all(
checksumUrls.map(async (url: string) => {
// console.log(`Fetching checksum from ${url}`)
return httpGetText(url)
})
)
return new Set(checksums)
}
@@ -83,10 +83,10 @@ export async function addDistributionSnapshotChecksums(checksumUrls: string[]):
// // Extract all wrapper checksum from the index page. These end in -wrapper.jar.sha256
// // Load the HTML into cheerio
const $ = cheerio.load(indexPage);
const $ = cheerio.load(indexPage)
// // Find all links ending with '-wrapper.jar.sha256'
const wrapperChecksumLinks = $('a[href$="-wrapper.jar.sha256"]');
const wrapperChecksumLinks = $('a[href$="-wrapper.jar.sha256"]')
// build the absolute URL for each wrapper checksum
wrapperChecksumLinks.each((index, element) => {