Skip to content

Check WordPress Update #5

Check WordPress Update

Check WordPress Update #5

name: Check and Update WordPress Version
on:
schedule:
- cron: '0 0 * * *' # 每天运行一次(可以根据需要调整)
workflow_dispatch: # 手动触发工作流
permissions:
contents: write
jobs:
check_wordpress_version:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Set up Python for version comparison
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Download latest WordPress
run: |
wget https://cn.wordpress.org/latest-zh_CN.zip -O latest.zip
- name: Extract downloaded WordPress
run: |
unzip latest.zip -d wordpress
- name: Get WordPress version
id: get_wp_version
run: |
VERSION=$(cat wordpress/wp-includes/version.php | grep "\$wp_version" | cut -d "'" -f 2)
echo "WP_VERSION=$VERSION" >> $GITHUB_ENV
- name: Check if version has changed
run: |
if [ -f "last_version.txt" ]; then
LAST_VERSION=$(cat last_version.txt)
if [ "$LAST_VERSION" != "$WP_VERSION" ]; then
echo "New version detected: $WP_VERSION"
echo $WP_VERSION > last_version.txt
echo "wordpress updated"
else
echo "No update found"
exit 0
fi
else
echo $WP_VERSION > last_version.txt
echo "First run, version: $WP_VERSION"
echo "wordpress updated"
continue-on-error: true
- name: Commit new WordPress version if updated
if: success() && github.event_name != 'schedule'
run: |
# Create a new commit with the updated WordPress package
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
mv latest.zip wp-latest.zip
git add wp-latest.zip
git commit -m "Update WordPress to version $WP_VERSION"
git push origin main # 将更改推送到主分支(或根据需要更改分支)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}