Fix getting version from temporary files in GH action

[MAILPOET-6097]
This commit is contained in:
Jan Lysý
2024-06-21 18:37:20 +02:00
committed by Jan Lysý
parent 46ad169439
commit f4adfaf732
7 changed files with 41 additions and 36 deletions

View File

@@ -5,6 +5,6 @@ require_once __DIR__ . '/helpers.php';
$repository = 'woocommerce/automatewoo';
$downloadCommand = 'download:automate-woo-zip';
$configParameterName = 'automate_woo_version';
$versionsFilename = 'automate_woo_versions.txt';
$versionsFilenameSuffix = 'automate_woo_version.txt';
replacePrivatePluginVersion($repository, $downloadCommand, $configParameterName, $versionsFilename);
replacePrivatePluginVersion($repository, $downloadCommand, $configParameterName, $versionsFilenameSuffix);

View File

@@ -5,6 +5,6 @@ require_once __DIR__ . '/helpers.php';
$repository = 'woocommerce/woocommerce-memberships';
$downloadCommand = 'download:woo-commerce-memberships-zip';
$configParameterName = 'woo_memberships_version';
$versionsFilename = 'woocommerce_memberships_versions.txt';
$versionsFilenameSuffix = 'woocommerce_memberships_version.txt';
replacePrivatePluginVersion($repository, $downloadCommand, $configParameterName, $versionsFilename);
replacePrivatePluginVersion($repository, $downloadCommand, $configParameterName, $versionsFilenameSuffix);

View File

@@ -5,6 +5,6 @@ require_once __DIR__ . '/helpers.php';
$repository = 'woocommerce/woocommerce-subscriptions';
$downloadCommand = 'download:woo-commerce-subscriptions-zip';
$configParameterName = 'woo_subscriptions_version';
$versionsFilename = 'woocommerce_subscriptions_versions.txt';
$versionsFilenameSuffix = 'woocommerce_subscriptions_version.txt';
replacePrivatePluginVersion($repository, $downloadCommand, $configParameterName, $versionsFilename);
replacePrivatePluginVersion($repository, $downloadCommand, $configParameterName, $versionsFilenameSuffix);

View File

@@ -4,7 +4,7 @@ require_once __DIR__ . '/helpers.php';
$downloadCommand = 'download:woo-commerce-zip';
$configParameterName = 'woo_core_version';
$versionsFilename = 'woocommerce_versions.txt';
$versionsFilenameSuffix = 'woocommerce_version.txt';
/**
* We get the official WooCommerce versions from the WordPress API.
@@ -42,4 +42,4 @@ if ($previousVersion) {
echo "No previous version found.\n";
}
saveVersionsToFile($latestVersion, $previousVersion, $versionsFilename);
saveVersionsToFiles($latestVersion, $previousVersion, $versionsFilenameSuffix);

View File

@@ -117,4 +117,4 @@ if ($previousVersion) {
echo "No previous version found.\n";
}
saveVersionsToFile($latestVersion, $previousVersion, 'wordpress_versions.txt');
saveVersionsToFiles($latestVersion, $previousVersion, 'wordpress_version.txt');

View File

@@ -83,17 +83,12 @@ function fetchGitHubTags(string $repo, string $token): array {
}
/**
* Function saving versions to a temporary file.
* Function saving versions to a temporary files.
* File containing latest version is prefixed with 'latest_' and previous version is prefixed with 'previous_'.
*/
function saveVersionsToFile(string $latestVersion, string $previousVersion, string $fileName): void {
$value = "";
if ($latestVersion) {
$value .= "- latest version: {$latestVersion}\n";
}
if ($previousVersion) {
$value .= "- previous version: {$previousVersion}\n";
}
file_put_contents("/tmp/{$fileName}", $value);
function saveVersionsToFiles(string $latestVersion, string $previousVersion, string $fileNameSuffix): void {
file_put_contents("/tmp/latest_{$fileNameSuffix}", $latestVersion);
file_put_contents("/tmp/previous_{$fileNameSuffix}", $previousVersion);
}
function replaceLatestVersion(string $latestVersion, string $downloadCommand): void {
@@ -150,5 +145,5 @@ function replacePrivatePluginVersion(
echo "No previous version found.\n";
}
saveVersionsToFile($latestVersion, $previousVersion, $versionsFilename);
saveVersionsToFiles($latestVersion, $previousVersion, $versionsFilename);
}

View File

@@ -30,15 +30,17 @@ jobs:
echo "WORDPRESS_CHANGES=true" >> $GITHUB_ENV
fi
- name: Get WordPress versions from file
- name: Get WordPress versions from files
id: get_wp_versions
run: echo "WORDPRESS_VERSION=$(cat /tmp/wordpress_versions.txt)" >> $GITHUB_ENV
run: |
echo "WORDPRESS_LATEST_VERSION=$(cat /tmp/latest_wordpress_version.txt)" >> $GITHUB_ENV
echo "WORDPRESS_PREVIOUS_VERSION=$(cat /tmp/previous_wordpress_version.txt)" >> $GITHUB_ENV
- name: Commit WordPress changes
if: env.WORDPRESS_CHANGES == 'true'
run: |
git add .
git commit -m "Update used WordPress images in Circle CI" -m "${{ env.WORDPRESS_VERSION }}"
git commit -m "Update used WordPress images in Circle CI\n\n - latest version: ${{ env.WORDPRESS_LATEST_VERSION }}\n - previous version: ${{ env.WORDPRESS_PREVIOUS_VERSION }}"
# Updating used WooCommerce plugin
- name: Check WooCommerce Versions
@@ -54,15 +56,17 @@ jobs:
echo "WOOCOMMERCE_CHANGES=true" >> $GITHUB_ENV
fi
- name: Get WooCommerce versions from file
- name: Get WooCommerce versions from files
id: get_wc_versions
run: echo "WOOCOMMERCE_VERSION=$(cat /tmp/woocommerce_versions.txt)" >> $GITHUB_ENV
run: |
echo "WOOCOMMERCE_LATEST_VERSION=$(cat /tmp/latest_woocommerce_version.txt)" >> $GITHUB_ENV
echo "WOOCOMMERCE_PREVIOUS_VERSION=$(cat /tmp/previous_woocommerce_version.txt)" >> $GITHUB_ENV
- name: Commit WooCommerce changes
if: env.WOOCOMMERCE_CHANGES == 'true'
run: |
git add .
git commit -m 'Update used WooCommerce plugin in Circle CI' -m "${{ env.WOOCOMMERCE_VERSION }}"
git commit -m 'Update used WooCommerce plugin in Circle CI\n\n - latest version: ${{ env.WOOCOMMERCE_LATEST_VERSION }}\n - previous version: ${{ env.WOOCOMMERCE_PREVIOUS_VERSION }}'
# Updating used Automate Woo plugin
- name: Check Automate Woo Versions
@@ -80,15 +84,17 @@ jobs:
echo "AUTOMATE_WOO_CHANGES=true" >> $GITHUB_ENV
fi
- name: Get Automate Woo versions from file
- name: Get Automate Woo versions from files
id: get_aw_versions
run: echo "AUTOMATE_WOO_VERSION=$(cat /tmp/automate_woo_versions.txt)" >> $GITHUB_ENV
run: |
echo "AUTOMATE_WOO_LATEST_VERSION=$(cat /tmp/latest_automate_woo_version.txt)" >> $GITHUB_ENV
echo "AUTOMATE_WOO_PREVIOUS_VERSION=$(cat /tmp/previous_automate_woo_version.txt)" >> $GITHUB_ENV
- name: Commit Automate Woo changes
if: env.AUTOMATE_WOO_CHANGES == 'true'
run: |
git add .
git commit -m 'Update used Automate Woo plugin in Circle CI' -m "${{ env.AUTOMATE_WOO_VERSION }}"
git commit -m 'Update used Automate Woo plugin in Circle CI\n\n - latest version: ${{ env.AUTOMATE_WOO_LATEST_VERSION }}\n - previous version: ${{ env.AUTOMATE_WOO_PREVIOUS_VERSION }}'
# Updating used WooCommerce Subscriptions plugin
- name: Check WooCommerce Subscriptions Versions
@@ -106,15 +112,17 @@ jobs:
echo "SUBSCRIPTIONS_CHANGES=true" >> $GITHUB_ENV
fi
- name: Get WooCommerce Subscriptions versions from file
- name: Get WooCommerce Subscriptions versions from files
id: get_ws_versions
run: echo "WOOCOMMERCE_SUBSCRIPTIONS_VERSION=$(cat /tmp/woocommerce_subscriptions_versions.txt)" >> $GITHUB_ENV
run: |
echo "WOOCOMMERCE_SUBSCRIPTIONS_LATEST_VERSION=$(cat /tmp/latest_woocommerce_subscriptions_version.txt)" >> $GITHUB_ENV
echo "WOOCOMMERCE_SUBSCRIPTIONS_PREVIOUS_VERSION=$(cat /tmp/previous_woocommerce_subscriptions_version.txt)" >> $GITHUB_ENV
- name: Commit WooCommerce Subscriptions changes
if: env.SUBSCRIPTIONS_CHANGES == 'true'
run: |
git add .
git commit -m 'Update used WooCommerce Subscriptions plugin in Circle CI' -m "${{ env.WOOCOMMERCE_SUBSCRIPTIONS_VERSION }}"
git commit -m 'Update used WooCommerce Subscriptions plugin in Circle CI\n\n - latest version: ${{ env.WOOCOMMERCE_SUBSCRIPTIONS_LATEST_VERSION }}\n - previous version: ${{ env.WOOCOMMERCE_SUBSCRIPTIONS_PREVIOUS_VERSION }}'
# Updating used WooCommerce Memberships plugin
- name: Check WooCommerce Memberships Versions
@@ -132,15 +140,17 @@ jobs:
echo "MEMBERSHIPS_CHANGES=true" >> $GITHUB_ENV
fi
- name: Get WooCommerce Memberships versions from file
- name: Get WooCommerce Memberships versions from files
id: get_wm_versions
run: echo "WOOCOMMERCE_MEMBERSHIPS_VERSION=$(cat /tmp/woocommerce_memberships_versions.txt)" >> $GITHUB_ENV
run: |
echo "WOOCOMMERCE_MEMBERSHIPS_LATEST_VERSION=$(cat /tmp/latest_woocommerce_memberships_version.txt)" >> $GITHUB_ENV
echo "WOOCOMMERCE_MEMBERSHIPS_PREVIOUS_VERSION=$(cat /tmp/previous_woocommerce_memberships_version.txt)" >> $GITHUB_ENV
- name: Commit WooCommerce Memberships changes
if: env.MEMBERSHIPS_CHANGES == 'true'
run: |
git add .
git commit -m 'Update used WooCommerce Memberships plugin in Circle CI' -m "${{ env.WOOCOMMERCE_MEMBERSHIPS_VERSION }}"
git commit -m 'Update used WooCommerce Memberships plugin in Circle CI\n\n - latest version: ${{ env.WOOCOMMERCE_MEMBERSHIPS_LATEST_VERSION }}\n - previous version: ${{ env.WOOCOMMERCE_MEMBERSHIPS_PREVIOUS_VERSION }}'
# Push all changes at the end if any changes were detected
- name: Push changes
@@ -153,7 +163,7 @@ jobs:
if: env.CHANGES_DETECTED == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GH_TOKEN }}
branch: update-plugins-and-wordpress
title: 'Update used WordPress Docker image and used plugin versions in Circle CI jobs'
base: trunk