diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000000..9f10a8004a --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,3 @@ +#!/bin/sh + +yarn prepush diff --git a/bin/prepush.sh b/bin/prepush.sh new file mode 100755 index 0000000000..7308a4fa3f --- /dev/null +++ b/bin/prepush.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +yarn lint +lint_status=$? + +if [ "$lint_status" -ne 0 ]; then + printf "=============================================================\n" >&2 + printf "The following command failed: yarn lint\n" >&2 + printf "run yarn lint command to find the lint errors and fix them, then push again.\n" >&2 + printf "=============================================================\n" >&2 + exit "$lint_status" +fi + +yarn test:audit +audit_status=$? + +yarn npm audit --recursive --environment production --json > yarn-audit-known-issues +cve_suppress_status=$? + +if [ "$cve_suppress_status" -ne 0 ] && [ ! -s yarn-audit-known-issues ]; then + printf "=============================================================\n" >&2 + printf "Unable to refresh yarn-audit-known-issues\n" >&2 + printf "=============================================================\n" >&2 + exit "$cve_suppress_status" +fi + +if ! git diff --quiet -- yarn-audit-known-issues; then + printf "=============================================================\n" >&2 + printf "yarn-audit-known-issues was refreshed with the latest CVE audit output.\n" >&2 + printf "Commit yarn-audit-known-issues and push again.\n" >&2 + printf "=============================================================\n" >&2 + exit 1 +fi + +if [ "$audit_status" -ne 0 ]; then + printf "=============================================================\n" >&2 + printf "The following command failed: test:audit\n" >&2 + printf "\n" >&2 + printf "There are unsuppressed vulnerabilities, update yarn-audit-known-issues and commit it.\n" >&2 + printf "\n" >&2 + printf "=============================================================\n" >&2 + exit 1 +fi diff --git a/package.json b/package.json index 38447a3b4c..f6bd092dc9 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "test": "ng test ccd-case-ui-toolkit-lib --code-coverage", "test:watch": "ng test ccd-case-ui-toolkit-lib --code-coverage --watch=true", "test:audit": "./bin/run-yarn-audit.sh -f yarn-audit-known-issues", + "prepush": "bash ./bin/prepush.sh", "tslint": "tslint", "docs:json": "compodoc -p ./tsconfig.json -e json -d .", "storybook": "yarn docs:json && start-storybook -p 6006", @@ -132,6 +133,7 @@ "gulp": "^4.0.2", "gulp-inline-ng2-template": "^5.0.1", "gulp-sass": "^5.1.0", + "husky": "^9.1.7", "istanbul-instrumenter-loader": "^3.0.1", "jasmine-core": "~5.1.0", "jasmine-spec-reporter": "~7.0.0", diff --git a/yarn.lock b/yarn.lock index dcefd6d975..5f098456e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3456,6 +3456,7 @@ __metadata: gulp: "npm:^4.0.2" gulp-inline-ng2-template: "npm:^5.0.1" gulp-sass: "npm:^5.1.0" + husky: "npm:^9.1.7" istanbul-instrumenter-loader: "npm:^3.0.1" jasmine-core: "npm:~5.1.0" jasmine-spec-reporter: "npm:~7.0.0" @@ -17022,6 +17023,15 @@ __metadata: languageName: node linkType: hard +"husky@npm:^9.1.7": + version: 9.1.7 + resolution: "husky@npm:9.1.7" + bin: + husky: bin.js + checksum: 10/c2412753f15695db369634ba70f50f5c0b7e5cb13b673d0826c411ec1bd9ddef08c1dad89ea154f57da2521d2605bd64308af748749b27d08c5f563bcd89975f + languageName: node + linkType: hard + "hyperdyperid@npm:^1.2.0": version: 1.2.0 resolution: "hyperdyperid@npm:1.2.0"