Better reporting of invalid wrapper jars

Signed-off-by: Paul Merlin <paul@gradle.com>
This commit is contained in:
Paul Merlin 2020-01-06 13:50:19 +01:00
parent 73443bf726
commit 89c35dd18b
4 changed files with 32 additions and 7 deletions

View file

@ -9,6 +9,9 @@ test('validates wrapper jars', async () => {
)
expect(invalidWrapperJars.length).toBe(1)
expect(invalidWrapperJars[0]).toEqual(
'__tests__/data/invalid/gradle-wrapper.jar'
new validate.InvalidWrapperJar(
'__tests__/data/invalid/gradle-wrapper.jar',
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
)
)
})

12
dist/index.js vendored
View file

@ -344,7 +344,8 @@ function run() {
const allowChecksums = core.getInput('allow-checksums').split(',');
const invalidWrapperJars = yield validate.findInvalidWrapperJars(path.resolve('.'), allowSnapshots, allowChecksums);
if (invalidWrapperJars.length > 0) {
core.setFailed(`Invalid wrapper jars ${invalidWrapperJars}`);
const list = invalidWrapperJars.map(invalid => `${invalid.checksum} ${invalid.path}`);
core.setFailed(`Found unknown Gradle Wrapper JAR files\n${list.join('\n- ')}`);
}
}
catch (error) {
@ -953,7 +954,7 @@ function findInvalidWrapperJars(gitRepoRoot, allowSnapshots, allowChecksums) {
for (const wrapperJar of wrapperJars) {
const sha = yield hash.sha256File(wrapperJar);
if (!validChecksums.includes(sha)) {
invalidWrapperJars.push(wrapperJar);
invalidWrapperJars.push(new InvalidWrapperJar(wrapperJar, sha));
}
}
return invalidWrapperJars;
@ -962,6 +963,13 @@ function findInvalidWrapperJars(gitRepoRoot, allowSnapshots, allowChecksums) {
});
}
exports.findInvalidWrapperJars = findInvalidWrapperJars;
class InvalidWrapperJar {
constructor(path, checksum) {
this.path = path;
this.checksum = checksum;
}
}
exports.InvalidWrapperJar = InvalidWrapperJar;
/***/ }),

View file

@ -13,7 +13,12 @@ export async function run(): Promise<void> {
allowChecksums
)
if (invalidWrapperJars.length > 0) {
core.setFailed(`Invalid wrapper jars ${invalidWrapperJars}`)
const list = invalidWrapperJars.map(
invalid => `${invalid.checksum} ${invalid.path}`
)
core.setFailed(
`Found unknown Gradle Wrapper JAR files\n${list.join('\n- ')}`
)
}
} catch (error) {
core.setFailed(error.message)

View file

@ -6,19 +6,28 @@ export async function findInvalidWrapperJars(
gitRepoRoot: string,
allowSnapshots: boolean,
allowChecksums: string[]
): Promise<string[]> {
): Promise<InvalidWrapperJar[]> {
const wrapperJars = await find.findWrapperJars(gitRepoRoot)
if (wrapperJars.length > 0) {
const validChecksums = await checksums.fetchValidChecksums(allowSnapshots)
validChecksums.push(...allowChecksums)
const invalidWrapperJars: string[] = []
const invalidWrapperJars: InvalidWrapperJar[] = []
for (const wrapperJar of wrapperJars) {
const sha = await hash.sha256File(wrapperJar)
if (!validChecksums.includes(sha)) {
invalidWrapperJars.push(wrapperJar)
invalidWrapperJars.push(new InvalidWrapperJar(wrapperJar, sha))
}
}
return invalidWrapperJars
}
return []
}
export class InvalidWrapperJar {
path: string
checksum: string
constructor(path: string, checksum: string) {
this.path = path
this.checksum = checksum
}
}