Move wrapper-validation into common setup code

This commit is contained in:
daz 2024-08-01 08:53:37 -06:00
parent b644be617f
commit ce4c3a6c5e
No known key found for this signature in database
4 changed files with 35 additions and 28 deletions

View File

@ -10,7 +10,8 @@ import {
DependencyGraphConfig, DependencyGraphConfig,
DependencyGraphOption, DependencyGraphOption,
GradleExecutionConfig, GradleExecutionConfig,
setActionId setActionId,
WrapperValidationConfig
} from '../../configuration' } from '../../configuration'
import {saveDeprecationState} from '../../deprecation-collector' import {saveDeprecationState} from '../../deprecation-collector'
import {handleMainActionError} from '../../errors' import {handleMainActionError} from '../../errors'
@ -23,7 +24,7 @@ export async function run(): Promise<void> {
setActionId('gradle/actions/dependency-submission') setActionId('gradle/actions/dependency-submission')
// Configure Gradle environment (Gradle User Home) // Configure Gradle environment (Gradle User Home)
await setupGradle.setup(new CacheConfig(), new BuildScanConfig()) await setupGradle.setup(new CacheConfig(), new BuildScanConfig(), new WrapperValidationConfig())
// Capture the enabled state of dependency-graph // Capture the enabled state of dependency-graph
const originallyEnabled = process.env['GITHUB_DEPENDENCY_GRAPH_ENABLED'] const originallyEnabled = process.env['GITHUB_DEPENDENCY_GRAPH_ENABLED']

View File

@ -26,10 +26,8 @@ export async function run(): Promise<void> {
setActionId('gradle/actions/setup-gradle') setActionId('gradle/actions/setup-gradle')
await setupGradle.validateWrappers(new WrapperValidationConfig())
// Configure Gradle environment (Gradle User Home) // Configure Gradle environment (Gradle User Home)
await setupGradle.setup(new CacheConfig(), new BuildScanConfig()) await setupGradle.setup(new CacheConfig(), new BuildScanConfig(), new WrapperValidationConfig())
// Configure the dependency graph submission // Configure the dependency graph submission
await dependencyGraph.setup(new DependencyGraphConfig()) await dependencyGraph.setup(new DependencyGraphConfig())

View File

@ -17,15 +17,18 @@ import {
WrapperValidationConfig, WrapperValidationConfig,
getWorkspaceDirectory getWorkspaceDirectory
} from './configuration' } from './configuration'
import {findInvalidWrapperJars} from './wrapper-validation/validate' import * as wrapperValidator from './wrapper-validation/wrapper-validator'
import {JobFailure} from './errors'
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED' const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED'
const USER_HOME = 'USER_HOME' const USER_HOME = 'USER_HOME'
const GRADLE_USER_HOME = 'GRADLE_USER_HOME' const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
const CACHE_LISTENER = 'CACHE_LISTENER' const CACHE_LISTENER = 'CACHE_LISTENER'
export async function setup(cacheConfig: CacheConfig, buildScanConfig: BuildScanConfig): Promise<boolean> { export async function setup(
cacheConfig: CacheConfig,
buildScanConfig: BuildScanConfig,
wrapperValidationConfig: WrapperValidationConfig
): Promise<boolean> {
const userHome = await determineUserHome() const userHome = await determineUserHome()
const gradleUserHome = await determineGradleUserHome() const gradleUserHome = await determineGradleUserHome()
@ -43,6 +46,8 @@ export async function setup(cacheConfig: CacheConfig, buildScanConfig: BuildScan
core.saveState(USER_HOME, userHome) core.saveState(USER_HOME, userHome)
core.saveState(GRADLE_USER_HOME, gradleUserHome) core.saveState(GRADLE_USER_HOME, gradleUserHome)
await wrapperValidator.validateWrappers(wrapperValidationConfig, getWorkspaceDirectory())
const cacheListener = new CacheListener() const cacheListener = new CacheListener()
await caches.restore(userHome, gradleUserHome, cacheListener, cacheConfig) await caches.restore(userHome, gradleUserHome, cacheListener, cacheConfig)
@ -122,23 +127,3 @@ async function determineUserHome(): Promise<string> {
core.debug(`Determined user.home from java -version output: '${userHome}'`) core.debug(`Determined user.home from java -version output: '${userHome}'`)
return userHome return userHome
} }
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, 0, config.allowSnapshotWrappers(), allowedChecksums)
if (result.isValid()) {
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()}`
)
}
}

View File

@ -0,0 +1,23 @@
import * as core from '@actions/core'
import {WrapperValidationConfig} from '../configuration'
import {findInvalidWrapperJars} from './validate'
import {JobFailure} from '../errors'
export async function validateWrappers(config: WrapperValidationConfig, workspaceRoot: string): Promise<void> {
if (!config.doValidateWrappers()) {
return // Wrapper validation is disabled
}
const allowedChecksums = process.env['ALLOWED_GRADLE_WRAPPER_CHECKSUMS']?.split(',') || []
const result = await findInvalidWrapperJars(workspaceRoot, 0, config.allowSnapshotWrappers(), allowedChecksums)
if (result.isValid()) {
await core.group('All Gradle Wrapper jars are valid', async () => {
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()}`
)
}
}