Add used WordPress versions to the commit message
[MAILPOET-6097]
This commit is contained in:
committed by
Rostislav Wolný
parent
8e3f7faa0e
commit
318424f0c4
@@ -2,21 +2,32 @@
|
|||||||
|
|
||||||
require_once __DIR__ . '/helpers.php';
|
require_once __DIR__ . '/helpers.php';
|
||||||
|
|
||||||
function fetchData($url): array {
|
/**
|
||||||
$response = file_get_contents($url);
|
* We try to get the current available official Docker images for WordPress.
|
||||||
return json_decode($response, true);
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
function getWordpressVersions($page = 1, $pageSize = 100): array {
|
function getWordpressVersions($page = 1, $pageSize = 100): array {
|
||||||
$url = "https://registry.hub.docker.com/v2/repositories/library/wordpress/tags?page_size={$pageSize}&page={$page}";
|
$url = "https://registry.hub.docker.com/v2/repositories/library/wordpress/tags?page_size={$pageSize}&page={$page}";
|
||||||
$data = fetchData($url);
|
$response = file_get_contents($url);
|
||||||
|
$data = json_decode($response, true);
|
||||||
return array_column($data['results'], 'name');
|
return array_column($data['results'], 'name');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We prefer the latest patch versions of WordPress with specified PHP versions.
|
||||||
|
* For example: 6.5.4-php8.3
|
||||||
|
*/
|
||||||
function filterVersions($versions): array {
|
function filterVersions($versions): array {
|
||||||
return array_filter($versions, fn($version) => preg_match('/^\d+\.\d+\.\d+-php\d+\.\d+$/', $version));
|
return array_filter($versions, fn($version) => preg_match('/^\d+\.\d+\.\d+-php\d+\.\d+$/', $version));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We sort the versions by WordPress version and PHP version.
|
||||||
|
* The expected output is:
|
||||||
|
* - 6.5.4-php8.3
|
||||||
|
* - 6.5.4-php8.2
|
||||||
|
* - 6.5.3-php8.3
|
||||||
|
* - 6.5.3-php8.2
|
||||||
|
*/
|
||||||
function sortVersions(&$versions) {
|
function sortVersions(&$versions) {
|
||||||
usort($versions, function($a, $b) {
|
usort($versions, function($a, $b) {
|
||||||
[$wpA, $phpA] = explode('-php', $a);
|
[$wpA, $phpA] = explode('-php', $a);
|
||||||
@@ -27,7 +38,11 @@ function sortVersions(&$versions) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLatestAndPreviousVersions($sortedVersions) {
|
/**
|
||||||
|
* This function group docker tags by the WordPress version and returns the latest with the higher PHP version
|
||||||
|
* abd the previous with the lower PHP version.
|
||||||
|
*/
|
||||||
|
function getLatestAndPreviousVersions($sortedVersions): array {
|
||||||
$uniqueVersions = [];
|
$uniqueVersions = [];
|
||||||
foreach ($sortedVersions as $version) {
|
foreach ($sortedVersions as $version) {
|
||||||
[$wpVersion] = explode('-php', $version);
|
[$wpVersion] = explode('-php', $version);
|
||||||
@@ -46,7 +61,10 @@ function getLatestAndPreviousVersions($sortedVersions) {
|
|||||||
return [reset($latestVersionGroup), end($previousVersionGroup)];
|
return [reset($latestVersionGroup), end($previousVersionGroup)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceLatestVersion($latestVersion) {
|
/**
|
||||||
|
* We specify the latest WordPress version only in the docker-compose file for the tests.
|
||||||
|
*/
|
||||||
|
function replaceLatestVersion($latestVersion): void {
|
||||||
replaceVersionInFile(
|
replaceVersionInFile(
|
||||||
__DIR__ . './../../../mailpoet/tests/docker/docker-compose.yml',
|
__DIR__ . './../../../mailpoet/tests/docker/docker-compose.yml',
|
||||||
'/(wordpress:\${WORDPRESS_IMAGE_VERSION:-\s*)\d+\.\d+\.?\d*-php\d+\.\d+(})/',
|
'/(wordpress:\${WORDPRESS_IMAGE_VERSION:-\s*)\d+\.\d+\.?\d*-php\d+\.\d+(})/',
|
||||||
@@ -54,7 +72,10 @@ function replaceLatestVersion($latestVersion) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function replacePreviousVersion($previousVersion) {
|
/**
|
||||||
|
* We use the previous WordPress version only in the CircleCI config file.
|
||||||
|
*/
|
||||||
|
function replacePreviousVersion($previousVersion): void {
|
||||||
replaceVersionInFile(
|
replaceVersionInFile(
|
||||||
__DIR__ . './../../../.circleci/config.yml',
|
__DIR__ . './../../../.circleci/config.yml',
|
||||||
'/(wordpress_image_version: )\d+\.\d+\.?\d*-php\d+\.\d+/',
|
'/(wordpress_image_version: )\d+\.\d+\.?\d*-php\d+\.\d+/',
|
||||||
@@ -70,6 +91,7 @@ $previousVersion = null;
|
|||||||
|
|
||||||
echo "Fetching WordPress versions...\n";
|
echo "Fetching WordPress versions...\n";
|
||||||
|
|
||||||
|
// We fetch the versions until we find the latest and previous versions. But there is a limit of 4 pages.
|
||||||
while (($latestVersion === null || $previousVersion === null) && $page <= $maxPages) {
|
while (($latestVersion === null || $previousVersion === null) && $page <= $maxPages) {
|
||||||
$versions = getWordpressVersions($page);
|
$versions = getWordpressVersions($page);
|
||||||
$allVersions = array_merge($allVersions, $versions);
|
$allVersions = array_merge($allVersions, $versions);
|
||||||
@@ -82,7 +104,18 @@ while (($latestVersion === null || $previousVersion === null) && $page <= $maxPa
|
|||||||
echo "Latest version: $latestVersion\n";
|
echo "Latest version: $latestVersion\n";
|
||||||
echo "Previous version: $previousVersion\n";
|
echo "Previous version: $previousVersion\n";
|
||||||
|
|
||||||
|
if ($latestVersion) {
|
||||||
echo "Replacing the latest version in the docker file...\n";
|
echo "Replacing the latest version in the docker file...\n";
|
||||||
replaceLatestVersion($latestVersion);
|
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, 'wordpress_versions.txt');
|
||||||
|
11
.github/workflows/scripts/helpers.php
vendored
11
.github/workflows/scripts/helpers.php
vendored
@@ -69,3 +69,14 @@ function fetchGitHubTags($repo, $token) {
|
|||||||
|
|
||||||
return array_column($data, 'name');
|
return array_column($data, 'name');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveVersionsToFile($latestVersion, $previousVersion, $fileName): void {
|
||||||
|
$value = "";
|
||||||
|
if ($latestVersion) {
|
||||||
|
$value .= "- latest version: {$latestVersion}\n";
|
||||||
|
}
|
||||||
|
if ($previousVersion) {
|
||||||
|
$value .= "- previous version: {$previousVersion}\n";
|
||||||
|
}
|
||||||
|
file_put_contents("/tmp/{$fileName}", $value);
|
||||||
|
}
|
||||||
|
@@ -30,11 +30,15 @@ jobs:
|
|||||||
echo "WORDPRESS_CHANGES=true" >> $GITHUB_ENV
|
echo "WORDPRESS_CHANGES=true" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
- name: Get WordPress versions from file
|
||||||
|
id: get_wp_version
|
||||||
|
run: echo "WORDPRESS_VERSION=$(cat /tmp/wordpress_versions.txt)" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Commit WordPress changes
|
- name: Commit WordPress changes
|
||||||
if: env.WORDPRESS_CHANGES == 'true'
|
if: env.WORDPRESS_CHANGES == 'true'
|
||||||
run: |
|
run: |
|
||||||
git add .
|
git add .
|
||||||
git commit -m 'Update used WordPress images in Circle CI'
|
git commit -m "Update used WordPress images in Circle CI" -m "${{ env.WORDPRESS_VERSION }}"
|
||||||
|
|
||||||
# Updating used WooCommerce plugin
|
# Updating used WooCommerce plugin
|
||||||
- name: Check WooCommerce Versions
|
- name: Check WooCommerce Versions
|
||||||
|
Reference in New Issue
Block a user