Add script updating used Automate Woo

[MAILPOET-6097]
This commit is contained in:
Jan Lysý
2024-06-17 19:35:36 +02:00
committed by Jan Lysý
parent 57ebc876ab
commit 4ae48e185f

View File

@ -0,0 +1,40 @@
<?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:automate-woo-zip )\d+\.\d+\.\d+/',
'${1}' . $previousVersion
);
}
function replacePreviousVersion($previousVersion) {
replaceVersionInFile(
__DIR__ . './../../../.circleci/config.yml',
'/(automate_woo_version: )\d+\.\d+\.\d+/',
'${1}' . $previousVersion
);
}
$repository = 'woocommerce/automatewoo';
$allVersions = fetchGitHubTags($repository, $token);
$stableVersions = filterStableVersions($allVersions);
[$latestVersion, $previousVersion] = getLatestAndPreviousMinorMajorVersions($stableVersions);
echo "Latest Automate Woo version: $latestVersion\n";
echo "Previous Automate Woo version: $previousVersion\n";
echo "Replacing the latest version in the config file...\n";
replaceLatestVersion($latestVersion);
echo "Replacing the previous version in the config file...\n";
replacePreviousVersion($previousVersion);