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'; 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"; $url = "https://api.wordpress.org/plugins/info/1.0/woocommerce.json";
$response = file_get_contents($url); $response = file_get_contents($url);
$data = json_decode($response, true); $data = json_decode($response, true);
@@ -14,7 +17,15 @@ function getWooCommerceVersions() {
return array_keys($data['versions']); 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( replaceVersionInFile(
__DIR__ . './../../../.circleci/config.yml', __DIR__ . './../../../.circleci/config.yml',
'/(woo_core_version: )\d+\.\d+\.?\d*/', '/(woo_core_version: )\d+\.\d+\.?\d*/',
@@ -26,9 +37,21 @@ $allVersions = getWooCommerceVersions();
$stableVersions = filterStableVersions($allVersions); $stableVersions = filterStableVersions($allVersions);
[$latestVersion, $previousVersion] = getLatestAndPreviousMinorMajorVersions($stableVersions); [$latestVersion, $previousVersion] = getLatestAndPreviousMinorMajorVersions($stableVersions);
echo "Latest WooCommerce version: $latestVersion\n"; echo "Latest WooCommerce version: $latestVersion\n";
echo "Previous WooCommerce version: $previousVersion\n"; echo "Previous WooCommerce 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"; echo "Replacing the previous version in the config file...\n";
replacePreviousVersion($previousVersion); replacePreviousVersion($previousVersion);
} else {
echo "No previous version found.\n";
}
saveVersionsToFile($latestVersion, $previousVersion, 'woocommerce_versions.txt');

View File

@@ -54,11 +54,15 @@ jobs:
echo "WOOCOMMERCE_CHANGES=true" >> $GITHUB_ENV echo "WOOCOMMERCE_CHANGES=true" >> $GITHUB_ENV
fi fi
- name: Get WooCommerce versions from file
id: get_wp_version
run: echo "WOOCOMMERCE_VERSION=$(cat /tmp/woocommerce_versions.txt)" >> $GITHUB_ENV
- name: Commit WooCommerce changes - name: Commit WooCommerce changes
if: env.WOOCOMMERCE_CHANGES == 'true' if: env.WOOCOMMERCE_CHANGES == 'true'
run: | run: |
git add . git add .
git commit -m 'Update used WooCommerce plugin in Circle CI' git commit -m 'Update used WooCommerce plugin in Circle CI' -m "${{ env.WOOCOMMERCE_VERSION }}"
# Updating used Automate Woo plugin # Updating used Automate Woo plugin
- name: Check Automate Woo Versions - name: Check Automate Woo Versions