diff --git a/__tests__/validate.test.ts b/__tests__/validate.test.ts index 647d366..042b6bd 100644 --- a/__tests__/validate.test.ts +++ b/__tests__/validate.test.ts @@ -4,6 +4,7 @@ import * as validate from '../src/validate' test('validates wrapper jars', async () => { const invalidWrapperJars = await validate.findInvalidWrapperJars( path.resolve('.'), + 2, false, [] ) @@ -15,3 +16,12 @@ test('validates wrapper jars', async () => { ) ) }) + +test('fails if not enough wrapper jars are found', async () => { + await expect(validate.findInvalidWrapperJars( + path.resolve('.'), + 3, + false, + [] + )).rejects.toThrowError('Expected at least 3 but got only 2') +}) diff --git a/action.yml b/action.yml index c3c843a..17deebd 100644 --- a/action.yml +++ b/action.yml @@ -2,6 +2,10 @@ name: 'Gradle Wrapper Validation' description: 'Validates Gradle Wrapper JAR Files' author: 'Gradle' inputs: + min-wrapper-count: + description: 'Minimum expected wrapper JAR files' + required: false + default: '1' allow-snapshots: description: 'Allow snapshot Gradle versions' required: false diff --git a/dist/index.js b/dist/index.js index ebba283..84a43be 100644 --- a/dist/index.js +++ b/dist/index.js @@ -340,9 +340,10 @@ const validate = __importStar(__webpack_require__(474)); function run() { return __awaiter(this, void 0, void 0, function* () { try { + const minWrapperCount = +core.getInput('min-wrapper-count'); const allowSnapshots = core.getInput('allow-snapshots') === 'true'; const allowChecksums = core.getInput('allow-checksums').split(','); - const invalidWrapperJars = yield validate.findInvalidWrapperJars(path.resolve('.'), allowSnapshots, allowChecksums); + const invalidWrapperJars = yield validate.findInvalidWrapperJars(path.resolve('.'), minWrapperCount, allowSnapshots, allowChecksums); if (invalidWrapperJars.length > 0) { const list = invalidWrapperJars.map(invalid => `${invalid.checksum} ${invalid.path}`); core.setFailed(`Found unknown Gradle Wrapper JAR files\n${list.join('\n- ')}`); @@ -944,9 +945,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); const find = __importStar(__webpack_require__(625)); const checksums = __importStar(__webpack_require__(762)); const hash = __importStar(__webpack_require__(652)); -function findInvalidWrapperJars(gitRepoRoot, allowSnapshots, allowChecksums) { +function findInvalidWrapperJars(gitRepoRoot, minWrapperCount, allowSnapshots, allowChecksums) { return __awaiter(this, void 0, void 0, function* () { const wrapperJars = yield find.findWrapperJars(gitRepoRoot); + if (wrapperJars.length < minWrapperCount) { + throw new Error(`Expected at least ${minWrapperCount} but got only ${wrapperJars.length}`); + } if (wrapperJars.length > 0) { const validChecksums = yield checksums.fetchValidChecksums(allowSnapshots); validChecksums.push(...allowChecksums); diff --git a/src/main.ts b/src/main.ts index 18abe2c..76a6299 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,10 +5,12 @@ import * as validate from './validate' export async function run(): Promise { try { + const minWrapperCount = +core.getInput('min-wrapper-count') const allowSnapshots = core.getInput('allow-snapshots') === 'true' const allowChecksums = core.getInput('allow-checksums').split(',') const invalidWrapperJars = await validate.findInvalidWrapperJars( path.resolve('.'), + minWrapperCount, allowSnapshots, allowChecksums ) diff --git a/src/validate.ts b/src/validate.ts index 05a577a..8a0e7f4 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -4,10 +4,20 @@ import * as hash from './hash' export async function findInvalidWrapperJars( gitRepoRoot: string, + minWrapperCount: number, allowSnapshots: boolean, allowChecksums: string[] ): Promise { const wrapperJars = await find.findWrapperJars(gitRepoRoot) + // eslint-disable-next-line no-console + console.log( + `Expected at least ${minWrapperCount} but got only ${wrapperJars.length}` + ) + if (wrapperJars.length < minWrapperCount) { + throw new Error( + `Expected at least ${minWrapperCount} but got only ${wrapperJars.length}` + ) + } if (wrapperJars.length > 0) { const validChecksums = await checksums.fetchValidChecksums(allowSnapshots) validChecksums.push(...allowChecksums)