diff --git a/README.md b/README.md index eed9c8f..3957a73 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ If any are found that do not match the SHA-256 checksums of our official release Simply add this action to your workflow **after** having checked out your source tree and **before** running any Gradle build: ```yaml -uses: gradle/wrapper-validation-action@releases/v1 +uses: gradle/wrapper-validation-action@v1 ``` Here's a sample complete workflow you can add to your repositories: @@ -47,7 +47,7 @@ Here's a sample complete workflow you can add to your repositories: **`.github/workflows/gradle-wrapper-validation.yml`** ```yaml name: "Validate Gradle Wrapper" -on: [push, pull_request] +on: [push] jobs: validation: @@ -55,7 +55,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: eskatos/gradle-wrapper-check@releases/v1 + - uses: gradle/wrapper-validation-action@v1 ``` ## Reporting Failures diff --git a/__tests__/validate.test.ts b/__tests__/validate.test.ts index 647d366..a3ec714 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,11 @@ 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 to find at least 3 Gradle Wrapper JARs but got only 2' + ) +}) diff --git a/action.yml b/action.yml index c3c843a..f8c1801 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,12 @@ 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 @@ -10,6 +15,11 @@ inputs: description: 'Allow arbitrary checksums, comma separated' required: false default: '' + runs: using: 'node12' main: 'dist/index.js' + +branding: + icon: 'shield' + color: gray-dark diff --git a/dist/index.js b/dist/index.js index ebba283..fdda1cc 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 to find at least ${minWrapperCount} Gradle Wrapper JARs 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..0be80e8 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -4,10 +4,16 @@ import * as hash from './hash' export async function findInvalidWrapperJars( gitRepoRoot: string, + minWrapperCount: number, allowSnapshots: boolean, allowChecksums: string[] ): Promise { const wrapperJars = await find.findWrapperJars(gitRepoRoot) + if (wrapperJars.length < minWrapperCount) { + throw new Error( + `Expected to find at least ${minWrapperCount} Gradle Wrapper JARs but got only ${wrapperJars.length}` + ) + } if (wrapperJars.length > 0) { const validChecksums = await checksums.fetchValidChecksums(allowSnapshots) validChecksums.push(...allowChecksums)