Skip to content

Commit

Permalink
Add a workflow to separate out eslint and annotate PRs. (woocommerce#…
Browse files Browse the repository at this point in the history
  • Loading branch information
samueljseay authored Aug 15, 2023
1 parent 3611faf commit 45c49dc
Show file tree
Hide file tree
Showing 45 changed files with 176 additions and 32 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pr-lint-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Lint JS packages

on:
pull_request:
paths-ignore:
- '**/changelog/**'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
lint-test-js:
name: Lint
runs-on: ubuntu-20.04
permissions:
contents: read
# This is required to allow the action to annotate the PR with the linting results.
checks: write
pull-requests: read
steps:
- uses: actions/checkout@v3

- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo

- name: Lint
run: pnpm run -r --filter='release-posts' --filter='woocommerce/client/admin...' --filter='@woocommerce/monorepo-utils' --filter='!@woocommerce/e2e*' --filter='!@woocommerce/api' --color lint
continue-on-error: true

- name: Collect and Combine Eslint Reports
run: node ./.github/workflows/scripts/collect-eslint-reports.js

- name: Annotate Code Linting Results
uses: ataylorme/eslint-annotate-action@a1bf7cb320a18aa53cb848a267ce9b7417221526

with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
report-json: 'combined_eslint_report.json'
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions: {}

jobs:
lint-test-js:
name: Lint and Test JS
name: Run JS Tests
runs-on: ubuntu-20.04
permissions:
contents: read
Expand All @@ -22,8 +22,5 @@ jobs:
- name: Setup WooCommerce Monorepo
uses: ./.github/actions/setup-woocommerce-monorepo

- name: Lint
run: pnpm run -r --filter='release-posts' --filter='woocommerce/client/admin...' --filter='@woocommerce/monorepo-utils' --filter='!@woocommerce/e2e*' --filter='!@woocommerce/api' --color lint

- name: Test
run: pnpm run test --filter='woocommerce/client/admin...' --filter='@woocommerce/monorepo-utils' --filter='!@woocommerce/e2e*' --filter='@woocommerce/monorepo-utils' --filter='!@woocommerce/api' --color
34 changes: 34 additions & 0 deletions .github/workflows/scripts/collect-eslint-reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require( 'fs' );
const path = require( 'path' );

const rootDirectory = path.resolve( __dirname, '..', '..', '..' );

const allReports = [];

function collectReports( directory ) {
const files = fs.readdirSync( directory );
for ( const file of files ) {
const fullPath = path.join( directory, file );
const isDirectory = fs.statSync( fullPath ).isDirectory();

if ( isDirectory && file !== 'node_modules' && file !== 'vendor' ) {
const reportPath = path.join( fullPath, 'eslint_report.json' );
if ( fs.existsSync( reportPath ) ) {
// an array of items
const report = require( reportPath );

// add the report to the allReports array
allReports.push( ...report );
}

collectReports( fullPath );
}
}
}

collectReports( rootDirectory );

fs.writeFileSync(
'combined_eslint_report.json',
JSON.stringify( allReports, null, 2 )
);
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ none
# Logs
logs/

# Eslint Cache
# Eslint
.eslintcache
eslint_report.json

# Environment files
wp-cli.local.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/admin-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"prepare": "composer install",
"changelog": "composer exec -- changelogger",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "tsc --project tsconfig.json --watch",
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"lint:fix": "eslint src --fix",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/admin-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"changelog": "composer exec -- changelogger",
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"build:js": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"build:css": "webpack",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\" \"webpack --watch\"",
Expand Down
4 changes: 4 additions & 0 deletions packages/js/ai/changelog/dev-include-eslint-annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"build:js": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"build:css": "webpack",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\" \"webpack --watch\"",
Expand Down
4 changes: 4 additions & 0 deletions packages/js/api/changelog/dev-include-eslint-annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"compile": "tsc --project tsconfig.json",
"prepack": "pnpm run build",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"lint:fix": "eslint src --fix"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
4 changes: 2 additions & 2 deletions packages/js/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@
"changelog": "composer exec -- changelogger",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src --ext=js,ts,tsx",
"lint": "eslint --output-file eslint_report.json --format json --ext=js,ts,tsx src",
"build:js": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"build:css": "webpack",
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"lint:fix": "eslint src --ext=js,ts,tsx --fix",
"lint:fix": "eslint --output-file eslint_report.json --format json --ext=js,ts,tsx src --fix",
"prepack": "pnpm run clean && pnpm run build",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\" \"webpack --watch\"",
"test:update-snapshots": "pnpm run test -- --updateSnapshot",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/csv-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\"",
"prepack": "pnpm run clean && pnpm run build",
"lint:fix": "eslint src --fix",
Expand Down
4 changes: 4 additions & 0 deletions packages/js/currency/changelog/dev-include-eslint-annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/currency/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\"",
"prepack": "pnpm run clean && pnpm run build",
"lint:fix": "eslint src --fix",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/customer-effort-score/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"build:js": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"build:css": "webpack",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\" \"webpack --watch\"",
Expand Down
4 changes: 4 additions & 0 deletions packages/js/data/changelog/dev-include-eslint-annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\"",
"prepack": "pnpm run clean && pnpm run build",
"lint:fix": "eslint src --fix",
Expand Down
4 changes: 4 additions & 0 deletions packages/js/date/changelog/dev-include-eslint-annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/date/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\"",
"prepack": "pnpm run clean && pnpm run build",
"lint:fix": "eslint src --fix",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"scripts": {
"prepare": "composer install",
"changelog": "composer exec -- changelogger",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"lint:fix": "eslint src --fix"
},
"lint-staged": {
Expand Down
4 changes: 2 additions & 2 deletions packages/js/e2e-core-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"clean": "rm -rf ./build ./build-module",
"compile": "e2e-builds",
"lint": "eslint src --ext=js,ts,tsx",
"lint:fix": "eslint src --ext=js,ts,tsx --fix"
"lint": "eslint --output-file eslint_report.json --format json --ext=js,ts,tsx src",
"lint:fix": "eslint --output-file eslint_report.json --format json --ext=js,ts,tsx src --fix"
},
"lint-staged": {
"*.(t|j)s?(x)": [
Expand Down
4 changes: 2 additions & 2 deletions packages/js/e2e-environment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"test:e2e": "bash ./bin/wait-for-build.sh && ./bin/e2e-test-integration.js",
"test:e2e-debug": "bash ./bin/wait-for-build.sh && ./bin/e2e-test-integration.js --dev --debug",
"test:e2e-dev": "bash ./bin/wait-for-build.sh && ./bin/e2e-test-integration.js --dev",
"lint": "eslint src --ext=js,ts,tsx",
"lint:fix": "eslint src --ext=js,ts,tsx --fix"
"lint": "eslint --output-file eslint_report.json --format json --ext=js,ts,tsx src",
"lint:fix": "eslint --output-file eslint_report.json --format json --ext=js,ts,tsx src --fix"
},
"bin": {
"wc-e2e": "bin/wc-e2e.sh"
Expand Down
4 changes: 2 additions & 2 deletions packages/js/e2e-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"clean": "rm -rf ./build ./build-module",
"compile": "e2e-builds",
"prepack": "pnpm run build",
"lint": "eslint src --ext=js,ts,tsx",
"lint:fix": "eslint src --ext=js,ts,tsx --fix"
"lint": "eslint --output-file eslint_report.json --format json --ext=js,ts,tsx src",
"lint:fix": "eslint --output-file eslint_report.json --format json --ext=js,ts,tsx src --fix"
},
"lint-staged": {
"*.(t|j)s?(x)": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"build:js": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"build:css": "webpack",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\" \"webpack --watch\"",
Expand Down
4 changes: 4 additions & 0 deletions packages/js/explat/changelog/dev-include-eslint-annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/explat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\"",
"prepack": "pnpm run clean && pnpm run build",
"lint:fix": "eslint src --fix",
Expand Down
2 changes: 1 addition & 1 deletion packages/js/internal-js-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"scripts": {
"turbo:build": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"ts:check": "tsc --noEmit --project ./tsconfig.json",
"clean": "pnpm exec rimraf *.tsbuildinfo build build-*",
"prepack": "pnpm run clean && pnpm run build",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/navigation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\"",
"prepack": "pnpm run clean && pnpm run build",
"lint:fix": "eslint src --fix",
Expand Down
2 changes: 1 addition & 1 deletion packages/js/notices/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"turbo:build": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\"",
"prepack": "pnpm run clean && pnpm run build",
"lint:fix": "eslint src --fix"
Expand Down
4 changes: 4 additions & 0 deletions packages/js/number/changelog/dev-include-eslint-annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/number/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\"",
"prepack": "pnpm run clean && pnpm run build",
"lint:fix": "eslint src --fix",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/onboarding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"changelog": "composer exec -- changelogger",
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"build:js": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"build:css": "webpack",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\" \"webpack --watch\"",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Make eslint emit JSON report for annotating PRs.
2 changes: 1 addition & 1 deletion packages/js/product-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"clean": "pnpm exec rimraf tsconfig.tsbuildinfo build build-*",
"build": "pnpm -w exec turbo run turbo:build --filter=$npm_package_name",
"test": "pnpm -w exec turbo run turbo:test --filter=$npm_package_name",
"lint": "eslint src",
"lint": "eslint --output-file eslint_report.json --format json src",
"build:js": "tsc --project tsconfig.json && tsc --project tsconfig-cjs.json",
"build:css": "webpack",
"start": "concurrently \"tsc --project tsconfig.json --watch\" \"tsc --project tsconfig-cjs.json --watch\" \"webpack --watch\"",
Expand Down
Loading

0 comments on commit 45c49dc

Please sign in to comment.