From 7e69806999260fb01817640020e72c94c31690f6 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 16 May 2024 17:46:41 -0700 Subject: [PATCH 1/3] Bump versions across plugins and add changelog entries --- load.php | 4 ++-- plugins/auto-sizes/auto-sizes.php | 4 ++-- plugins/auto-sizes/readme.txt | 6 +++++- plugins/dominant-color-images/load.php | 4 ++-- plugins/dominant-color-images/readme.txt | 6 +++++- plugins/embed-optimizer/load.php | 4 ++-- plugins/embed-optimizer/readme.txt | 6 +++++- plugins/optimization-detective/load.php | 4 ++-- plugins/optimization-detective/readme.txt | 6 +++++- plugins/speculation-rules/load.php | 4 ++-- plugins/speculation-rules/readme.txt | 6 +++++- plugins/webp-uploads/load.php | 4 ++-- plugins/webp-uploads/readme.txt | 6 +++++- readme.txt | 6 +++++- 14 files changed, 49 insertions(+), 21 deletions(-) diff --git a/load.php b/load.php index 5140c42893..4ee61dc53b 100644 --- a/load.php +++ b/load.php @@ -5,7 +5,7 @@ * Description: Performance plugin from the WordPress Performance Team, which is a collection of standalone performance features. * Requires at least: 6.4 * Requires PHP: 7.2 - * Version: 3.0.0 + * Version: 3.1.0 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -19,7 +19,7 @@ exit; // Exit if accessed directly. } -define( 'PERFLAB_VERSION', '3.0.0' ); +define( 'PERFLAB_VERSION', '3.1.0' ); define( 'PERFLAB_MAIN_FILE', __FILE__ ); define( 'PERFLAB_PLUGIN_DIR_PATH', plugin_dir_path( PERFLAB_MAIN_FILE ) ); define( 'PERFLAB_SCREEN', 'performance-lab' ); diff --git a/plugins/auto-sizes/auto-sizes.php b/plugins/auto-sizes/auto-sizes.php index 2e8a06fe59..2611385061 100644 --- a/plugins/auto-sizes/auto-sizes.php +++ b/plugins/auto-sizes/auto-sizes.php @@ -5,7 +5,7 @@ * Description: Instructs browsers to automatically choose the right image size for lazy-loaded images. * Requires at least: 6.4 * Requires PHP: 7.2 - * Version: 1.0.1 + * Version: 1.0.2 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -25,6 +25,6 @@ return; } -define( 'IMAGE_AUTO_SIZES_VERSION', '1.0.1' ); +define( 'IMAGE_AUTO_SIZES_VERSION', '1.0.2' ); require_once __DIR__ . '/hooks.php'; diff --git a/plugins/auto-sizes/readme.txt b/plugins/auto-sizes/readme.txt index 6694cd808b..ac5cd51582 100644 --- a/plugins/auto-sizes/readme.txt +++ b/plugins/auto-sizes/readme.txt @@ -4,7 +4,7 @@ Contributors: wordpressdotorg Requires at least: 6.4 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 1.0.1 +Stable tag: 1.0.2 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, images, auto-sizes @@ -48,6 +48,10 @@ Contributions are always welcome! Learn more about how to get involved in the [C == Changelog == += 1.0.2 = + +* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775)) + = 1.0.1 = * Add auto-sizes generator tag. ([1105](https://github.com/WordPress/performance/pull/1105)) diff --git a/plugins/dominant-color-images/load.php b/plugins/dominant-color-images/load.php index b55d0c6c8a..1ca1c86ce7 100644 --- a/plugins/dominant-color-images/load.php +++ b/plugins/dominant-color-images/load.php @@ -5,7 +5,7 @@ * Description: Displays placeholders based on an image's dominant color while the image is loading. * Requires at least: 6.4 * Requires PHP: 7.2 - * Version: 1.1.0 + * Version: 1.1.1 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -25,7 +25,7 @@ return; } -define( 'DOMINANT_COLOR_IMAGES_VERSION', '1.1.0' ); +define( 'DOMINANT_COLOR_IMAGES_VERSION', '1.1.1' ); require_once __DIR__ . '/helper.php'; require_once __DIR__ . '/hooks.php'; diff --git a/plugins/dominant-color-images/readme.txt b/plugins/dominant-color-images/readme.txt index 8d84a395fc..ef2d210c6a 100644 --- a/plugins/dominant-color-images/readme.txt +++ b/plugins/dominant-color-images/readme.txt @@ -4,7 +4,7 @@ Contributors: wordpressdotorg Requires at least: 6.4 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 1.1.0 +Stable tag: 1.1.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, images, dominant color @@ -49,6 +49,10 @@ Contributions are always welcome! Learn more about how to get involved in the [C == Changelog == += 1.1.1 = + +* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775)) + = 1.1.0 = * Rename plugin to "Image Placeholders". ([1101](https://github.com/WordPress/performance/pull/1101)) diff --git a/plugins/embed-optimizer/load.php b/plugins/embed-optimizer/load.php index ebc93dad50..a92c948ea9 100644 --- a/plugins/embed-optimizer/load.php +++ b/plugins/embed-optimizer/load.php @@ -5,7 +5,7 @@ * Description: Optimizes the performance of embeds by lazy-loading iframes and scripts. * Requires at least: 6.4 * Requires PHP: 7.2 - * Version: 0.1.1 + * Version: 0.1.2 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -20,7 +20,7 @@ exit; } -define( 'EMBED_OPTIMIZER_VERSION', '0.1.1' ); +define( 'EMBED_OPTIMIZER_VERSION', '0.1.2' ); // Load in the Embed Optimizer plugin hooks. require_once __DIR__ . '/hooks.php'; diff --git a/plugins/embed-optimizer/readme.txt b/plugins/embed-optimizer/readme.txt index 3063158126..e88a31285f 100644 --- a/plugins/embed-optimizer/readme.txt +++ b/plugins/embed-optimizer/readme.txt @@ -4,7 +4,7 @@ Contributors: wordpressdotorg Requires at least: 6.4 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 0.1.1 +Stable tag: 0.1.2 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, embeds @@ -49,6 +49,10 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu == Changelog == += 0.1.2 = + +* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775)) + = 0.1.1 = * Use plugin slug for generator tag. ([1103](https://github.com/WordPress/performance/pull/1103)) diff --git a/plugins/optimization-detective/load.php b/plugins/optimization-detective/load.php index 52af073d3a..7c571333ec 100644 --- a/plugins/optimization-detective/load.php +++ b/plugins/optimization-detective/load.php @@ -5,7 +5,7 @@ * Description: Uses real user metrics to improve heuristics WordPress applies on the frontend to improve image loading priority. * Requires at least: 6.4 * Requires PHP: 7.2 - * Version: 0.1.1 + * Version: 0.2.0 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -65,7 +65,7 @@ static function ( string $global_var_name, string $version, Closure $load ): voi } )( 'optimization_detective_pending_plugin', - '0.1.1', + '0.2.0', static function ( string $version ): void { // Define the constant. diff --git a/plugins/optimization-detective/readme.txt b/plugins/optimization-detective/readme.txt index 0b643634ff..9e042c0a85 100644 --- a/plugins/optimization-detective/readme.txt +++ b/plugins/optimization-detective/readme.txt @@ -4,7 +4,7 @@ Contributors: wordpressdotorg Requires at least: 6.4 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 0.1.1 +Stable tag: 0.2.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, images @@ -137,6 +137,10 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu == Changelog == += 0.2.0 = + +* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775)) + = 0.1.1 = * Use plugin slug for generator tag. ([1103](https://github.com/WordPress/performance/pull/1103)) diff --git a/plugins/speculation-rules/load.php b/plugins/speculation-rules/load.php index 38865bc1b9..0730ea84a1 100644 --- a/plugins/speculation-rules/load.php +++ b/plugins/speculation-rules/load.php @@ -5,7 +5,7 @@ * Description: Enables browsers to speculatively prerender or prefetch pages when hovering over links. * Requires at least: 6.4 * Requires PHP: 7.2 - * Version: 1.2.2 + * Version: 1.3.0 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -65,7 +65,7 @@ static function ( string $global_var_name, string $version, Closure $load ): voi } )( 'plsr_pending_plugin_info', - '1.2.2', + '1.3.0', static function ( string $version ): void { // Define the constant. diff --git a/plugins/speculation-rules/readme.txt b/plugins/speculation-rules/readme.txt index fc268e1b22..195453642f 100644 --- a/plugins/speculation-rules/readme.txt +++ b/plugins/speculation-rules/readme.txt @@ -4,7 +4,7 @@ Contributors: wordpressdotorg Requires at least: 6.4 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 1.2.2 +Stable tag: 1.3.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, javascript, speculation rules, prerender, prefetch @@ -114,6 +114,10 @@ Contributions are always welcome! Learn more about how to get involved in the [C == Changelog == += 1.3.0 = + +* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775)) + = 1.2.2 = **Bug Fixes** diff --git a/plugins/webp-uploads/load.php b/plugins/webp-uploads/load.php index 866d218df0..eee5e7ba96 100644 --- a/plugins/webp-uploads/load.php +++ b/plugins/webp-uploads/load.php @@ -5,7 +5,7 @@ * Description: Converts images to more modern formats such as WebP or AVIF during upload. * Requires at least: 6.4 * Requires PHP: 7.2 - * Version: 1.1.0 + * Version: 1.1.1 * Author: WordPress Performance Team * Author URI: https://make.wordpress.org/performance/ * License: GPLv2 or later @@ -25,7 +25,7 @@ return; } -define( 'WEBP_UPLOADS_VERSION', '1.1.0' ); +define( 'WEBP_UPLOADS_VERSION', '1.1.1' ); define( 'WEBP_UPLOADS_MAIN_FILE', plugin_basename( __FILE__ ) ); require_once __DIR__ . '/helper.php'; diff --git a/plugins/webp-uploads/readme.txt b/plugins/webp-uploads/readme.txt index af8d8aad72..a1e33e8826 100644 --- a/plugins/webp-uploads/readme.txt +++ b/plugins/webp-uploads/readme.txt @@ -4,7 +4,7 @@ Contributors: wordpressdotorg Requires at least: 6.4 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 1.1.0 +Stable tag: 1.1.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, images, webp @@ -60,6 +60,10 @@ By default, the Modern Image Formats plugin will only generate WebP versions of == Changelog == += 1.1.1 = + +* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775)) + = 1.1.0 = * Add link to WebP settings to plugins table. ([1036](https://github.com/WordPress/performance/pull/1036)) diff --git a/readme.txt b/readme.txt index 225c3472f8..ffd48a2002 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: wordpressdotorg Requires at least: 6.4 Tested up to: 6.5 Requires PHP: 7.2 -Stable tag: 3.0.0 +Stable tag: 3.1.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Tags: performance, site health, measurement, optimization, diagnostics @@ -60,6 +60,10 @@ Contributions are always welcome! Learn more about how to get involved in the [C == Changelog == += 3.1.0 = + +* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775)) + = 3.0.0 = **Enhancements** From ae9c52c8a5d18ee724f1d1654a72cd9ed8011e3d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 16 May 2024 17:50:59 -0700 Subject: [PATCH 2/3] Add versions command to check for version consistency across plugins --- bin/plugin/cli.js | 9 ++ bin/plugin/commands/versions.js | 157 ++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 167 insertions(+) create mode 100644 bin/plugin/commands/versions.js diff --git a/bin/plugin/cli.js b/bin/plugin/cli.js index 8cb778b24e..6a1bfd8f43 100755 --- a/bin/plugin/cli.js +++ b/bin/plugin/cli.js @@ -43,6 +43,10 @@ const { handler: sinceHandler, options: sinceOptions, } = require( './commands/since' ); +const { + handler: versionsHandler, + options: versionsOptions, +} = require( './commands/versions' ); withOptions( program.command( 'release-plugin-changelog' ), changelogOptions ) .alias( 'changelog' ) @@ -59,4 +63,9 @@ withOptions( program.command( 'plugin-readme' ), readmeOptions ) .description( 'Updates the readme.txt file' ) .action( catchException( readmeHandler ) ); +withOptions( program.command( 'verify-version-consistency' ), versionsOptions ) + .alias( 'versions' ) + .description( 'Verifies consistency of versions in plugins' ) + .action( catchException( versionsHandler ) ); + program.parse( process.argv ); diff --git a/bin/plugin/commands/versions.js b/bin/plugin/commands/versions.js new file mode 100644 index 0000000000..e8bf01fe95 --- /dev/null +++ b/bin/plugin/commands/versions.js @@ -0,0 +1,157 @@ +/** + * External dependencies + */ +const fs = require( 'fs' ); +const path = require( 'path' ); +const glob = require( 'fast-glob' ); +const { log, formats } = require( '../lib/logger' ); + +/** + * Internal dependencies + */ +const { plugins } = require( '../../../plugins.json' ); + +/** + * @typedef WPVersionsCommandOptions + * + * @property {?string} plugin Plugin slug. + */ + +exports.options = [ + { + argname: '-p, --plugin ', + description: 'Plugin slug', + defaults: null, + }, +]; + +/** + * Checks a plugin directory for the required versions. + * + * @throws Error When there are inconsistent versions. + * + * @param {string} pluginDirectory + * @return {Promise} Consistent version. + */ +async function checkPluginDirectory( pluginDirectory ) { + const readmeContents = fs.readFileSync( + path.resolve( pluginDirectory, 'readme.txt' ), + 'utf-8' + ); + + const stableTagVersionMatches = readmeContents.match( + /^Stable tag:\s*(\d+\.\d+\.\d+)$/m + ); + if ( ! stableTagVersionMatches ) { + throw new Error( 'Unable to locate stable tag in readme.txt' ); + } + const stableTagVersion = stableTagVersionMatches[ 1 ]; + + const latestChangelogMatches = readmeContents.match( + /^== Changelog ==\n+= (\d+\.\d+\.\d+) =$/m + ); + if ( ! latestChangelogMatches ) { + throw new Error( + 'Unable to latest version entry in readme changelog.' + ); + } + const latestChangelogVersion = latestChangelogMatches[ 1 ]; + + // Find the bootstrap file. + let phpBootstrapFileContents = null; + for ( const phpFile of await glob( + path.resolve( pluginDirectory, '*.php' ) + ) ) { + const phpFileContents = fs.readFileSync( phpFile, 'utf-8' ); + if ( /^<\?php\n\/\*\*\n \* Plugin Name:/.test( phpFileContents ) ) { + phpBootstrapFileContents = phpFileContents; + break; + } + } + if ( ! phpBootstrapFileContents ) { + throw new Error( 'Unable to locate the PHP bootstrap file.' ); + } + + const headerVersionMatches = phpBootstrapFileContents.match( + /^ \* Version:\s+(\d+\.\d+\.\d+)$/m + ); + if ( ! headerVersionMatches ) { + throw new Error( + 'Unable to locate version in plugin PHP bootstrap file header.' + ); + } + const headerVersion = headerVersionMatches[ 1 ]; + + const phpLiteralVersionMatches = + phpBootstrapFileContents.match( /'(\d+\.\d+\.\d+?)'/ ); + if ( ! phpLiteralVersionMatches ) { + throw new Error( 'Unable to locate the PHP literal version.' ); + } + const phpLiteralVersion = phpLiteralVersionMatches[ 1 ]; + + const allVersions = [ + stableTagVersion, + latestChangelogVersion, + headerVersion, + phpLiteralVersion, + ]; + + if ( ! allVersions.every( ( version ) => version === stableTagVersion ) ) { + throw new Error( + `Version mismatch: ${ JSON.stringify( { + latestChangelogVersion, + headerVersion, + stableTagVersion, + phpLiteralVersion, + } ) }` + ); + } + + return stableTagVersion; +} + +/** + * Checks that the versions are consistent across all plugins, including in: + * + * - Plugin bootstrap header metadata comment. + * - Plugin bootstrap PHP literal (e.g. constant). + * - The 'Stable tag' in readme.txt. + * - The most recent changelog entry in readme.txt. + * + * @param {WPVersionsCommandOptions} opt Command options. + */ +exports.handler = async ( opt ) => { + const pluginRoot = path.resolve( __dirname, '../../../' ); + + const pluginDirectories = []; + + if ( ! opt.plugin || 'performance-lab' === opt.plugin ) { + pluginDirectories.push( pluginRoot ); // TODO: Remove this after . + } + + for ( const pluginSlug of plugins ) { + if ( ! opt.plugin || pluginSlug === opt.plugin ) { + pluginDirectories.push( + path.resolve( pluginRoot, 'plugins', pluginSlug ) + ); + } + } + + let errorCount = 0; + for ( const pluginDirectory of pluginDirectories ) { + const slug = path.basename( pluginDirectory ); + try { + const version = await checkPluginDirectory( pluginDirectory ); + log( formats.success( `✅ ${ slug }: ${ version } ` ) ); + } catch ( error ) { + errorCount++; + log( formats.error( `❌ ${ slug }: ${ error.message }` ) ); + } + } + + if ( errorCount > 0 ) { + throw new Error( + `There are ${ errorCount } plugin(s) with inconsistent versions.` + ); + } +}; diff --git a/package.json b/package.json index 2bac718e88..265a90ae40 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "changelog": "./bin/plugin/cli.js changelog", "since": "./bin/plugin/cli.js since", "readme": "./bin/plugin/cli.js readme", + "versions": "./bin/plugin/cli.js versions", "build": "wp-scripts build", "build-plugins": "npm-run-all 'build:plugin:!(performance-lab)'", "build:plugin:performance-lab": "rm -rf build/performance-lab && mkdir -p build/performance-lab && git archive HEAD | tar -x -C build/performance-lab", From f33ef9bda09332f570cc641b80207ee9d4815829 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 16 May 2024 18:04:36 -0700 Subject: [PATCH 3/3] Check plugin versions when releasing standalone plugins --- .github/workflows/deploy-standalone-plugins.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/deploy-standalone-plugins.yml b/.github/workflows/deploy-standalone-plugins.yml index 4fd129fc96..7bb8ee5a1d 100644 --- a/.github/workflows/deploy-standalone-plugins.yml +++ b/.github/workflows/deploy-standalone-plugins.yml @@ -69,6 +69,9 @@ jobs: - name: Install npm dependencies run: npm ci + - name: Check plugin versions + run: npm run versions -- --plugin=${{ matrix.plugin }} + - name: Build plugin run: npm run build:plugin:${{ matrix.plugin }}