Skip to content

Commit

Permalink
Add CI check for newspack-blocks textdomain (#44323)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
noahtallen authored Jul 23, 2020
1 parent bd71a36 commit 5012986
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/full-site-editing-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
14 changes: 14 additions & 0 deletions apps/full-site-editing/bin/newspack-block-sync-phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<ruleset name="newspack-blocks">
<description>Detect issues with newspack blocks sync</description>

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="full-site-editing"/>
</property>
</properties>
</rule>

<file>../full-site-editing-plugin/newspack-blocks/synced-newspack-blocks</file>
</ruleset>
22 changes: 19 additions & 3 deletions apps/full-site-editing/bin/npm-run-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand 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.' );
}
}
} );
7 changes: 6 additions & 1 deletion apps/full-site-editing/bin/sync-newspack-blocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions apps/full-site-editing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-*",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 5012986

Please sign in to comment.