mirror of
https://github.com/gradle/actions.git
synced 2025-11-26 17:09:10 +08:00
Enable wrapper validation by default
- Add 'allow-snapshot-wrappers' input parameter - Default 'validate-wrappers' to 'true' Fixes #12
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user