Merge branch 'master' into releases/v1

This commit is contained in:
Paul Merlin 2020-01-10 18:06:17 +01:00
commit e60abf8b0f
6 changed files with 36 additions and 5 deletions

View File

@ -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

View File

@ -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'
)
})

View File

@ -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

8
dist/index.js vendored
View File

@ -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);

View File

@ -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
)

View File

@ -4,10 +4,16 @@ 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)
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)