Files
nolimit-discounts/ci/latest-prerelease.php
T

51 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* Print the newest published beta/RC of a wordpress.org plugin, or nothing.
*
* Usage: SLUG=woocommerce php ci/latest-prerelease.php
*
* The .org API lists every published version, prereleases included. The newest
* one that is not a plain stable release is what a shop on the beta channel
* would get, which makes it the earliest available warning that the next
* release breaks us. A prerelease *older* than current stable is a leftover
* from a finished cycle and is ignored — testing it would answer a question
* nobody asked.
*
* @package ci
*/
$slug = getenv( 'SLUG' );
if ( ! $slug ) {
fwrite( STDERR, "SLUG is not set.\n" );
exit( 1 );
}
$url = 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information'
. '&request[slug]=' . rawurlencode( $slug )
. '&request[fields][versions]=1';
$body = @file_get_contents( $url ); // phpcs:ignore WordPress.PHP.NoSilencedErrors
if ( false === $body ) {
// A network blip must not fail the build — the caller falls back to the
// stable release, which is still a useful test.
fwrite( STDERR, "Could not reach the wordpress.org plugin API.\n" );
exit( 0 );
}
$info = json_decode( $body, true );
$stable = isset( $info['version'] ) ? $info['version'] : '0';
$pre = array_filter(
array_keys( isset( $info['versions'] ) ? $info['versions'] : array() ),
static function ( $version ) {
return (bool) preg_match( '/-(beta|rc)/i', $version );
}
);
usort( $pre, 'version_compare' );
$newest = end( $pre );
if ( $newest && version_compare( $newest, $stable, '>' ) ) {
echo $newest;
}