Update script getting WooCommerce versions and store them to file

[MAILPOET-6097]
This commit is contained in:
Jan Lysý
2024-06-19 20:35:59 +02:00
committed by Rostislav Wolný
parent 0b157c3ac9
commit 3898b3dccb
2 changed files with 33 additions and 6 deletions

View File

@@ -2,7 +2,10 @@
require_once __DIR__ . '/helpers.php';
function getWooCommerceVersions() {
/**
* We get the official WooCommerce versions from the WordPress API.
*/
function getWooCommerceVersions(): array {
$url = "https://api.wordpress.org/plugins/info/1.0/woocommerce.json";
$response = file_get_contents($url);
$data = json_decode($response, true);
@@ -14,7 +17,15 @@ function getWooCommerceVersions() {
return array_keys($data['versions']);
}
function replacePreviousVersion($previousVersion) {
function replaceLatestVersion($latestVersion): void {
replaceVersionInFile(
__DIR__ . './../../../.circleci/config.yml',
'/(.\/do download:woo-commerce-zip )\d+\.\d+\.\d+/',
'${1}' . $latestVersion
);
}
function replacePreviousVersion($previousVersion): void {
replaceVersionInFile(
__DIR__ . './../../../.circleci/config.yml',
'/(woo_core_version: )\d+\.\d+\.?\d*/',
@@ -26,9 +37,21 @@ $allVersions = getWooCommerceVersions();
$stableVersions = filterStableVersions($allVersions);
[$latestVersion, $previousVersion] = getLatestAndPreviousMinorMajorVersions($stableVersions);
echo "Latest WooCommerce version: $latestVersion\n";
echo "Previous WooCommerce version: $previousVersion\n";
echo "Replacing the previous version in the config file...\n";
replacePreviousVersion($previousVersion);
if ($latestVersion) {
echo "Replacing the latest version in the config file...\n";
replaceLatestVersion($latestVersion);
} else {
echo "No latest version found.\n";
}
if ($previousVersion) {
echo "Replacing the previous version in the config file...\n";
replacePreviousVersion($previousVersion);
} else {
echo "No previous version found.\n";
}
saveVersionsToFile($latestVersion, $previousVersion, 'woocommerce_versions.txt');