mirror of
https://github.com/gradle/wrapper-validation-action
synced 2024-11-23 17:22:01 +00:00
Make TypeScript linter happy
Signed-off-by: Paul Merlin <paul@gradle.com>
This commit is contained in:
parent
9ecb02f313
commit
9e2c9e95db
11 changed files with 22653 additions and 294 deletions
|
@ -1,10 +1,10 @@
|
|||
import * as path from "path";
|
||||
import * as path from 'path'
|
||||
import * as find from '../src/find'
|
||||
|
||||
test('finds test data wrapper jars', async () => {
|
||||
let repoRoot = path.resolve('.')
|
||||
let wrapperJars = await find.findWrapperJars(repoRoot)
|
||||
const repoRoot = path.resolve('.')
|
||||
const wrapperJars = await find.findWrapperJars(repoRoot)
|
||||
expect(wrapperJars.length).toBe(2)
|
||||
expect(wrapperJars).toContain("__tests__/data/valid/gradle-wrapper.jar")
|
||||
expect(wrapperJars).toContain("__tests__/data/invalid/gradle-wrapper.jar")
|
||||
expect(wrapperJars).toContain('__tests__/data/valid/gradle-wrapper.jar')
|
||||
expect(wrapperJars).toContain('__tests__/data/invalid/gradle-wrapper.jar')
|
||||
})
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import * as path from "path";
|
||||
import * as path from 'path'
|
||||
import * as hash from '../src/hash'
|
||||
|
||||
test('can sha256 files', async () => {
|
||||
let sha = await hash.sha256File(path.resolve('__tests__/data/invalid/gradle-wrapper.jar'))
|
||||
expect(sha).toEqual("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
||||
let sha = await hash.sha256File(
|
||||
path.resolve('__tests__/data/invalid/gradle-wrapper.jar')
|
||||
)
|
||||
expect(sha).toEqual(
|
||||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
||||
)
|
||||
})
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import * as path from "path";
|
||||
import * as path from 'path'
|
||||
import * as validate from '../src/validate'
|
||||
|
||||
test('validates wrapper jars', async () => {
|
||||
let invalidWrapperJars = await validate.findInvalidWrapperJars(path.resolve('.'), false)
|
||||
let invalidWrapperJars = await validate.findInvalidWrapperJars(
|
||||
path.resolve('.'),
|
||||
false
|
||||
)
|
||||
expect(invalidWrapperJars.length).toBe(1)
|
||||
expect(invalidWrapperJars[0]).toEqual("__tests__/data/invalid/gradle-wrapper.jar")
|
||||
expect(invalidWrapperJars[0]).toEqual(
|
||||
'__tests__/data/invalid/gradle-wrapper.jar'
|
||||
)
|
||||
})
|
||||
|
|
BIN
dist/build/Release/nodegit.node
vendored
Executable file
BIN
dist/build/Release/nodegit.node
vendored
Executable file
Binary file not shown.
22401
dist/index.js
vendored
22401
dist/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,21 +1,35 @@
|
|||
import * as httpm from 'typed-rest-client/HttpClient'
|
||||
|
||||
const httpc = new httpm.HttpClient("eskatos/gradle-wrapper-check");
|
||||
const httpc = new httpm.HttpClient('eskatos/gradle-wrapper-check')
|
||||
|
||||
export async function fetchValidChecksums(allowSnapshots: boolean): Promise<string[]> {
|
||||
let all: any[] = await httpGetJson('https://services.gradle.org/versions/all')
|
||||
let withChecksum = all.filter(entry => entry.hasOwnProperty('wrapperChecksumUrl'))
|
||||
let allowed = withChecksum.filter(entry => allowSnapshots || !entry.snapshot)
|
||||
let checksumUrls: string[] = allowed.map(entry => entry.wrapperChecksumUrl)
|
||||
let checksums = await Promise.all(checksumUrls.map((url: string) => httpGetText(url)))
|
||||
export async function fetchValidChecksums(
|
||||
allowSnapshots: boolean
|
||||
): Promise<string[]> {
|
||||
const all: object[] = await httpGetJsonArray(
|
||||
'https://services.gradle.org/versions/all'
|
||||
)
|
||||
const withChecksum = all.filter(entry =>
|
||||
entry.hasOwnProperty('wrapperChecksumUrl')
|
||||
)
|
||||
const allowed = withChecksum.filter(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(entry: any) => allowSnapshots || !entry.snapshot
|
||||
)
|
||||
const checksumUrls: string[] = allowed.map(
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(entry: any) => entry.wrapperChecksumUrl as string
|
||||
)
|
||||
const checksums = await Promise.all(
|
||||
checksumUrls.map(async (url: string) => httpGetText(url))
|
||||
)
|
||||
return [...new Set(checksums)]
|
||||
}
|
||||
|
||||
async function httpGetJson(url: string): Promise<any> {
|
||||
return JSON.parse(await httpGetText(url));
|
||||
async function httpGetJsonArray(url: string): Promise<object[]> {
|
||||
return JSON.parse(await httpGetText(url))
|
||||
}
|
||||
|
||||
async function httpGetText(url: string): Promise<string> {
|
||||
const response = await httpc.get(url);
|
||||
return await response.readBody();
|
||||
const response = await httpc.get(url)
|
||||
return await response.readBody()
|
||||
}
|
||||
|
|
26
src/find.ts
26
src/find.ts
|
@ -1,31 +1,27 @@
|
|||
import {Repository, Commit, Tree, TreeEntry} from 'nodegit'
|
||||
|
||||
|
||||
export async function findWrapperJars(gitRepoPath: string): Promise<string[]> {
|
||||
const repo: Repository = await Repository.open(gitRepoPath)
|
||||
const commit: Commit = await repo.getHeadCommit()
|
||||
const tree: Tree = await commit.getTree()
|
||||
const walker = tree.walk()
|
||||
|
||||
let repo: Repository = await Repository.open(gitRepoPath)
|
||||
let commit: Commit = await repo.getHeadCommit()
|
||||
let tree: Tree = await commit.getTree()
|
||||
let walker = tree.walk()
|
||||
const prom: Promise<string[]> = new Promise((resolve, reject) => {
|
||||
const wrapperJars: string[] = []
|
||||
|
||||
let prom: Promise<string[]> = new Promise(((resolve, reject) => {
|
||||
|
||||
let wrapperJars: string[] = []
|
||||
|
||||
walker.on("entry", (entry: TreeEntry) => {
|
||||
let path = entry.path()
|
||||
walker.on('entry', (entry: TreeEntry) => {
|
||||
const path = entry.path()
|
||||
if (path.endsWith('gradle-wrapper.jar')) {
|
||||
wrapperJars.push(path)
|
||||
}
|
||||
})
|
||||
walker.on("error", (error) => {
|
||||
walker.on('error', error => {
|
||||
reject(error)
|
||||
})
|
||||
walker.on("end", (trees) => {
|
||||
walker.on('end', () => {
|
||||
resolve(wrapperJars)
|
||||
})
|
||||
|
||||
}))
|
||||
})
|
||||
walker.start()
|
||||
return prom
|
||||
}
|
||||
|
|
12
src/hash.ts
12
src/hash.ts
|
@ -1,12 +1,12 @@
|
|||
import * as crypto from "crypto"
|
||||
import * as fs from "fs"
|
||||
import * as crypto from 'crypto'
|
||||
import * as fs from 'fs'
|
||||
|
||||
export async function sha256File(path: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hash = crypto.createHash("sha256")
|
||||
const hash = crypto.createHash('sha256')
|
||||
fs.createReadStream(path)
|
||||
.on("data", data => hash.update(data))
|
||||
.on("end", () => resolve(hash.digest("hex")))
|
||||
.on("error", error => reject(error))
|
||||
.on('data', data => hash.update(data))
|
||||
.on('end', () => resolve(hash.digest('hex')))
|
||||
.on('error', error => reject(error))
|
||||
})
|
||||
}
|
||||
|
|
14
src/main.ts
14
src/main.ts
|
@ -1,15 +1,17 @@
|
|||
import * as path from "path";
|
||||
import * as path from 'path'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
import * as validate from "./validate"
|
||||
|
||||
import * as validate from './validate'
|
||||
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const allowSnapshots = core.getInput("allow-snapshots") == "true"
|
||||
const invalidWrapperJars = await validate.findInvalidWrapperJars(path.resolve('.'), allowSnapshots)
|
||||
const allowSnapshots = core.getInput('allow-snapshots') === 'true'
|
||||
const invalidWrapperJars = await validate.findInvalidWrapperJars(
|
||||
path.resolve('.'),
|
||||
allowSnapshots
|
||||
)
|
||||
if (invalidWrapperJars.length > 0) {
|
||||
core.setFailed("Invalid wrapper jars " + invalidWrapperJars)
|
||||
core.setFailed(`Invalid wrapper jars ${invalidWrapperJars}`)
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
import * as find from "./find"
|
||||
import * as checksums from "./checksums"
|
||||
import * as hash from "./hash"
|
||||
|
||||
|
||||
export async function findInvalidWrapperJars(gitRepoRoot: string, allowSnapshots: boolean): Promise<string[]> {
|
||||
import * as find from './find'
|
||||
import * as checksums from './checksums'
|
||||
import * as hash from './hash'
|
||||
|
||||
export async function findInvalidWrapperJars(
|
||||
gitRepoRoot: string,
|
||||
allowSnapshots: boolean
|
||||
): Promise<string[]> {
|
||||
const wrapperJars = await find.findWrapperJars(gitRepoRoot)
|
||||
if (wrapperJars.length > 0) {
|
||||
const validChecksums = await checksums.fetchValidChecksums(allowSnapshots)
|
||||
const invalidWrapperJars: string[] = []
|
||||
for (let wrapperJar of wrapperJars) {
|
||||
for (const wrapperJar of wrapperJars) {
|
||||
const sha = await hash.sha256File(wrapperJar)
|
||||
if (validChecksums.indexOf(sha) < 0) {
|
||||
if (!validChecksums.includes(sha)) {
|
||||
invalidWrapperJars.push(wrapperJar)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue