Analyzer: Turn on comments for database changes (#33224)

This commit is contained in:
Paul Sealock 2022-06-09 09:25:49 +12:00 committed by GitHub
parent 21e6eea3cc
commit c3fd7134cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 16 deletions

View File

@ -12,13 +12,15 @@ jobs:
- name: Install prerequisites - name: Install prerequisites
run: | run: |
npm install -g pnpm@^6.24.2 npm install -g pnpm@^6.24.2
npm -g i @wordpress/env
pnpm install pnpm install
pnpm nx build:feature-config woocommerce
- name: Run analyzer - name: Run analyzer
id: run id: run
run: ./tools/code-analyzer/bin/dev analyzer "$GITHUB_HEAD_REF" -o github run: ./tools/code-analyzer/bin/dev analyzer "$GITHUB_HEAD_REF" -o github
- name: Print results - name: Print results
id: results id: results
run: echo "::set-output name=results::${{ steps.run.outputs.templates }}${{ steps.run.outputs.wphooks }}" run: echo "::set-output name=results::${{ steps.run.outputs.templates }}${{ steps.run.outputs.wphooks }}${{ steps.run.outputs.schema }}${{ steps.run.outputs.database }}"
comment: comment:
name: Add comment to hightlight changes name: Add comment to hightlight changes
needs: analyze needs: analyze
@ -29,7 +31,7 @@ jobs:
id: find-comment id: find-comment
with: with:
issue-number: ${{ github.event.number }} issue-number: ${{ github.event.number }}
comment-author: woocommercebot body-includes: New hook, template, or database changes in this PR
- name: Add comment - name: Add comment
if: ${{ needs.analyze.outputs.results && (steps.find-comment.outputs.comment-id == '') }} if: ${{ needs.analyze.outputs.results && (steps.find-comment.outputs.comment-id == '') }}
uses: actions/github-script@v5 uses: actions/github-script@v5
@ -40,7 +42,7 @@ jobs:
issue_number: context.issue.number, issue_number: context.issue.number,
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
body: '## New hook or template changes in this PR${{ needs.analyze.outputs.results }}' body: '## New hook, template, or database changes in this PR${{ needs.analyze.outputs.results }}'
}) })
- name: Update comment - name: Update comment
if: ${{ needs.analyze.outputs.results && steps.find-comment.outputs.comment-id }} if: ${{ needs.analyze.outputs.results && steps.find-comment.outputs.comment-id }}
@ -52,15 +54,19 @@ jobs:
comment_id: ${{ steps.find-comment.outputs.comment-id }}, comment_id: ${{ steps.find-comment.outputs.comment-id }},
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
body: '## New hook or template changes in this PR${{ needs.analyze.outputs.results }}' body: '## New hook, template, or database changes in this PR${{ needs.analyze.outputs.results }}'
}) })
- name: Delete comment - name: Delete comment
if: ${{ !needs.analyze.outputs.results && steps.find-comment.outputs.comment-id }} if: ${{ !needs.analyze.outputs.results && steps.find-comment.outputs.comment-id }}
uses: izhangzhihao/delete-comment@master uses: actions/github-script@v5
with: with:
github_token: ${{ secrets.WC_BOT_TRIAGE_TOKEN }} github-token: ${{ secrets.WC_BOT_TRIAGE_TOKEN }}
delete_user_name: woocommercebot script: |
issue_number: ${{ github.event.number }} github.rest.issues.deleteComment({
comment_id: ${{ steps.find-comment.outputs.comment-id }},
owner: context.repo.owner,
repo: context.repo.repo
})
- name: Add label - name: Add label
if: ${{ needs.analyze.outputs.results }} if: ${{ needs.analyze.outputs.results }}
uses: actions/github-script@v5 uses: actions/github-script@v5

View File

@ -91,11 +91,8 @@ export default class Analyzer extends Command {
const pluginData = this.getPluginData( flags.plugin ); const pluginData = this.getPluginData( flags.plugin );
this.log( `${ pluginData[ 1 ] } Version: ${ pluginData[ 0 ] }` ); this.log( `${ pluginData[ 1 ] } Version: ${ pluginData[ 0 ] }` );
// Avoid running this on CI for now, and only run schema diffs in the monorepo. // Run schema diffs only in the monorepo.
if ( if ( flags.source === 'woocommerce/woocommerce' ) {
flags.output === 'console' &&
flags.source === 'woocommerce/woocommerce'
) {
const schemaDiff = await generateSchemaDiff( const schemaDiff = await generateSchemaDiff(
flags.source, flags.source,
args.compare, args.compare,
@ -202,6 +199,7 @@ export default class Analyzer extends Command {
description: string; description: string;
base: string; base: string;
compare: string; compare: string;
method: string;
areEqual: boolean; areEqual: boolean;
}; };
} | void } | void

View File

@ -169,6 +169,7 @@ export const generateSchemaDiff = async (
description: string; description: string;
base: string; base: string;
compare: string; compare: string;
method: string;
areEqual: boolean; areEqual: boolean;
}; };
} | void > => { } | void > => {
@ -188,12 +189,15 @@ export const generateSchemaDiff = async (
description: 'WooCommerce Base Schema', description: 'WooCommerce Base Schema',
base: baseSchema.schema, base: baseSchema.schema,
compare: compareSchema.schema, compare: compareSchema.schema,
method: 'WC_Install->get_schema',
areEqual: baseSchema.schema === compareSchema.schema, areEqual: baseSchema.schema === compareSchema.schema,
}, },
OrdersTableDataStore: { OrdersTableDataStore: {
description: 'OrdersTableDataStore Schema', description: 'OrdersTableDataStore Schema',
base: baseSchema.OrdersTableDataStore, base: baseSchema.OrdersTableDataStore,
compare: compareSchema.OrdersTableDataStore, compare: compareSchema.OrdersTableDataStore,
method:
'Automattic\\WooCommerce\\Internal\\DataStores\\Orders\\OrdersTableDataStore->get_database_schema',
areEqual: areEqual:
baseSchema.OrdersTableDataStore === baseSchema.OrdersTableDataStore ===
compareSchema.OrdersTableDataStore, compareSchema.OrdersTableDataStore,

View File

@ -69,6 +69,7 @@ export const printHookResults = (
log( `::set-output name=wphooks::${ opt }` ); log( `::set-output name=wphooks::${ opt }` );
} else { } else {
log( `\n## ${ title }:` ); log( `\n## ${ title }:` );
log( '---------------------------------------------------' );
for ( const [ key, value ] of data ) { for ( const [ key, value ] of data ) {
if ( value.size ) { if ( value.size ) {
log( 'FILE: ' + key ); log( 'FILE: ' + key );
@ -104,6 +105,7 @@ export const printSchemaChange = (
description: string; description: string;
base: string; base: string;
compare: string; compare: string;
method: string;
areEqual: boolean; areEqual: boolean;
}; };
} | void, } | void,
@ -115,7 +117,14 @@ export const printSchemaChange = (
return; return;
} }
if ( output === 'github' ) { if ( output === 'github' ) {
// Add Github output here. let githubCommentContent = '\\n\\n### New schema changes:';
Object.keys( schemaDiff ).forEach( ( key ) => {
if ( ! schemaDiff[ key ].areEqual ) {
githubCommentContent += `\\n* **Schema:** ${ schemaDiff[ key ].method } introduced in ${ version }`;
}
} );
log( `::set-output name=schema::${ githubCommentContent }` );
} else { } else {
log( '\n## SCHEMA CHANGES' ); log( '\n## SCHEMA CHANGES' );
log( '---------------------------------------------------' ); log( '---------------------------------------------------' );
@ -123,7 +132,7 @@ export const printSchemaChange = (
Object.keys( schemaDiff ).forEach( ( key ) => { Object.keys( schemaDiff ).forEach( ( key ) => {
if ( ! schemaDiff[ key ].areEqual ) { if ( ! schemaDiff[ key ].areEqual ) {
log( log(
` NOTICE | Schema changes detected in ${ schemaDiff[ key ].description } as of ${ version }` ` NOTICE | Schema changes detected in ${ schemaDiff[ key ].method } as of ${ version }`
); );
log( '---------------------------------------------------' ); log( '---------------------------------------------------' );
} }
@ -148,7 +157,8 @@ export const printDatabaseUpdates = (
log: ( s: string ) => void log: ( s: string ) => void
): void => { ): void => {
if ( output === 'github' ) { if ( output === 'github' ) {
// Add Github output here. const githubCommentContent = `\\n\\n### New database updates:\\n * **${ updateFunctionName }** introduced in ${ updateFunctionVersion }`;
log( `::set-output name=database::${ githubCommentContent }` );
} else { } else {
log( '\n## DATABASE UPDATES' ); log( '\n## DATABASE UPDATES' );
log( '---------------------------------------------------' ); log( '---------------------------------------------------' );

View File

@ -126,7 +126,11 @@ export const startWPEnv = async ( error: ( s: string ) => void ) => {
cwd: 'plugins/woocommerce', cwd: 'plugins/woocommerce',
encoding: 'utf-8', encoding: 'utf-8',
} ); } );
} catch ( e ) {
// If an error is produced here, it means wp-env is not initialized and therefor not running already.
}
try {
if ( await isWPEnvPortTaken() ) { if ( await isWPEnvPortTaken() ) {
throw new Error( throw new Error(
'Unable to start wp-env. Make sure port 8888 is available or specify port number WP_ENV_PORT in .wp-env.override.json' 'Unable to start wp-env. Make sure port 8888 is available or specify port number WP_ENV_PORT in .wp-env.override.json'