mirror of
https://github.com/gradle/actions.git
synced 2025-04-20 09:49:19 +08:00
Improve error messages for min-wrapper-count
- Specific message when no wrappers are found - Better message when wrapper count is less than configured Fixes #284
This commit is contained in:
parent
d473db0899
commit
ac3aebda93
@ -18,15 +18,23 @@ export async function run(): Promise<void> {
|
|||||||
|
|
||||||
const result = await validate.findInvalidWrapperJars(
|
const result = await validate.findInvalidWrapperJars(
|
||||||
path.resolve('.'),
|
path.resolve('.'),
|
||||||
+core.getInput('min-wrapper-count'),
|
|
||||||
core.getInput('allow-snapshots') === 'true',
|
core.getInput('allow-snapshots') === 'true',
|
||||||
core.getInput('allow-checksums').split(',')
|
core.getInput('allow-checksums').split(',')
|
||||||
)
|
)
|
||||||
if (result.isValid()) {
|
if (result.isValid()) {
|
||||||
core.info(result.toDisplayString())
|
core.info(result.toDisplayString())
|
||||||
|
|
||||||
|
const minWrapperCount = +core.getInput('min-wrapper-count')
|
||||||
|
if (result.valid.length < minWrapperCount) {
|
||||||
|
const message =
|
||||||
|
result.valid.length === 0
|
||||||
|
? 'Wrapper validation failed: no Gradle Wrapper jars found. Did you forget to checkout the repository?'
|
||||||
|
: `Wrapper validation failed: expected at least ${minWrapperCount} Gradle Wrapper jars, but found ${result.valid.length}.`
|
||||||
|
core.setFailed(message)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
`Gradle Wrapper Validation Failed!\n See https://github.com/gradle/actions/blob/main/docs/wrapper-validation.md#reporting-failures\n${result.toDisplayString()}`
|
`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()}`
|
||||||
)
|
)
|
||||||
if (result.invalid.length > 0) {
|
if (result.invalid.length > 0) {
|
||||||
core.setOutput('failed-wrapper', `${result.invalid.map(w => w.path).join('|')}`)
|
core.setOutput('failed-wrapper', `${result.invalid.map(w => w.path).join('|')}`)
|
||||||
|
@ -5,7 +5,6 @@ import {resolve} from 'path'
|
|||||||
|
|
||||||
export async function findInvalidWrapperJars(
|
export async function findInvalidWrapperJars(
|
||||||
gitRepoRoot: string,
|
gitRepoRoot: string,
|
||||||
minWrapperCount: number,
|
|
||||||
allowSnapshots: boolean,
|
allowSnapshots: boolean,
|
||||||
allowedChecksums: string[],
|
allowedChecksums: string[],
|
||||||
previouslyValidatedChecksums: string[] = [],
|
previouslyValidatedChecksums: string[] = [],
|
||||||
@ -13,11 +12,6 @@ export async function findInvalidWrapperJars(
|
|||||||
): Promise<ValidationResult> {
|
): Promise<ValidationResult> {
|
||||||
const wrapperJars = await find.findWrapperJars(gitRepoRoot)
|
const wrapperJars = await find.findWrapperJars(gitRepoRoot)
|
||||||
const result = new ValidationResult([], [])
|
const result = new ValidationResult([], [])
|
||||||
if (wrapperJars.length < minWrapperCount) {
|
|
||||||
result.errors.push(
|
|
||||||
`Expected to find at least ${minWrapperCount} Gradle Wrapper JARs but got only ${wrapperJars.length}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (wrapperJars.length > 0) {
|
if (wrapperJars.length > 0) {
|
||||||
const notYetValidatedWrappers = []
|
const notYetValidatedWrappers = []
|
||||||
for (const wrapperJar of wrapperJars) {
|
for (const wrapperJar of wrapperJars) {
|
||||||
@ -54,7 +48,6 @@ export class ValidationResult {
|
|||||||
valid: WrapperJar[]
|
valid: WrapperJar[]
|
||||||
invalid: WrapperJar[]
|
invalid: WrapperJar[]
|
||||||
fetchedChecksums = false
|
fetchedChecksums = false
|
||||||
errors: string[] = []
|
|
||||||
|
|
||||||
constructor(valid: WrapperJar[], invalid: WrapperJar[]) {
|
constructor(valid: WrapperJar[], invalid: WrapperJar[]) {
|
||||||
this.valid = valid
|
this.valid = valid
|
||||||
@ -62,7 +55,7 @@ export class ValidationResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isValid(): boolean {
|
isValid(): boolean {
|
||||||
return this.invalid.length === 0 && this.errors.length === 0
|
return this.invalid.length === 0
|
||||||
}
|
}
|
||||||
|
|
||||||
toDisplayString(): string {
|
toDisplayString(): string {
|
||||||
@ -72,10 +65,6 @@ export class ValidationResult {
|
|||||||
this.invalid
|
this.invalid
|
||||||
)}`
|
)}`
|
||||||
}
|
}
|
||||||
if (this.errors.length > 0) {
|
|
||||||
if (displayString.length > 0) displayString += '\n'
|
|
||||||
displayString += `✗ Other validation errors:\n ${this.errors.join(`\n `)}`
|
|
||||||
}
|
|
||||||
if (this.valid.length > 0) {
|
if (this.valid.length > 0) {
|
||||||
if (displayString.length > 0) displayString += '\n'
|
if (displayString.length > 0) displayString += '\n'
|
||||||
displayString += `✓ Found known Gradle Wrapper JAR files:\n${ValidationResult.toDisplayList(this.valid)}`
|
displayString += `✓ Found known Gradle Wrapper JAR files:\n${ValidationResult.toDisplayList(this.valid)}`
|
||||||
|
@ -20,20 +20,19 @@ export async function validateWrappers(
|
|||||||
|
|
||||||
const result = await findInvalidWrapperJars(
|
const result = await findInvalidWrapperJars(
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
0,
|
|
||||||
config.allowSnapshotWrappers(),
|
config.allowSnapshotWrappers(),
|
||||||
allowedChecksums,
|
allowedChecksums,
|
||||||
previouslyValidatedChecksums
|
previouslyValidatedChecksums
|
||||||
)
|
)
|
||||||
if (result.isValid()) {
|
if (result.isValid()) {
|
||||||
await core.group('All Gradle Wrapper jars are valid', async () => {
|
await core.group('All Gradle Wrapper jars are valid', async () => {
|
||||||
core.info(`Loaded previously validated checksums from cache: ${previouslyValidatedChecksums.join(', ')}`)
|
core.debug(`Loaded previously validated checksums from cache: ${previouslyValidatedChecksums.join(', ')}`)
|
||||||
core.info(result.toDisplayString())
|
core.info(result.toDisplayString())
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
core.info(result.toDisplayString())
|
core.info(result.toDisplayString())
|
||||||
throw new JobFailure(
|
throw new JobFailure(
|
||||||
`Gradle Wrapper Validation Failed!\n See https://github.com/gradle/actions/blob/main/docs/wrapper-validation.md#validation-failures\n${result.toDisplayString()}`
|
`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()}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ const baseDir = path.resolve('./test/jest/wrapper-validation')
|
|||||||
const tmpDir = path.resolve('./test/jest/tmp')
|
const tmpDir = path.resolve('./test/jest/tmp')
|
||||||
|
|
||||||
test('succeeds if all found wrapper jars are valid', async () => {
|
test('succeeds if all found wrapper jars are valid', async () => {
|
||||||
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [
|
const result = await validate.findInvalidWrapperJars(baseDir, false, [
|
||||||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ test('succeeds if all found wrapper jars are valid', async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('succeeds if all found wrapper jars are previously valid', async () => {
|
test('succeeds if all found wrapper jars are previously valid', async () => {
|
||||||
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [], [
|
const result = await validate.findInvalidWrapperJars(baseDir, false, [], [
|
||||||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
|
||||||
'3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce'
|
'3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce'
|
||||||
])
|
])
|
||||||
@ -50,7 +50,6 @@ test('succeeds if all found wrapper jars are valid (and checksums are fetched fr
|
|||||||
const knownValidChecksums = new WrapperChecksums()
|
const knownValidChecksums = new WrapperChecksums()
|
||||||
const result = await validate.findInvalidWrapperJars(
|
const result = await validate.findInvalidWrapperJars(
|
||||||
baseDir,
|
baseDir,
|
||||||
1,
|
|
||||||
false,
|
false,
|
||||||
['e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'],
|
['e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'],
|
||||||
[],
|
[],
|
||||||
@ -71,7 +70,7 @@ test('succeeds if all found wrapper jars are valid (and checksums are fetched fr
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('fails if invalid wrapper jars are found', async () => {
|
test('fails if invalid wrapper jars are found', async () => {
|
||||||
const result = await validate.findInvalidWrapperJars(baseDir, 3, false, [])
|
const result = await validate.findInvalidWrapperJars(baseDir, false, [])
|
||||||
|
|
||||||
expect(result.isValid()).toBe(false)
|
expect(result.isValid()).toBe(false)
|
||||||
|
|
||||||
@ -102,26 +101,6 @@ test('fails if invalid wrapper jars are found', async () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('fails if not enough wrapper jars are found', async () => {
|
|
||||||
const result = await validate.findInvalidWrapperJars(baseDir, 4, false, [])
|
|
||||||
|
|
||||||
expect(result.isValid()).toBe(false)
|
|
||||||
|
|
||||||
expect(result.errors).toEqual([
|
|
||||||
'Expected to find at least 4 Gradle Wrapper JARs but got only 3'
|
|
||||||
])
|
|
||||||
|
|
||||||
expect(result.toDisplayString()).toBe(
|
|
||||||
'✗ Found unknown Gradle Wrapper JAR files:\n' +
|
|
||||||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradle-wrapper.jar\n' +
|
|
||||||
' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 data/invalid/gradlе-wrapper.jar\n' + // homoglyph
|
|
||||||
'✗ Other validation errors:\n' +
|
|
||||||
' Expected to find at least 4 Gradle Wrapper JARs but got only 3\n' +
|
|
||||||
'✓ Found known Gradle Wrapper JAR files:\n' +
|
|
||||||
' 3888c76faa032ea8394b8a54e04ce2227ab1f4be64f65d450f8509fe112d38ce data/valid/gradle-wrapper.jar'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('can save and load checksums', async () => {
|
test('can save and load checksums', async () => {
|
||||||
const cacheDir = path.join(tmpDir, 'wrapper-validation-cache')
|
const cacheDir = path.join(tmpDir, 'wrapper-validation-cache')
|
||||||
fs.rmSync(cacheDir, {recursive: true, force: true})
|
fs.rmSync(cacheDir, {recursive: true, force: true})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user