From 6524f639b40b56e8999662f727aaa5fa949613d0 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Thu, 22 Feb 2024 15:05:28 -0400 Subject: [PATCH] exclude tests folders from template version linting (#44721) Co-authored-by: Ron Rennick --- .github/workflows/pr-highlight-changes.yml | 3 ++- .../src/commands/analyzer/analyzer-lint.ts | 11 +++++++++-- tools/code-analyzer/src/lib/scan-changes.ts | 13 +++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pr-highlight-changes.yml b/.github/workflows/pr-highlight-changes.yml index 518f183d91b..2ffcfebbb30 100644 --- a/.github/workflows/pr-highlight-changes.yml +++ b/.github/workflows/pr-highlight-changes.yml @@ -22,8 +22,9 @@ jobs: working-directory: 'tools/code-analyzer' run: | HEAD_REF=$(git rev-parse HEAD) + exclude="plugins/woocommerce/tests plugins/woocommerce-admin/tests plugins/woocommerce-blocks/tests" version=$(pnpm analyzer major-minor "$HEAD_REF" "plugins/woocommerce/woocommerce.php" | tail -n 1) - pnpm analyzer "$HEAD_REF" $version -o "github" + pnpm analyzer "$HEAD_REF" $version -o "github" -e $exclude - uses: 'actions/github-script@v6' name: 'Validate' with: diff --git a/tools/code-analyzer/src/commands/analyzer/analyzer-lint.ts b/tools/code-analyzer/src/commands/analyzer/analyzer-lint.ts index 2a250e78178..439b7e9bbc1 100644 --- a/tools/code-analyzer/src/commands/analyzer/analyzer-lint.ts +++ b/tools/code-analyzer/src/commands/analyzer/analyzer-lint.ts @@ -35,6 +35,11 @@ const program = new Command() 'Git repo url or local path to a git repo.', join( process.cwd(), '../../' ) ) + .option( + '-e, --exclude ', + 'List of folders / files to exclude.', + [] + ) .addOption( new Option( '-o, --outputStyle ' ).choices( [ 'github', @@ -42,14 +47,16 @@ const program = new Command() ] as const ) ) .action( async ( compare, sinceVersion, options ) => { - const { source, base, outputStyle = 'cli' } = options; + const { source, base, outputStyle = 'cli', exclude = [] } = options; const changes = await scanForChanges( compare, sinceVersion, source, base, - outputStyle + outputStyle, + undefined, + exclude ); if ( changes.templates.size ) { diff --git a/tools/code-analyzer/src/lib/scan-changes.ts b/tools/code-analyzer/src/lib/scan-changes.ts index d2b5096596a..40235036253 100644 --- a/tools/code-analyzer/src/lib/scan-changes.ts +++ b/tools/code-analyzer/src/lib/scan-changes.ts @@ -36,10 +36,6 @@ const generateVersionDiff = async ( `Temporary clone of ${ source } created at ${ tmpRepoPath }` ); - Logger.notice( - `Temporary clone of ${ source } created at ${ tmpRepoPath }` - ); - const diff = await generateDiff( tmpRepoPath, base, @@ -119,7 +115,8 @@ export const scanForChanges = async ( source: string, base: string, outputStyle: 'cli' | 'github', - clonedPath?: string + clonedPath?: string, + exclude?: string[] ) => { Logger.startTask( `Making temporary clone of ${ source }...` ); @@ -134,16 +131,12 @@ export const scanForChanges = async ( `Temporary clone of ${ source } created at ${ tmpRepoPath }` ); - Logger.notice( - `Temporary clone of ${ source } created at ${ tmpRepoPath }` - ); - const diff = await generateDiff( tmpRepoPath, base, compareVersion, Logger.error, - [ 'tools' ] + [ 'tools', ...exclude ] ); // Only checkout the compare version if we're in CLI mode.