Skip to content

Commit a4b2672

Browse files
Merge pull request #1221 from WordPress/update/version-bumps
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]>
2 parents 074f962 + f33ef9b commit a4b2672

File tree

18 files changed

+219
-21
lines changed

18 files changed

+219
-21
lines changed

.github/workflows/deploy-standalone-plugins.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ jobs:
6969
- name: Install npm dependencies
7070
run: npm ci
7171

72+
- name: Check plugin versions
73+
run: npm run versions -- --plugin=${{ matrix.plugin }}
74+
7275
- name: Build plugin
7376
run: npm run build:plugin:${{ matrix.plugin }}
7477

bin/plugin/cli.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ const {
4343
handler: sinceHandler,
4444
options: sinceOptions,
4545
} = require( './commands/since' );
46+
const {
47+
handler: versionsHandler,
48+
options: versionsOptions,
49+
} = require( './commands/versions' );
4650

4751
withOptions( program.command( 'release-plugin-changelog' ), changelogOptions )
4852
.alias( 'changelog' )
@@ -59,4 +63,9 @@ withOptions( program.command( 'plugin-readme' ), readmeOptions )
5963
.description( 'Updates the readme.txt file' )
6064
.action( catchException( readmeHandler ) );
6165

66+
withOptions( program.command( 'verify-version-consistency' ), versionsOptions )
67+
.alias( 'versions' )
68+
.description( 'Verifies consistency of versions in plugins' )
69+
.action( catchException( versionsHandler ) );
70+
6271
program.parse( process.argv );

bin/plugin/commands/versions.js

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/**
2+
* External dependencies
3+
*/
4+
const fs = require( 'fs' );
5+
const path = require( 'path' );
6+
const glob = require( 'fast-glob' );
7+
const { log, formats } = require( '../lib/logger' );
8+
9+
/**
10+
* Internal dependencies
11+
*/
12+
const { plugins } = require( '../../../plugins.json' );
13+
14+
/**
15+
* @typedef WPVersionsCommandOptions
16+
*
17+
* @property {?string} plugin Plugin slug.
18+
*/
19+
20+
exports.options = [
21+
{
22+
argname: '-p, --plugin <plugin>',
23+
description: 'Plugin slug',
24+
defaults: null,
25+
},
26+
];
27+
28+
/**
29+
* Checks a plugin directory for the required versions.
30+
*
31+
* @throws Error When there are inconsistent versions.
32+
*
33+
* @param {string} pluginDirectory
34+
* @return {Promise<string>} Consistent version.
35+
*/
36+
async function checkPluginDirectory( pluginDirectory ) {
37+
const readmeContents = fs.readFileSync(
38+
path.resolve( pluginDirectory, 'readme.txt' ),
39+
'utf-8'
40+
);
41+
42+
const stableTagVersionMatches = readmeContents.match(
43+
/^Stable tag:\s*(\d+\.\d+\.\d+)$/m
44+
);
45+
if ( ! stableTagVersionMatches ) {
46+
throw new Error( 'Unable to locate stable tag in readme.txt' );
47+
}
48+
const stableTagVersion = stableTagVersionMatches[ 1 ];
49+
50+
const latestChangelogMatches = readmeContents.match(
51+
/^== Changelog ==\n+= (\d+\.\d+\.\d+) =$/m
52+
);
53+
if ( ! latestChangelogMatches ) {
54+
throw new Error(
55+
'Unable to latest version entry in readme changelog.'
56+
);
57+
}
58+
const latestChangelogVersion = latestChangelogMatches[ 1 ];
59+
60+
// Find the bootstrap file.
61+
let phpBootstrapFileContents = null;
62+
for ( const phpFile of await glob(
63+
path.resolve( pluginDirectory, '*.php' )
64+
) ) {
65+
const phpFileContents = fs.readFileSync( phpFile, 'utf-8' );
66+
if ( /^<\?php\n\/\*\*\n \* Plugin Name:/.test( phpFileContents ) ) {
67+
phpBootstrapFileContents = phpFileContents;
68+
break;
69+
}
70+
}
71+
if ( ! phpBootstrapFileContents ) {
72+
throw new Error( 'Unable to locate the PHP bootstrap file.' );
73+
}
74+
75+
const headerVersionMatches = phpBootstrapFileContents.match(
76+
/^ \* Version:\s+(\d+\.\d+\.\d+)$/m
77+
);
78+
if ( ! headerVersionMatches ) {
79+
throw new Error(
80+
'Unable to locate version in plugin PHP bootstrap file header.'
81+
);
82+
}
83+
const headerVersion = headerVersionMatches[ 1 ];
84+
85+
const phpLiteralVersionMatches =
86+
phpBootstrapFileContents.match( /'(\d+\.\d+\.\d+?)'/ );
87+
if ( ! phpLiteralVersionMatches ) {
88+
throw new Error( 'Unable to locate the PHP literal version.' );
89+
}
90+
const phpLiteralVersion = phpLiteralVersionMatches[ 1 ];
91+
92+
const allVersions = [
93+
stableTagVersion,
94+
latestChangelogVersion,
95+
headerVersion,
96+
phpLiteralVersion,
97+
];
98+
99+
if ( ! allVersions.every( ( version ) => version === stableTagVersion ) ) {
100+
throw new Error(
101+
`Version mismatch: ${ JSON.stringify( {
102+
latestChangelogVersion,
103+
headerVersion,
104+
stableTagVersion,
105+
phpLiteralVersion,
106+
} ) }`
107+
);
108+
}
109+
110+
return stableTagVersion;
111+
}
112+
113+
/**
114+
* Checks that the versions are consistent across all plugins, including in:
115+
*
116+
* - Plugin bootstrap header metadata comment.
117+
* - Plugin bootstrap PHP literal (e.g. constant).
118+
* - The 'Stable tag' in readme.txt.
119+
* - The most recent changelog entry in readme.txt.
120+
*
121+
* @param {WPVersionsCommandOptions} opt Command options.
122+
*/
123+
exports.handler = async ( opt ) => {
124+
const pluginRoot = path.resolve( __dirname, '../../../' );
125+
126+
const pluginDirectories = [];
127+
128+
if ( ! opt.plugin || 'performance-lab' === opt.plugin ) {
129+
pluginDirectories.push( pluginRoot ); // TODO: Remove this after <https://github.com/WordPress/performance/pull/1182>.
130+
}
131+
132+
for ( const pluginSlug of plugins ) {
133+
if ( ! opt.plugin || pluginSlug === opt.plugin ) {
134+
pluginDirectories.push(
135+
path.resolve( pluginRoot, 'plugins', pluginSlug )
136+
);
137+
}
138+
}
139+
140+
let errorCount = 0;
141+
for ( const pluginDirectory of pluginDirectories ) {
142+
const slug = path.basename( pluginDirectory );
143+
try {
144+
const version = await checkPluginDirectory( pluginDirectory );
145+
log( formats.success( `✅ ${ slug }: ${ version } ` ) );
146+
} catch ( error ) {
147+
errorCount++;
148+
log( formats.error( `❌ ${ slug }: ${ error.message }` ) );
149+
}
150+
}
151+
152+
if ( errorCount > 0 ) {
153+
throw new Error(
154+
`There are ${ errorCount } plugin(s) with inconsistent versions.`
155+
);
156+
}
157+
};

load.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Performance plugin from the WordPress Performance Team, which is a collection of standalone performance features.
66
* Requires at least: 6.4
77
* Requires PHP: 7.2
8-
* Version: 3.0.0
8+
* Version: 3.1.0
99
* Author: WordPress Performance Team
1010
* Author URI: https://make.wordpress.org/performance/
1111
* License: GPLv2 or later
@@ -19,7 +19,7 @@
1919
exit; // Exit if accessed directly.
2020
}
2121

22-
define( 'PERFLAB_VERSION', '3.0.0' );
22+
define( 'PERFLAB_VERSION', '3.1.0' );
2323
define( 'PERFLAB_MAIN_FILE', __FILE__ );
2424
define( 'PERFLAB_PLUGIN_DIR_PATH', plugin_dir_path( PERFLAB_MAIN_FILE ) );
2525
define( 'PERFLAB_SCREEN', 'performance-lab' );

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"changelog": "./bin/plugin/cli.js changelog",
2929
"since": "./bin/plugin/cli.js since",
3030
"readme": "./bin/plugin/cli.js readme",
31+
"versions": "./bin/plugin/cli.js versions",
3132
"build": "wp-scripts build",
3233
"build-plugins": "npm-run-all 'build:plugin:!(performance-lab)'",
3334
"build:plugin:performance-lab": "rm -rf build/performance-lab && mkdir -p build/performance-lab && git archive HEAD | tar -x -C build/performance-lab",

plugins/auto-sizes/auto-sizes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Instructs browsers to automatically choose the right image size for lazy-loaded images.
66
* Requires at least: 6.4
77
* Requires PHP: 7.2
8-
* Version: 1.0.1
8+
* Version: 1.0.2
99
* Author: WordPress Performance Team
1010
* Author URI: https://make.wordpress.org/performance/
1111
* License: GPLv2 or later
@@ -25,6 +25,6 @@
2525
return;
2626
}
2727

28-
define( 'IMAGE_AUTO_SIZES_VERSION', '1.0.1' );
28+
define( 'IMAGE_AUTO_SIZES_VERSION', '1.0.2' );
2929

3030
require_once __DIR__ . '/hooks.php';

plugins/auto-sizes/readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: wordpressdotorg
44
Requires at least: 6.4
55
Tested up to: 6.5
66
Requires PHP: 7.2
7-
Stable tag: 1.0.1
7+
Stable tag: 1.0.2
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
Tags: performance, images, auto-sizes
@@ -48,6 +48,10 @@ Contributions are always welcome! Learn more about how to get involved in the [C
4848

4949
== Changelog ==
5050

51+
= 1.0.2 =
52+
53+
* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775))
54+
5155
= 1.0.1 =
5256

5357
* Add auto-sizes generator tag. ([1105](https://github.com/WordPress/performance/pull/1105))

plugins/dominant-color-images/load.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Displays placeholders based on an image's dominant color while the image is loading.
66
* Requires at least: 6.4
77
* Requires PHP: 7.2
8-
* Version: 1.1.0
8+
* Version: 1.1.1
99
* Author: WordPress Performance Team
1010
* Author URI: https://make.wordpress.org/performance/
1111
* License: GPLv2 or later
@@ -25,7 +25,7 @@
2525
return;
2626
}
2727

28-
define( 'DOMINANT_COLOR_IMAGES_VERSION', '1.1.0' );
28+
define( 'DOMINANT_COLOR_IMAGES_VERSION', '1.1.1' );
2929

3030
require_once __DIR__ . '/helper.php';
3131
require_once __DIR__ . '/hooks.php';

plugins/dominant-color-images/readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: wordpressdotorg
44
Requires at least: 6.4
55
Tested up to: 6.5
66
Requires PHP: 7.2
7-
Stable tag: 1.1.0
7+
Stable tag: 1.1.1
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
Tags: performance, images, dominant color
@@ -49,6 +49,10 @@ Contributions are always welcome! Learn more about how to get involved in the [C
4949

5050
== Changelog ==
5151

52+
= 1.1.1 =
53+
54+
* Improve overall code quality with stricter static analysis checks. ([775](https://github.com/WordPress/performance/issues/775))
55+
5256
= 1.1.0 =
5357

5458
* Rename plugin to "Image Placeholders". ([1101](https://github.com/WordPress/performance/pull/1101))

plugins/embed-optimizer/load.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Optimizes the performance of embeds by lazy-loading iframes and scripts.
66
* Requires at least: 6.4
77
* Requires PHP: 7.2
8-
* Version: 0.1.1
8+
* Version: 0.1.2
99
* Author: WordPress Performance Team
1010
* Author URI: https://make.wordpress.org/performance/
1111
* License: GPLv2 or later
@@ -20,7 +20,7 @@
2020
exit;
2121
}
2222

23-
define( 'EMBED_OPTIMIZER_VERSION', '0.1.1' );
23+
define( 'EMBED_OPTIMIZER_VERSION', '0.1.2' );
2424

2525
// Load in the Embed Optimizer plugin hooks.
2626
require_once __DIR__ . '/hooks.php';

0 commit comments

Comments
 (0)