From 5012986c4a3c298b33758fd8746ebb6033f04359 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Thu, 23 Jul 2020 14:44:53 -0700 Subject: [PATCH] Add CI check for newspack-blocks textdomain (#44323) * Move newspack block sync to build instead of install * Add phpcs and run step for newspack-blocks * Fix workflow name * TEMP: remove phpcbf to trigger build failure * Add back phpcbf with error condition * TEMP: remove newspack-blocks sync to test build failure * Add back sync step * Fail build script on errors. * Add helpful error message to build failure * Add back composer install * Use exitCode, add error message * Explicitly call sync instead of using prescript Prescript will be removed in the future (yarn2) --- .../workflows/full-site-editing-plugin.yml | 32 +++++++++++++++++++ .../bin/newspack-block-sync-phpcs.xml | 14 ++++++++ apps/full-site-editing/bin/npm-run-build.js | 22 +++++++++++-- .../bin/sync-newspack-blocks.sh | 7 +++- apps/full-site-editing/package.json | 5 ++- 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 apps/full-site-editing/bin/newspack-block-sync-phpcs.xml diff --git a/.github/workflows/full-site-editing-plugin.yml b/.github/workflows/full-site-editing-plugin.yml index 43e1d78bd67ba4..9a699902b34e14 100644 --- a/.github/workflows/full-site-editing-plugin.yml +++ b/.github/workflows/full-site-editing-plugin.yml @@ -33,6 +33,11 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' run: yarn install --frozen-lockfile # Not needed when restoring from cache. + - name: Run composer + uses: nick-zh/composer-php@HEAD + with: + action: 'install' + - name: Build packages if: steps.cache.outputs.cache-hit == 'true' run: yarn run postinstall # Needed only when not running yarn install. @@ -140,3 +145,30 @@ jobs: - name: No changes found run: echo "No changes found to check!" if: ${{ steps.changes.outputs.all == '' }} + + newspack-blocks: + name: Check newspack-blocks sync + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@HEAD + + # It saves a bit of time to download the artifact rather than doing a build. + - name: Get build + uses: actions/download-artifact@HEAD + with: + name: fse-build-archive + path: apps/full-site-editing/full-site-editing-plugin + + - name: Check if newspack-blocks exists + run: test -f ./apps/full-site-editing/full-site-editing-plugin/newspack-blocks/synced-newspack-blocks/class-newspack-blocks.php + + - name: Run composer + uses: nick-zh/composer-php@HEAD + with: + action: 'install' + + # This will fail if the textdomain has not been changed to full-site-editing, which indicates an issue with the sync or build scripts. + - name: Execute phpcs on newspack-blocks PHP files. + run: ./vendor/bin/phpcs --standard=apps/full-site-editing/bin/newspack-block-sync-phpcs.xml \ No newline at end of file diff --git a/apps/full-site-editing/bin/newspack-block-sync-phpcs.xml b/apps/full-site-editing/bin/newspack-block-sync-phpcs.xml new file mode 100644 index 00000000000000..65a3444c60491b --- /dev/null +++ b/apps/full-site-editing/bin/newspack-block-sync-phpcs.xml @@ -0,0 +1,14 @@ + + + Detect issues with newspack blocks sync + + + + + + + + + + ../full-site-editing-plugin/newspack-blocks/synced-newspack-blocks + diff --git a/apps/full-site-editing/bin/npm-run-build.js b/apps/full-site-editing/bin/npm-run-build.js index 037e3418e36604..967f31789cbd88 100644 --- a/apps/full-site-editing/bin/npm-run-build.js +++ b/apps/full-site-editing/bin/npm-run-build.js @@ -4,6 +4,7 @@ /* eslint-disable import/no-nodejs-modules */ /* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable no-console */ +/* eslint-disable no-process-exit */ const runAll = require( 'npm-run-all' ); @@ -26,6 +27,21 @@ const runOptions = { printLabel: true, }; -runAll( commands, runOptions ).then( () => { - console.log( 'Finished running commands!' ); -} ); +runAll( commands, runOptions ) + .then( () => { + console.log( 'Finished running commands!' ); + } ) + .catch( ( e ) => { + process.exitCode = 1; + console.log( 'The build failed.' ); + console.log( `Reported build error: ${ e.message }` ); + const tasks = e.results; + if ( Array.isArray( tasks ) ) { + const didNewspackSyncFail = tasks.some( + ( task ) => task.name === 'build:newspack-blocks' && task.code !== 0 + ); + if ( didNewspackSyncFail ) { + console.log( 'You may need to run `composer install` from wp-calypso root.' ); + } + } + } ); diff --git a/apps/full-site-editing/bin/sync-newspack-blocks.sh b/apps/full-site-editing/bin/sync-newspack-blocks.sh index 26218ae13fcfd5..86d09c14eb7269 100755 --- a/apps/full-site-editing/bin/sync-newspack-blocks.sh +++ b/apps/full-site-editing/bin/sync-newspack-blocks.sh @@ -129,7 +129,12 @@ echo -n "eslint --fix: " npx eslint . --fix > /dev/null 2>&1 echo "done" echo -n "phpcbf: " -../../vendor/bin/phpcbf -q $TARGET | grep "A TOTAL OF" || echo '!! There was an error executing phpcbf' +../../vendor/bin/phpcbf -q $TARGET | grep "A TOTAL OF" || PHPCBF_ERRORED=1 + +if [ "$PHPCBF_ERRORED" = 1 ] ; then + echo '!! There was an error executing phpcbf!' + exit 1 +fi if [ "$MODE" = "npm" ] ; then # Finds and prints the version of newspack from package.json diff --git a/apps/full-site-editing/package.json b/apps/full-site-editing/package.json index 9dfcd522a2f29e..c31d3944aca620 100644 --- a/apps/full-site-editing/package.json +++ b/apps/full-site-editing/package.json @@ -37,7 +37,7 @@ "editor-site-launch": "check-npm-client && calypso-build --source='editor-site-launch'", "dev:editor-site-launch": "check-npm-client && yarn run editor-site-launch", "build:editor-site-launch": "check-npm-client && NODE_ENV=production yarn run editor-site-launch", - "newspack-blocks": "check-npm-client && npm-run-all --parallel newspack-blocks-*", + "newspack-blocks": "check-npm-client && npm run sync:newspack-blocks -- --nodemodules && npm-run-all --parallel newspack-blocks-*", "newspack-blog-posts-block-editor": "check-npm-client && calypso-build --source='newspack-blocks/blog-posts-block-editor'", "newspack-blog-posts-block-view": "check-npm-client && calypso-build --source='newspack-blocks/blog-posts-block-view'", "newspack-blocks-blog-posts-block": "check-npm-client && npm-run-all --parallel newspack-blog-posts-block-*", @@ -88,8 +88,7 @@ "prebuild": "check-npm-client && yarn run clean", "predev": "check-npm-client && yarn run clean", "sync:newspack-blocks": "check-npm-client && ./bin/sync-newspack-blocks.sh", - "wpcom-sync": "check-npm-client && ./bin/wpcom-watch-and-sync.sh", - "prepare": "check-npm-client && yarn run sync:newspack-blocks --nodemodules" + "wpcom-sync": "check-npm-client && ./bin/wpcom-watch-and-sync.sh" }, "dependencies": { "@automattic/calypso-analytics": "^1.0.0-alpha.1",