Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pre-release version syntax to all relevant tools #1823

Merged
merged 3 commits into from
Jan 24, 2025

Conversation

felixarntz
Copy link
Member

Summary

In order to support release versions like the upcoming Optimization Detective 1.0.0-beta.1, we need to make sure our tooling supports such versions.

The versions command was already checking for pre-release identifiers, however it was flawed because it would not accept periods in the suffix, which are commonly used. This PR updates all relevant regexes to support version suffixes, using a uniform approach.

@felixarntz felixarntz added [Type] Enhancement A suggestion for improvement of an existing feature Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release labels Jan 24, 2025
Copy link

github-actions bot commented Jan 24, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: felixarntz <[email protected]>
Co-authored-by: westonruter <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@felixarntz
Copy link
Member Author

Tested the regex by manually updating the different Optimization Detective version references locally to 1.0.0-beta.1, and then running npm run versions -- --plugin=optimization-detective. Everything appears to work as expected.

@felixarntz
Copy link
Member Author

One thing to flag here is that the versions command will warn if such a pre-release identifier is present. Overall I think this makes sense. It just shouldn't cause the deploy workflow to fail - I'm not entirely sure whether such a warning would do that or not. I don't think so, but would be great to get that validated.

@westonruter
Copy link
Member

In order to support release versions like the upcoming Optimization Detective 1.0.0-beta.1, we need to make sure our tooling supports such versions.

Do we need to include the period? WordPress core releases don't include it. They use versions like 1.0.0-beta1 and 1.0.0-RC1.

@felixarntz
Copy link
Member Author

@westonruter I don't feel strongly about what format we use, but I think supporting the period doesn't hurt, as it's common. So I don't think we need to alter that regardless of what version we end up using.

@westonruter
Copy link
Member

One thing to flag here is that the versions command will warn if such a pre-release identifier is present. Overall I think this makes sense. It just shouldn't cause the deploy workflow to fail - I'm not entirely sure whether such a warning would do that or not. I don't think so, but would be great to get that validated.

No, it won't impact this because it doesn't increment the errorCount:

try {
const version = await checkPluginDirectory( pluginDirectory );
if ( version.includes( '-' ) ) {
log(
formats.warning(
`⚠ ${ slug }: ${ version } (pre-release identifier is present)`
)
);
} else {
log( formats.success( `✅ ${ slug }: ${ version } ` ) );
}
} catch ( error ) {
errorCount++;
log( formats.error( `❌ ${ slug }: ${ error.message }` ) );
}

@westonruter
Copy link
Member

Output of npm run versions:

image

Output of npm run since:

image

git diff -- plugins/optimization-detective/
diff --git a/plugins/optimization-detective/class-od-element.php b/plugins/optimization-detective/class-od-element.php
index e2415e512..e918d7c29 100644
--- a/plugins/optimization-detective/class-od-element.php
+++ b/plugins/optimization-detective/class-od-element.php
@@ -36,7 +36,7 @@ class OD_Element implements ArrayAccess, JsonSerializable {
 	/**
 	 * Transitional XPath.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 * @todo Remove logic related to transitional_xpath in a subsequent release once URL Metrics have been collected with the new format.
 	 * @var non-empty-string|null
 	 */
@@ -131,7 +131,7 @@ class OD_Element implements ArrayAccess, JsonSerializable {
 	 * Gets XPath for element.
 	 *
 	 * @since 0.7.0
-	 * @since n.e.x.t Returns the transitional XPath format. To access the underlying raw XPath, access the 'xpath' key of the jsonSerialize response.
+	 * @since 1.0.0-beta1 Returns the transitional XPath format. To access the underlying raw XPath, access the 'xpath' key of the jsonSerialize response.
 	 * @todo Remove logic related to transitional_xpath in a subsequent release once URL Metrics have been collected with the new format.
 	 *
 	 * @return non-empty-string XPath.
diff --git a/plugins/optimization-detective/class-od-html-tag-processor.php b/plugins/optimization-detective/class-od-html-tag-processor.php
index cac52d782..e995a4a1e 100644
--- a/plugins/optimization-detective/class-od-html-tag-processor.php
+++ b/plugins/optimization-detective/class-od-html-tag-processor.php
@@ -159,7 +159,7 @@ final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor {
 	 * Note that currently only the third item will currently be populated (index 2), as this corresponds to tags which
 	 * are children of the `BODY` tag. This is used in {@see self::get_xpath()}.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 * @var array<array<string, string>>
 	 */
 	private $open_stack_attributes = array();
@@ -204,7 +204,7 @@ final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor {
 	 * This is used to store the old XPath format in a transitional period until which new URL Metrics are expected to
 	 * have been collected to purge out references to the old format.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 * @var string|null
 	 */
 	private $current_xpath = null;
@@ -582,7 +582,7 @@ final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor {
 	 * Themes utilize the 'wp-site-blocks' class name in the root `DIV`. Only one attribute is currently returned,
 	 * although potentially more could be returned if additional disambiguation is needed in the future.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 *
 	 * @return array<string, string> Disambiguating attributes.
 	 */
@@ -682,7 +682,7 @@ final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor {
 	 * can simply be an alias for that one. See related logic in {@see OD_Element::get_xpath()}. This function is only
 	 * used internally by Optimization Detective in {@see od_optimize_template_output_buffer()}.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 * @todo Move the logic in this method to the get_xpath() method and let this be an alias for that method once the transitional period is over.
 	 * @access private
 	 *
@@ -715,7 +715,7 @@ final class OD_HTML_Tag_Processor extends WP_HTML_Tag_Processor {
 	/**
 	 * Returns whether the processor is currently at or inside the admin bar.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 *
 	 * @return bool Whether at or inside the admin bar.
 	 */
diff --git a/plugins/optimization-detective/class-od-tag-visitor-context.php b/plugins/optimization-detective/class-od-tag-visitor-context.php
index 7a85a9f12..1398030b8 100644
--- a/plugins/optimization-detective/class-od-tag-visitor-context.php
+++ b/plugins/optimization-detective/class-od-tag-visitor-context.php
@@ -51,7 +51,7 @@ final class OD_Tag_Visitor_Context {
 	/**
 	 * Visited tag state.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 * @var OD_Visited_Tag_State
 	 */
 	private $visited_tag_state;
@@ -78,7 +78,7 @@ final class OD_Tag_Visitor_Context {
 	 *
 	 * Calling this method from a tag visitor has the same effect as a tag visitor returning `true`.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 */
 	public function track_tag(): void {
 		$this->visited_tag_state->track_tag();
diff --git a/plugins/optimization-detective/class-od-visited-tag-state.php b/plugins/optimization-detective/class-od-visited-tag-state.php
index d0ed12013..d7cedc405 100644
--- a/plugins/optimization-detective/class-od-visited-tag-state.php
+++ b/plugins/optimization-detective/class-od-visited-tag-state.php
@@ -3,7 +3,7 @@
  * Optimization Detective: OD_Visited_Tag_State class
  *
  * @package optimization-detective
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  */
 
 // @codeCoverageIgnoreStart
@@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) {
 /**
  * State for a tag visitation when visited by tag visitors while walking over a document.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  */
 final class OD_Visited_Tag_State {
@@ -23,7 +23,7 @@ final class OD_Visited_Tag_State {
 	/**
 	 * Whether the tag should be tracked among the elements in URL Metrics.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 * @var bool
 	 */
 	private $should_track_tag;
@@ -38,7 +38,7 @@ final class OD_Visited_Tag_State {
 	/**
 	 * Marks the tag for being tracked in URL Metrics.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 */
 	public function track_tag(): void {
 		$this->should_track_tag = true;
@@ -47,7 +47,7 @@ final class OD_Visited_Tag_State {
 	/**
 	 * Whether the tag should be tracked among the elements in URL Metrics.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 * @return bool Whether tracked.
 	 */
 	public function is_tag_tracked(): bool {
@@ -59,7 +59,7 @@ final class OD_Visited_Tag_State {
 	 *
 	 * This should be called after tag visitors have been invoked on a tag.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 */
 	public function reset(): void {
 		$this->should_track_tag = false;
diff --git a/plugins/optimization-detective/detection.php b/plugins/optimization-detective/detection.php
index e7992ffe0..ac49a9762 100644
--- a/plugins/optimization-detective/detection.php
+++ b/plugins/optimization-detective/detection.php
@@ -87,7 +87,7 @@ function od_get_detection_script( string $slug, OD_URL_Metric_Group_Collection $
 	 * Note that the attribution build is slightly larger than the standard build, so this is why it is not used by default.
 	 * The additional attribution data is made available to client-side extension script modules registered via the `od_extension_module_urls` filter.
 	 *
-	 * @since n.e.x.t
+	 * @since 1.0.0-beta1
 	 *
 	 * @param bool $use_attribution_build Whether to use the attribution build.
 	 */
diff --git a/plugins/optimization-detective/load.php b/plugins/optimization-detective/load.php
index b3db78933..801c8fdee 100644
--- a/plugins/optimization-detective/load.php
+++ b/plugins/optimization-detective/load.php
@@ -5,7 +5,7 @@
  * Description: Provides an API for leveraging real user metrics to detect optimizations to apply on the frontend to improve page performance.
  * Requires at least: 6.6
  * Requires PHP: 7.2
- * Version: 0.9.0
+ * Version: 1.0.0-beta1
  * Author: WordPress Performance Team
  * Author URI: https://make.wordpress.org/performance/
  * License: GPLv2 or later
@@ -71,7 +71,7 @@ if ( ! defined( 'ABSPATH' ) ) {
 	}
 )(
 	'optimization_detective_pending_plugin',
-	'0.9.0',
+	'1.0.0-beta1',
 	static function ( string $version ): void {
 		if ( defined( 'OPTIMIZATION_DETECTIVE_VERSION' ) ) {
 			return;
diff --git a/plugins/optimization-detective/optimization.php b/plugins/optimization-detective/optimization.php
index 7dbd53154..0f6b7fbdb 100644
--- a/plugins/optimization-detective/optimization.php
+++ b/plugins/optimization-detective/optimization.php
@@ -130,7 +130,7 @@ function od_maybe_add_template_output_buffer_filter(): void {
  *
  * This is only used when WP_DEBUG is enabled.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  *
  * @param string[] $reasons Reason messages.
diff --git a/plugins/optimization-detective/readme.txt b/plugins/optimization-detective/readme.txt
index da95e8392..6ffb1ff82 100644
--- a/plugins/optimization-detective/readme.txt
+++ b/plugins/optimization-detective/readme.txt
@@ -2,7 +2,7 @@
 
 Contributors: wordpressdotorg
 Tested up to: 6.7
-Stable tag:   0.9.0
+Stable tag:   1.0.0-beta1
 License:      GPLv2 or later
 License URI:  https://www.gnu.org/licenses/gpl-2.0.html
 Tags:         performance, optimization, rum
@@ -55,6 +55,10 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu
 
 == Changelog ==
 
+= 1.0.0-beta1 =
+
 = 0.9.0 =
 
 **Enhancements**
diff --git a/plugins/optimization-detective/site-health.php b/plugins/optimization-detective/site-health.php
index dadfe3437..968dc565e 100644
--- a/plugins/optimization-detective/site-health.php
+++ b/plugins/optimization-detective/site-health.php
@@ -3,7 +3,7 @@
  * Site Health checks.
  *
  * @package optimization-detective
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  */
 
 // @codeCoverageIgnoreStart
@@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) {
 /**
  * Adds the Optimization Detective REST API check to site health tests.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  *
  * @param array{direct: array<string, array{label: string, test: string}>}|mixed $tests Site Health Tests.
@@ -39,7 +39,7 @@ function od_add_rest_api_availability_test( $tests ): array {
 /**
  * Tests availability of the Optimization Detective REST API endpoint.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  *
  * @return array{label: string, status: string, badge: array{label: string, color: string}, description: string, actions: string, test: string} Result.
@@ -68,7 +68,7 @@ function od_test_rest_api_availability(): array {
  * the admin. The reason for storing the negative unavailable state as opposed to the positive available state is that
  * when an option does not exist then `get_option()` returns `false` which is the same falsy value as the stored `'0'`.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  *
  * @return bool Whether unavailable.
@@ -80,7 +80,7 @@ function od_is_rest_api_unavailable(): bool {
 /**
  * Tests availability of the Optimization Detective REST API endpoint.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  *
  * @param array<string, mixed>|WP_Error $response REST API response.
@@ -165,7 +165,7 @@ function od_compose_site_health_result( $response ): array {
 /**
  * Gets the response to an Optimization Detective REST API store request to confirm it is available to unauthenticated requests.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  *
  * @param bool $use_cached Whether to use a previous response cached in a transient.
@@ -195,7 +195,7 @@ function od_get_rest_api_health_check_response( bool $use_cached ) {
 /**
  * Renders an admin notice if the REST API health check fails.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  *
  * @param bool $in_plugin_row Whether the notice is to be printed in the plugin row.
@@ -251,7 +251,7 @@ function od_maybe_render_rest_api_health_check_admin_notice( bool $in_plugin_row
 /**
  * Displays an admin notice on the plugin row if the REST API health check fails.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  *
  * @param string $plugin_file Plugin file.
@@ -273,7 +273,7 @@ function od_render_rest_api_health_check_admin_notice_in_plugin_row( string $plu
  * shown at the `admin_notices` action once, the notice will only be displayed inline with the plugin row thereafter
  * via {@see od_render_rest_api_health_check_admin_notice_in_plugin_row()}.
  *
- * @since n.e.x.t
+ * @since 1.0.0-beta1
  * @access private
  */
 function od_maybe_run_rest_api_health_check(): void {

Output of npm run readme:

image

git diff -- plugins/optimization-detective/readme.txt
diff --git a/plugins/optimization-detective/readme.txt b/plugins/optimization-detective/readme.txt
index da95e8392..f0dd9c442 100644
--- a/plugins/optimization-detective/readme.txt
+++ b/plugins/optimization-detective/readme.txt
@@ -2,7 +2,7 @@
 
 Contributors: wordpressdotorg
 Tested up to: 6.7
-Stable tag:   0.9.0
+Stable tag:   1.0.0-beta1
 License:      GPLv2 or later
 License URI:  https://www.gnu.org/licenses/gpl-2.0.html
 Tags:         performance, optimization, rum
@@ -55,6 +55,24 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu
 
 == Changelog ==
 
+= 1.0.0-beta1 =
+
+**Enhancements**
+
+* Add site health check to detect blocked REST API and short-circuit optimization when Inaccessible. ([1762](https://github.com/WordPress/performance/pull/1762))
+* Allow extensions to opt-in to using the web-vitals attribution build via the `od_use_web_vitals_attribution_build` filter. ([1759](https://github.com/WordPress/performance/pull/1759))
+* Disambiguate XPaths for children of BODY with `id`, `class`, or `role` attributes. ([1797](https://github.com/WordPress/performance/pull/1797))
+* Eliminate varying URL Metrics by logged-in state and discontinue disabling optimization by default for admins. ([1788](https://github.com/WordPress/performance/pull/1788))
+* Improve snapshot testing for Optimization Detective. ([1791](https://github.com/WordPress/performance/pull/1791))
+* Introduce `OD_Tag_Visitor_Context::track_tag()` method as alternative for returning `true` in tag visitor callback. ([1821](https://github.com/WordPress/performance/pull/1821))
+* Omit element node index in XPaths up to children of BODY. ([1790](https://github.com/WordPress/performance/pull/1790))
+* Skip visiting tags in the Admin Bar when optimizing a page. ([1816](https://github.com/WordPress/performance/pull/1816))
+
+**Bug Fixes**
+
+* Ensure optimization is performed in the wp-env local environment and log debug messages to console when disabled. ([1822](https://github.com/WordPress/performance/pull/1822))
+* Skip visiting any tags inside of NOSCRIPT elements. ([1783](https://github.com/WordPress/performance/pull/1783))
+
 = 0.9.0 =
 
 **Enhancements**

@westonruter
Copy link
Member

Output of npm run build-plugins as build/manifest.json:

{
  "performance-lab": "3.7.0",
  "auto-sizes": "1.4.0",
  "dominant-color-images": "1.2.0",
  "embed-optimizer": "0.4.0",
  "image-prioritizer": "0.3.0",
  "optimization-detective": "1.0.0-beta1",
  "speculation-rules": "1.3.1",
  "web-worker-offloading": "0.2.0",
  "webp-uploads": "2.4.0"
}

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good:

image

@westonruter westonruter merged commit 2b1bf18 into trunk Jan 24, 2025
8 checks passed
@westonruter westonruter deleted the support/pre-release-version-syntax branch January 24, 2025 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Issues for the overall performance plugin infrastructure no milestone PRs that do not have a defined milestone for release [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants