From 81a4c4cdf0c6bf81b2ec86a62721f54b06b6ebba Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Mon, 4 Mar 2024 11:23:59 +0000 Subject: [PATCH] Build/Test Tools: Fix the `precommit:emoji` script. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../callable-test-core-build-process.yml | 5 ++++ Gruntfile.js | 23 +++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/callable-test-core-build-process.yml b/.github/workflows/callable-test-core-build-process.yml index 1ba3c9108f..d63aa904ad 100644 --- a/.github/workflows/callable-test-core-build-process.yml +++ b/.github/workflows/callable-test-core-build-process.yml @@ -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' || '' }} diff --git a/Gruntfile.js b/Gruntfile.js index 7d6981248f..a99dcb4104 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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, '' );