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

View File

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

View File

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

View File

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

View File

@ -126,7 +126,11 @@ export const startWPEnv = async ( error: ( s: string ) => void ) => {
cwd: 'plugins/woocommerce',
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() ) {
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'