Add new GitHub action updating used WooCommerce plugin
[MAILPOET-6097]
This commit is contained in:
19
.github/workflows/check-wordpress-versions.yml
vendored
19
.github/workflows/check-wordpress-versions.yml
vendored
@@ -17,6 +17,7 @@ jobs:
|
||||
with:
|
||||
php-version: '8.3' # Specify the PHP version you want to use
|
||||
|
||||
# Updating used WordPress
|
||||
- name: Check WordPress Docker Versions
|
||||
run: php .github/workflows/scripts/check_wordpress_versions.php
|
||||
|
||||
@@ -33,3 +34,21 @@ jobs:
|
||||
git add config.yml
|
||||
git commit -m 'Update used WordPress images in Circle CI'
|
||||
git push origin HEAD:refs/heads/circle-ci-wordpress-image
|
||||
|
||||
# Updating used WooCommerce plugin
|
||||
- name: Check WooCommerce Versions
|
||||
run: php .github/workflows/scripts/check_woocommerce_versions.php
|
||||
|
||||
- name: Check for changes
|
||||
id: git_diff
|
||||
run: |
|
||||
git config --global user.name 'github-actions[bot]'
|
||||
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
|
||||
git diff --exit-code || echo "::set-output name=changes::true"
|
||||
|
||||
- name: Commit changes
|
||||
if: steps.git_diff.outputs.changes == 'true'
|
||||
run: |
|
||||
git add config.yml
|
||||
git commit -m 'Update used WooCommerce plugin in Circle CI'
|
||||
git push origin HEAD:refs/heads/circle-ci-wordpress-image
|
||||
|
78
.github/workflows/scripts/check_woocommerce_versions.php
vendored
Normal file
78
.github/workflows/scripts/check_woocommerce_versions.php
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
function getWooCommerceVersions() {
|
||||
$url = "https://api.wordpress.org/plugins/info/1.0/woocommerce.json";
|
||||
$response = file_get_contents($url);
|
||||
$data = json_decode($response, true);
|
||||
|
||||
if (!isset($data['versions'])) {
|
||||
die("Failed to fetch WooCommerce versions.");
|
||||
}
|
||||
|
||||
return array_keys($data['versions']);
|
||||
}
|
||||
|
||||
function filterStableVersions($versions) {
|
||||
return array_filter($versions, function($version) {
|
||||
// Only include stable versions (exclude versions with -rc, -beta, -alpha, etc.)
|
||||
return !preg_match('/-(rc|beta|alpha|dev|nightly|pl)/i', $version);
|
||||
});
|
||||
}
|
||||
|
||||
function getLatestAndPreviousMinorMajorVersions($versions) {
|
||||
usort($versions, 'version_compare');
|
||||
$currentVersion = end($versions);
|
||||
|
||||
$previousVersion = null;
|
||||
foreach (array_reverse($versions) as $version) {
|
||||
if (version_compare($version, $currentVersion, '<') && getMinorMajorVersion($version) !== getMinorMajorVersion($currentVersion)) {
|
||||
$previousVersion = $version;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [$currentVersion, $previousVersion];
|
||||
}
|
||||
|
||||
function getMinorMajorVersion($version) {
|
||||
$parts = explode('.', $version);
|
||||
return $parts[0] . '.' . $parts[1];
|
||||
}
|
||||
|
||||
function replaceVersionInFile($filePath, $pattern, $replacement): void {
|
||||
$content = file_get_contents($filePath);
|
||||
|
||||
if ($content === false) {
|
||||
die("Failed to read the file at $filePath.");
|
||||
}
|
||||
|
||||
$updatedContent = preg_replace($pattern, $replacement, $content);
|
||||
|
||||
if ($updatedContent === null || $updatedContent === $content) {
|
||||
echo "Nothing to update in $filePath\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if (file_put_contents($filePath, $updatedContent) === false) {
|
||||
die("Failed to write the updated file at $filePath.");
|
||||
}
|
||||
}
|
||||
|
||||
function replacePreviousVersion($previousVersion) {
|
||||
replaceVersionInFile(
|
||||
__DIR__ . './../../../.circleci/config.yml',
|
||||
'/(woo_core_version: )\d+\.\d+\.?\d*/',
|
||||
'${1}' . $previousVersion
|
||||
);
|
||||
}
|
||||
|
||||
$allVersions = getWooCommerceVersions();
|
||||
$stableVersions = filterStableVersions($allVersions);
|
||||
list($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);
|
Reference in New Issue
Block a user