Build/Test Tools: Fix the precommit:emoji script.

GitHub recently sunset support for Subversion, causing the `precommit:emoji` Grunt script to break. Since there’s no direct replacement for `svn ls` in Git, this has been replaced with a query through the GitHub CLI.

This also adds a step in the workflow that tests the build process to run the `precommit:emoji` script to ensure no changes to built files are missed when updating the Twemoji library in the future.

Follow up to [57626].

Props kraftbj, peterwilsoncc, swissspidy.
Fixes #60520. See #57600.

git-svn-id: https://develop.svn.wordpress.org/trunk@57758 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2024-03-04 11:23:59 +00:00
parent 79f570a7a2
commit 81a4c4cdf0
2 changed files with 24 additions and 4 deletions

View File

@ -62,6 +62,11 @@ jobs:
- name: Install npm Dependencies
run: npm ci
- name: Run Emoji precommit task
run: npm run grunt precommit:emoji
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build WordPress to run from ${{ inputs.directory }}
run: npm run build${{ inputs.directory == 'src' && ':dev' || '' }}

View File

@ -1047,19 +1047,34 @@ module.exports = function(grunt) {
{
match: /\/\/ START: emoji arrays[\S\s]*\/\/ END: emoji arrays/g,
replacement: function() {
var regex, files,
var regex, files, ghCli,
partials, partialsSet,
entities, emojiArray;
entities, emojiArray,
apiResponse, query;
grunt.log.writeln( 'Fetching list of Twemoji files...' );
// Ensure that the GitHub CLI is installed.
ghCli = spawn( 'gh', [ '--version' ] );
if ( 0 !== ghCli.status ) {
grunt.fatal( 'Emoji precommit script requires GitHub CLI. See https://cli.github.com/.' );
}
// Fetch a list of the files that Twemoji supplies.
files = spawn( 'svn', [ 'ls', 'https://github.com/twitter/twemoji.git/trunk/assets/svg' ] );
query = 'query={repository(owner: "jdecked", name: "twemoji") {object(expression: "v15.0.3:assets/svg") {... on Tree {entries {name}}}}}';
files = spawn( 'gh', [ 'api', 'graphql', '-f', query] );
if ( 0 !== files.status ) {
grunt.fatal( 'Unable to fetch Twemoji file list' );
}
entities = files.stdout.toString();
try {
apiResponse = JSON.parse( files.stdout.toString() );
} catch ( e ) {
grunt.fatal( 'Unable to parse Twemoji file list' );
}
entities = apiResponse.data.repository.object.entries;
entities = entities.reduce( function( accumulator, val ) { return accumulator + val.name + '\n'; }, '' );
// Tidy up the file list.
entities = entities.replace( /\.svg/g, '' );