Skip to content

Commit

Permalink
Merge pull request #1221 from WordPress/update/version-bumps
Browse files Browse the repository at this point in the history
Bump plugin versions and add versions command to verify version consistency in plugins

Co-authored-by: westonruter <[email protected]>
Co-authored-by: joemcgill <[email protected]>
  • Loading branch information
3 people authored May 17, 2024
2 parents 074f962 + f33ef9b commit a4b2672
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deploy-standalone-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
9 changes: 9 additions & 0 deletions bin/plugin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand All @@ -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 );
157 changes: 157 additions & 0 deletions bin/plugin/commands/versions.js
Original file line number Diff line number Diff line change
@@ -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 <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<string>} 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 <https://github.com/WordPress/performance/pull/1182>.
}

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.`
);
}
};
4 changes: 2 additions & 2 deletions load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' );
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions plugins/auto-sizes/auto-sizes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
6 changes: 5 additions & 1 deletion plugins/auto-sizes/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions plugins/dominant-color-images/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
6 changes: 5 additions & 1 deletion plugins/dominant-color-images/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions plugins/embed-optimizer/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
6 changes: 5 additions & 1 deletion plugins/embed-optimizer/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions plugins/optimization-detective/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion plugins/optimization-detective/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions plugins/speculation-rules/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit a4b2672

Please sign in to comment.