Add checking that a related versions were found

[MAILPOET-6097]
This commit is contained in:
Jan Lysý
2024-06-18 16:48:00 +02:00
committed by Jan Lysý
parent c72c876fb3
commit 92fdefda91
3 changed files with 39 additions and 12 deletions

View File

@@ -0,0 +1,49 @@
<?php
require_once __DIR__ . '/helpers.php';
// Read the GitHub token from environment variable
$token = getenv('GH_TOKEN');
if (!$token) {
die("GitHub token not found. Make sure it's set in the environment variable 'GH_TOKEN'.");
}
function replaceLatestVersion($previousVersion) {
replaceVersionInFile(
__DIR__ . './../../../.circleci/config.yml',
'/(.\/do download:woo-commerce-memberships-zip )\d+\.\d+\.\d+/',
'${1}' . $previousVersion
);
}
function replacePreviousVersion($previousVersion) {
replaceVersionInFile(
__DIR__ . './../../../.circleci/config.yml',
'/(woo_memberships_version: )\d+\.\d+\.\d+/',
'${1}' . $previousVersion
);
}
$repository = 'woocommerce/woocommerce-memberships';
$allVersions = fetchGitHubTags($repository, $token);
$stableVersions = filterStableVersions($allVersions);
[$latestVersion, $previousVersion] = getLatestAndPreviousMinorMajorVersions($stableVersions);
echo "Latest WooCommerce Memberships version: $latestVersion\n";
echo "Previous WooCommerce Memberships version: $previousVersion\n";
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";
}