mirror of
https://github.com/gradle/wrapper-validation-action
synced 2024-11-23 17:22:01 +00:00
Introduce min-wrapper-count input
Signed-off-by: Paul Merlin <paul@gradle.com>
This commit is contained in:
parent
66b3019a7f
commit
9393a6ed98
5 changed files with 32 additions and 2 deletions
|
@ -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')
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
8
dist/index.js
vendored
8
dist/index.js
vendored
|
@ -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);
|
||||
|
|
|
@ -5,10 +5,12 @@ import * as validate from './validate'
|
|||
|
||||
export async function run(): Promise<void> {
|
||||
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
|
||||
)
|
||||
|
|
|
@ -4,10 +4,20 @@ import * as hash from './hash'
|
|||
|
||||
export async function findInvalidWrapperJars(
|
||||
gitRepoRoot: string,
|
||||
minWrapperCount: number,
|
||||
allowSnapshots: boolean,
|
||||
allowChecksums: string[]
|
||||
): Promise<InvalidWrapperJar[]> {
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue