Skip to content

Maintenance: Update version requirements #100

Maintenance: Update version requirements

Maintenance: Update version requirements #100

name: 'Maintenance: Update version requirements'
on:
schedule:
- cron: '0 0 * * *' # Runs every day at midnight UTC
workflow_dispatch:
jobs:
update-versions:
name: Update WordPress and PHP version requirements
runs-on: ubuntu-latest
steps:
- name: Install SVN
run: sudo apt-get -qq install -y subversion
- name: Get current WordPress version
id: wp-version
run: |
WP_VERSION=$(svn ls https://core.svn.wordpress.org/tags | sort -V | tail -n 1 | tr -d '/')
if [[ -z "$WP_VERSION" ]]; then
echo "Failed to get WordPress version"
exit 1
fi
echo "wp_version=$WP_VERSION" >> $GITHUB_OUTPUT
echo "Latest WordPress version is $WP_VERSION"
- name: Calculate L-1 WordPress version
id: wp-previous-version
uses: actions/github-script@v7
env:
WP_VERSION: ${{ steps.wp-version.outputs.wp_version }}
with:
script: |
const version = process.env.WP_VERSION;
const parts = version.split('.').map(Number);
const [major, minor] = parts;
let previousVersion;
if (minor > 0) {
previousVersion = `${major}.${minor - 1}`;
} else {
previousVersion = `${major - 1}.9`;
}
core.info(`Previous WordPress version is ${previousVersion}`);
core.setOutput('wp_prev_version', previousVersion);
- name: Check out trunk
uses: actions/checkout@v4
with:
ref: trunk
- name: Get minimum PHP version from composer.json
id: php-version
run: |
REQUIRED_PHP=$(jq -r '.config.platform.php' plugins/woocommerce/composer.json)
if [[ -z "$REQUIRED_PHP" ]]; then
echo "Failed to get PHP version from composer.json"
exit 1
fi
echo "required_php_version=$REQUIRED_PHP" >> $GITHUB_OUTPUT
echo "Required PHP version from composer.json: $REQUIRED_PHP"
- name: Set up dev environment
run: |
cd plugins/woocommerce
# Install dev packages. Required for changelogger use.
composer install --quiet
# Configure Git.
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Update version requirements and create PR
id: update-pr
env:
WP_PREV_VERSION: ${{ steps.wp-previous-version.outputs.wp_prev_version }}
PHP_VERSION: ${{ steps.php-version.outputs.required_php_version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Update the version requirements in woocommerce.php
WOOCOMMERCE_FILE="plugins/woocommerce/woocommerce.php"
sed -i "s/\* Requires at least: [0-9.]*/\* Requires at least: $WP_PREV_VERSION/" "$WOOCOMMERCE_FILE"
sed -i "s/\* Requires PHP: [0-9.]*/\* Requires PHP: $PHP_VERSION/" "$WOOCOMMERCE_FILE"
# Update the version requirements in readme.txt
README_FILE="plugins/woocommerce/readme.txt"
sed -i "s/Requires at least: [0-9.]*/Requires at least: $WP_PREV_VERSION/" "$README_FILE"
sed -i "s/Requires PHP: [0-9.]*/Requires PHP: $PHP_VERSION/" "$README_FILE"
sed -i "s/WordPress [0-9.]\+/WordPress $WP_PREV_VERSION/" "$README_FILE"
sed -i "s/PHP [0-9.]\+ or greater is required/PHP $PHP_VERSION or greater is required/" "$README_FILE"
# Check for changes and exit early if none
if git diff --quiet; then
echo "No changes detected. No PR needed."
exit 0
fi
# Create new branch with timestamp
BRANCH_NAME="update-version-requirements-$(date +%s)"
git checkout -b "$BRANCH_NAME"
cd plugins/woocommerce
composer exec -- changelogger add \
--significance minor \
--type update \
--entry "Update version requirements to WordPress $WP_PREV_VERSION and PHP $PHP_VERSION in readme.txt and woocommerce.php." \
--no-interaction
git add .
git commit -m "Update version requirements to WP $WP_PREV_VERSION / PHP $PHP_VERSION"
git push origin "$BRANCH_NAME"
PR_URL=$(gh pr create \
--title "Update version requirements to WP $WP_PREV_VERSION / PHP $PHP_VERSION" \
--body "This PR automatically updates the version requirements in \`$WOOCOMMERCE_FILE\` and \`$README_FILE\`:
## Changes
- **WordPress requirement**: $WP_PREV_VERSION
- **PHP requirement**: $PHP_VERSION
Auto-generated by the \`maintenance-update-version-requirements.yml\` workflow." \
--head "$BRANCH_NAME" \
--base trunk)
echo "PR created successfully: $PR_URL"
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
- name: Send Slack notification
if: steps.update-pr.outputs.pr_url != ''
uses: archive/github-actions-slack@v2.10.0
with:
slack-bot-user-oauth-access-token: ${{ secrets.CODE_FREEZE_BOT_TOKEN }}
slack-channel: ${{ secrets.WOO_DOCS_SLACK_CHANNEL }}
slack-optional-unfurl_links: false
slack-text: |
:woo: *WooCommerce Versions Requirements Updated*
Version requirements for :woo: have been automatically updated and a PR has been created.
*WordPress Requirement:* ${{ steps.wp-previous-version.outputs.wp_prev_version }}
*PHP Requirement:* ${{ steps.php-version.outputs.required_php_version }}
*Pull Request:* <${{ steps.update-pr.outputs.pr_url }}|${{ steps.update-pr.outputs.pr_url }}>
<!subteam^S011VV34JTX> Please also update these documentation pages:
• <https://woocommerce.com/document/update-php-wordpress/|Update PHP and WordPress>
• <https://woocommerce.com/document/server-requirements/|WooCommerce Server Recommendations>