Merge pull request #142 from kachick/fix-lint-errors-and-add-ci

Add CI workflow and fix lint errors
This commit is contained in:
Federico Builes
2022-07-06 11:00:13 +02:00
committed by GitHub
7 changed files with 82 additions and 50 deletions
+42
View File
@@ -0,0 +1,42 @@
name: CI
on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Test
run: |
npm test
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Check format
run: |
npm run format-check
- name: Lint
run: |
npm run lint
Generated Vendored
+16 -17
View File
@@ -81,11 +81,11 @@ exports.getDeniedLicenseChanges = void 0;
* @returns {[Array<Change>, Array<Change]} A tuple where the first element is the list of denied changes and the second one is the list of changes with unknown licenses * @returns {[Array<Change>, Array<Change]} A tuple where the first element is the list of denied changes and the second one is the list of changes with unknown licenses
*/ */
function getDeniedLicenseChanges(changes, licenses) { function getDeniedLicenseChanges(changes, licenses) {
let { allow, deny } = licenses; const { allow, deny } = licenses;
let disallowed = []; const disallowed = [];
let unknown = []; const unknown = [];
for (const change of changes) { for (const change of changes) {
let license = change.license; const license = change.license;
if (license === null) { if (license === null) {
unknown.push(change); unknown.push(change);
continue; continue;
@@ -171,14 +171,14 @@ function run() {
baseRef: pull_request.base.sha, baseRef: pull_request.base.sha,
headRef: pull_request.head.sha headRef: pull_request.head.sha
}); });
let config = (0, config_1.readConfig)(); const config = (0, config_1.readConfig)();
let minSeverity = config.fail_on_severity; const minSeverity = config.fail_on_severity;
let failed = false; let failed = false;
let licenses = { const licenses = {
allow: config.allow_licenses, allow: config.allow_licenses,
deny: config.deny_licenses deny: config.deny_licenses
}; };
let filteredChanges = (0, filter_1.filterChangesBySeverity)(minSeverity, changes); const filteredChanges = (0, filter_1.filterChangesBySeverity)(minSeverity, changes);
for (const change of filteredChanges) { for (const change of filteredChanges) {
if (change.change_type === 'added' && if (change.change_type === 'added' &&
change.vulnerabilities !== undefined && change.vulnerabilities !== undefined &&
@@ -187,9 +187,9 @@ function run() {
failed = true; failed = true;
} }
} }
let [licenseErrors, unknownLicenses] = (0, licenses_1.getDeniedLicenseChanges)(changes, licenses); const [licenseErrors, unknownLicenses] = (0, licenses_1.getDeniedLicenseChanges)(changes, licenses);
if (licenseErrors.length > 0) { if (licenseErrors.length > 0) {
printLicensesError(licenseErrors, licenses); printLicensesError(licenseErrors);
core.setFailed('Dependency review detected incompatible licenses.'); core.setFailed('Dependency review detected incompatible licenses.');
} }
printNullLicenses(unknownLicenses); printNullLicenses(unknownLicenses);
@@ -233,11 +233,10 @@ function renderSeverity(severity) {
}[severity]; }[severity];
return `${ansi_styles_1.default.color[color].open}(${severity} severity)${ansi_styles_1.default.color[color].close}`; return `${ansi_styles_1.default.color[color].open}(${severity} severity)${ansi_styles_1.default.color[color].close}`;
} }
function printLicensesError(changes, licenses) { function printLicensesError(changes) {
if (changes.length == 0) { if (changes.length === 0) {
return; return;
} }
let { allow = [], deny = [] } = licenses;
core.info('\nThe following dependencies have incompatible licenses:\n'); core.info('\nThe following dependencies have incompatible licenses:\n');
for (const change of changes) { for (const change of changes) {
core.info(`${ansi_styles_1.default.bold.open}${change.manifest} » ${change.name}@${change.version}${ansi_styles_1.default.bold.close} License: ${ansi_styles_1.default.color.red.open}${change.license}${ansi_styles_1.default.color.red.close}`); core.info(`${ansi_styles_1.default.bold.open}${change.manifest} » ${change.name}@${change.version}${ansi_styles_1.default.bold.close} License: ${ansi_styles_1.default.color.red.open}${change.license}${ansi_styles_1.default.color.red.close}`);
@@ -320,7 +319,7 @@ exports.ConfigurationOptionsSchema = z
deny_licenses: z.array(z.string()).default([]) deny_licenses: z.array(z.string()).default([])
}) })
.partial() .partial()
.refine(obj => !(obj.allow_licenses && obj.deny_licenses), "Your workflow file has both an allow_licenses list and deny_licenses list, but you can only set one or the other."); .refine(obj => !(obj.allow_licenses && obj.deny_licenses), 'Your workflow file has both an allow_licenses list and deny_licenses list, but you can only set one or the other.');
exports.ChangesSchema = z.array(exports.ChangeSchema); exports.ChangesSchema = z.array(exports.ChangeSchema);
@@ -13814,13 +13813,13 @@ const schemas_1 = __nccwpck_require__(1129);
function filterChangesBySeverity(severity, changes) { function filterChangesBySeverity(severity, changes) {
const severityIdx = schemas_1.SEVERITIES.indexOf(severity); const severityIdx = schemas_1.SEVERITIES.indexOf(severity);
let filteredChanges = []; let filteredChanges = [];
for (let change of changes) { for (const change of changes) {
if (change === undefined || if (change === undefined ||
change.vulnerabilities === undefined || change.vulnerabilities === undefined ||
change.vulnerabilities.length === 0) { change.vulnerabilities.length === 0) {
continue; continue;
} }
let fChange = Object.assign(Object.assign({}, change), { vulnerabilities: change.vulnerabilities.filter(vuln => { const fChange = Object.assign(Object.assign({}, change), { vulnerabilities: change.vulnerabilities.filter(vuln => {
const vulnIdx = schemas_1.SEVERITIES.indexOf(vuln.severity); const vulnIdx = schemas_1.SEVERITIES.indexOf(vuln.severity);
if (vulnIdx <= severityIdx) { if (vulnIdx <= severityIdx) {
return true; return true;
@@ -13900,7 +13899,7 @@ exports.ConfigurationOptionsSchema = z
deny_licenses: z.array(z.string()).default([]) deny_licenses: z.array(z.string()).default([])
}) })
.partial() .partial()
.refine(obj => !(obj.allow_licenses && obj.deny_licenses), "Your workflow file has both an allow_licenses list and deny_licenses list, but you can only set one or the other."); .refine(obj => !(obj.allow_licenses && obj.deny_licenses), 'Your workflow file has both an allow_licenses list and deny_licenses list, but you can only set one or the other.');
exports.ChangesSchema = z.array(exports.ChangeSchema); exports.ChangesSchema = z.array(exports.ChangeSchema);
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -4
View File
@@ -1,5 +1,4 @@
import {Changes} from './schemas' import {Changes, Severity, SEVERITIES} from './schemas'
import {Severity, SEVERITIES} from './schemas'
export function filterChangesBySeverity( export function filterChangesBySeverity(
severity: Severity, severity: Severity,
@@ -7,7 +6,7 @@ export function filterChangesBySeverity(
): Changes { ): Changes {
const severityIdx = SEVERITIES.indexOf(severity) const severityIdx = SEVERITIES.indexOf(severity)
let filteredChanges = [] let filteredChanges = []
for (let change of changes) { for (const change of changes) {
if ( if (
change === undefined || change === undefined ||
change.vulnerabilities === undefined || change.vulnerabilities === undefined ||
@@ -16,7 +15,7 @@ export function filterChangesBySeverity(
continue continue
} }
let fChange = { const fChange = {
...change, ...change,
vulnerabilities: change.vulnerabilities.filter(vuln => { vulnerabilities: change.vulnerabilities.filter(vuln => {
const vulnIdx = SEVERITIES.indexOf(vuln.severity) const vulnIdx = SEVERITIES.indexOf(vuln.severity)
+9 -9
View File
@@ -1,4 +1,4 @@
import {Change, ChangeSchema} from './schemas' import {Change} from './schemas'
/** /**
* Loops through a list of changes, filtering and returning the * Loops through a list of changes, filtering and returning the
@@ -13,19 +13,19 @@ import {Change, ChangeSchema} from './schemas'
* @returns {[Array<Change>, Array<Change]} A tuple where the first element is the list of denied changes and the second one is the list of changes with unknown licenses * @returns {[Array<Change>, Array<Change]} A tuple where the first element is the list of denied changes and the second one is the list of changes with unknown licenses
*/ */
export function getDeniedLicenseChanges( export function getDeniedLicenseChanges(
changes: Array<Change>, changes: Change[],
licenses: { licenses: {
allow?: Array<string> allow?: string[]
deny?: Array<string> deny?: string[]
} }
): [Array<Change>, Array<Change>] { ): [Change[], Change[]] {
let {allow, deny} = licenses const {allow, deny} = licenses
let disallowed: Change[] = [] const disallowed: Change[] = []
let unknown: Change[] = [] const unknown: Change[] = []
for (const change of changes) { for (const change of changes) {
let license = change.license const license = change.license
if (license === null) { if (license === null) {
unknown.push(change) unknown.push(change)
continue continue
+10 -18
View File
@@ -27,16 +27,16 @@ async function run(): Promise<void> {
headRef: pull_request.head.sha headRef: pull_request.head.sha
}) })
let config = readConfig() const config = readConfig()
let minSeverity = config.fail_on_severity const minSeverity = config.fail_on_severity
let failed = false let failed = false
let licenses = { const licenses = {
allow: config.allow_licenses, allow: config.allow_licenses,
deny: config.deny_licenses deny: config.deny_licenses
} }
let filteredChanges = filterChangesBySeverity( const filteredChanges = filterChangesBySeverity(
minSeverity as Severity, minSeverity as Severity,
changes changes
) )
@@ -52,13 +52,13 @@ async function run(): Promise<void> {
} }
} }
let [licenseErrors, unknownLicenses] = getDeniedLicenseChanges( const [licenseErrors, unknownLicenses] = getDeniedLicenseChanges(
changes, changes,
licenses licenses
) )
if (licenseErrors.length > 0) { if (licenseErrors.length > 0) {
printLicensesError(licenseErrors, licenses) printLicensesError(licenseErrors)
core.setFailed('Dependency review detected incompatible licenses.') core.setFailed('Dependency review detected incompatible licenses.')
} }
@@ -90,7 +90,7 @@ async function run(): Promise<void> {
} }
} }
function printChangeVulnerabilities(change: Change) { function printChangeVulnerabilities(change: Change): void {
for (const vuln of change.vulnerabilities) { for (const vuln of change.vulnerabilities) {
core.info( core.info(
`${styles.bold.open}${change.manifest} » ${change.name}@${ `${styles.bold.open}${change.manifest} » ${change.name}@${
@@ -117,19 +117,11 @@ function renderSeverity(
return `${styles.color[color].open}(${severity} severity)${styles.color[color].close}` return `${styles.color[color].open}(${severity} severity)${styles.color[color].close}`
} }
function printLicensesError( function printLicensesError(changes: Change[]): void {
changes: Array<Change>, if (changes.length === 0) {
licenses: {
allow?: Array<string>
deny?: Array<string>
}
): void {
if (changes.length == 0) {
return return
} }
let {allow = [], deny = []} = licenses
core.info('\nThe following dependencies have incompatible licenses:\n') core.info('\nThe following dependencies have incompatible licenses:\n')
for (const change of changes) { for (const change of changes) {
core.info( core.info(
@@ -138,7 +130,7 @@ function printLicensesError(
} }
} }
function printNullLicenses(changes: Array<Change>): void { function printNullLicenses(changes: Change[]): void {
if (changes.length === 0) { if (changes.length === 0) {
return return
} }
+1 -1
View File
@@ -39,7 +39,7 @@ export const ConfigurationOptionsSchema = z
.partial() .partial()
.refine( .refine(
obj => !(obj.allow_licenses && obj.deny_licenses), obj => !(obj.allow_licenses && obj.deny_licenses),
"Your workflow file has both an allow_licenses list and deny_licenses list, but you can only set one or the other." 'Your workflow file has both an allow_licenses list and deny_licenses list, but you can only set one or the other.'
) )
export const ChangesSchema = z.array(ChangeSchema) export const ChangesSchema = z.array(ChangeSchema)