Introduce min-wrapper-count input

Signed-off-by: Paul Merlin <paul@gradle.com>
This commit is contained in:
Paul Merlin 2020-01-10 17:54:22 +01:00
parent 66b3019a7f
commit 9393a6ed98
5 changed files with 32 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import * as validate from '../src/validate'
test('validates wrapper jars', async () => { test('validates wrapper jars', async () => {
const invalidWrapperJars = await validate.findInvalidWrapperJars( const invalidWrapperJars = await validate.findInvalidWrapperJars(
path.resolve('.'), path.resolve('.'),
2,
false, 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')
})

View file

@ -2,6 +2,10 @@ name: 'Gradle Wrapper Validation'
description: 'Validates Gradle Wrapper JAR Files' description: 'Validates Gradle Wrapper JAR Files'
author: 'Gradle' author: 'Gradle'
inputs: inputs:
min-wrapper-count:
description: 'Minimum expected wrapper JAR files'
required: false
default: '1'
allow-snapshots: allow-snapshots:
description: 'Allow snapshot Gradle versions' description: 'Allow snapshot Gradle versions'
required: false required: false

8
dist/index.js vendored
View file

@ -340,9 +340,10 @@ const validate = __importStar(__webpack_require__(474));
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const minWrapperCount = +core.getInput('min-wrapper-count');
const allowSnapshots = core.getInput('allow-snapshots') === 'true'; const allowSnapshots = core.getInput('allow-snapshots') === 'true';
const allowChecksums = core.getInput('allow-checksums').split(','); 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) { if (invalidWrapperJars.length > 0) {
const list = invalidWrapperJars.map(invalid => `${invalid.checksum} ${invalid.path}`); const list = invalidWrapperJars.map(invalid => `${invalid.checksum} ${invalid.path}`);
core.setFailed(`Found unknown Gradle Wrapper JAR files\n${list.join('\n- ')}`); 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 find = __importStar(__webpack_require__(625));
const checksums = __importStar(__webpack_require__(762)); const checksums = __importStar(__webpack_require__(762));
const hash = __importStar(__webpack_require__(652)); 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* () { return __awaiter(this, void 0, void 0, function* () {
const wrapperJars = yield find.findWrapperJars(gitRepoRoot); 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) { if (wrapperJars.length > 0) {
const validChecksums = yield checksums.fetchValidChecksums(allowSnapshots); const validChecksums = yield checksums.fetchValidChecksums(allowSnapshots);
validChecksums.push(...allowChecksums); validChecksums.push(...allowChecksums);

View file

@ -5,10 +5,12 @@ import * as validate from './validate'
export async function run(): Promise<void> { export async function run(): Promise<void> {
try { try {
const minWrapperCount = +core.getInput('min-wrapper-count')
const allowSnapshots = core.getInput('allow-snapshots') === 'true' const allowSnapshots = core.getInput('allow-snapshots') === 'true'
const allowChecksums = core.getInput('allow-checksums').split(',') const allowChecksums = core.getInput('allow-checksums').split(',')
const invalidWrapperJars = await validate.findInvalidWrapperJars( const invalidWrapperJars = await validate.findInvalidWrapperJars(
path.resolve('.'), path.resolve('.'),
minWrapperCount,
allowSnapshots, allowSnapshots,
allowChecksums allowChecksums
) )

View file

@ -4,10 +4,20 @@ import * as hash from './hash'
export async function findInvalidWrapperJars( export async function findInvalidWrapperJars(
gitRepoRoot: string, gitRepoRoot: string,
minWrapperCount: number,
allowSnapshots: boolean, allowSnapshots: boolean,
allowChecksums: string[] allowChecksums: string[]
): Promise<InvalidWrapperJar[]> { ): Promise<InvalidWrapperJar[]> {
const wrapperJars = await find.findWrapperJars(gitRepoRoot) 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) { if (wrapperJars.length > 0) {
const validChecksums = await checksums.fetchValidChecksums(allowSnapshots) const validChecksums = await checksums.fetchValidChecksums(allowSnapshots)
validChecksums.push(...allowChecksums) validChecksums.push(...allowChecksums)