From 89c35dd18be0546235f3cbf9a2025dad38ecc173 Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Mon, 6 Jan 2020 13:50:19 +0100 Subject: [PATCH] Better reporting of invalid wrapper jars Signed-off-by: Paul Merlin --- __tests__/validate.test.ts | 5 ++++- dist/index.js | 12 ++++++++++-- src/main.ts | 7 ++++++- src/validate.ts | 15 ++++++++++++--- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/__tests__/validate.test.ts b/__tests__/validate.test.ts index 8e4f359..647d366 100644 --- a/__tests__/validate.test.ts +++ b/__tests__/validate.test.ts @@ -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' + ) ) }) diff --git a/dist/index.js b/dist/index.js index 8de39e8..ebba283 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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; /***/ }), diff --git a/src/main.ts b/src/main.ts index cccc911..18abe2c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,7 +13,12 @@ export async function run(): Promise { 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) diff --git a/src/validate.ts b/src/validate.ts index d49c173..05a577a 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -6,19 +6,28 @@ export async function findInvalidWrapperJars( gitRepoRoot: string, allowSnapshots: boolean, allowChecksums: string[] -): Promise { +): Promise { 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 + } +}