mirror of
https://github.com/gradle/actions.git
synced 2025-11-26 17:09:10 +08:00
Enable wrapper validation with setup-gradle action
This commit is contained in:
@@ -261,6 +261,10 @@ export class GradleExecutionConfig {
|
||||
}
|
||||
}
|
||||
|
||||
export function doValidateWrappers(): boolean {
|
||||
return getBooleanInput('validate-wrappers')
|
||||
}
|
||||
|
||||
// Internal parameters
|
||||
export function getJobMatrix(): string {
|
||||
return core.getInput('workflow-job-context')
|
||||
|
||||
@@ -9,7 +9,7 @@ import type {PullRequestEvent} from '@octokit/webhooks-types'
|
||||
import * as path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
import {PostActionJobFailure} from './errors'
|
||||
import {JobFailure} from './errors'
|
||||
import {DependencyGraphConfig, DependencyGraphOption, getGithubToken, getWorkspaceDirectory} from './configuration'
|
||||
|
||||
const DEPENDENCY_GRAPH_PREFIX = 'dependency-graph_'
|
||||
@@ -208,7 +208,7 @@ function markProcessed(dependencyGraphFile: string): void {
|
||||
|
||||
function warnOrFail(config: DependencyGraphConfig, option: String, error: unknown): void {
|
||||
if (!config.getDependencyGraphContinueOnFailure()) {
|
||||
throw new PostActionJobFailure(error)
|
||||
throw new JobFailure(error)
|
||||
}
|
||||
|
||||
core.warning(`Failed to ${option} dependency graph. Will continue.\n${String(error)}`)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
|
||||
export class PostActionJobFailure extends Error {
|
||||
export class JobFailure extends Error {
|
||||
constructor(error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
super(error.message)
|
||||
@@ -21,6 +21,8 @@ export function handleMainActionError(error: unknown): void {
|
||||
core.info(err.stack)
|
||||
}
|
||||
}
|
||||
} else if (error instanceof JobFailure) {
|
||||
core.setFailed(String(error)) // No stack trace for JobFailure: these are known errors
|
||||
} else {
|
||||
core.setFailed(String(error))
|
||||
if (error instanceof Error && error.stack) {
|
||||
@@ -30,7 +32,7 @@ export function handleMainActionError(error: unknown): void {
|
||||
}
|
||||
|
||||
export function handlePostActionError(error: unknown): void {
|
||||
if (error instanceof PostActionJobFailure) {
|
||||
if (error instanceof JobFailure) {
|
||||
core.setFailed(String(error))
|
||||
} else {
|
||||
core.warning(`Unhandled error in Gradle post-action - job will continue: ${error}`)
|
||||
|
||||
@@ -10,6 +10,8 @@ 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 {findInvalidWrapperJars} from './wrapper-validation/validate'
|
||||
import {JobFailure} from './errors'
|
||||
|
||||
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED'
|
||||
const USER_HOME = 'USER_HOME'
|
||||
@@ -96,3 +98,16 @@ async function determineUserHome(): Promise<string> {
|
||||
core.debug(`Determined user.home from java -version output: '${userHome}'`)
|
||||
return userHome
|
||||
}
|
||||
|
||||
export async function checkNoInvalidWrapperJars(rootDir = getWorkspaceDirectory()): Promise<void> {
|
||||
const allowedChecksums = process.env['ALLOWED_GRADLE_WRAPPER_CHECKSUMS']?.split(',') || []
|
||||
const result = await findInvalidWrapperJars(rootDir, 1, false, 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()}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
CacheConfig,
|
||||
DependencyGraphConfig,
|
||||
GradleExecutionConfig,
|
||||
doValidateWrappers,
|
||||
getActionId,
|
||||
setActionId
|
||||
} from '../configuration'
|
||||
@@ -25,6 +26,11 @@ export async function run(): Promise<void> {
|
||||
setActionId('gradle/actions/setup-gradle')
|
||||
}
|
||||
|
||||
// Check for invalid wrapper JARs if requested
|
||||
if (doValidateWrappers()) {
|
||||
await setupGradle.checkNoInvalidWrapperJars()
|
||||
}
|
||||
|
||||
// Configure Gradle environment (Gradle User Home)
|
||||
await setupGradle.setup(new CacheConfig(), new BuildScanConfig())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user