Skip to content

Check WordPress Update #69

Check WordPress Update

Check WordPress Update #69

name: Check WordPress Update
on:
schedule:
- cron: '0 0 * * *' # 每天凌晨检查更新
workflow_dispatch: # 手动触发
permissions:
contents: write
jobs:
check-wordpress-update:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Node.js (to use curl)
uses: actions/setup-node@v4
- name: Download WordPress Latest
run: |
# 下载最新版本的 WordPress 中文版
curl -sSL -o latest-zh_CN.zip https://cn.wordpress.org/latest-zh_CN.zip
- name: Check if WordPress is Updated
id: check_update
run: |
# 如果 `wp-latest.zip` 文件已经存在,比较它与新下载文件的内容
if [ -f wp-latest.zip ]; then
if cmp -s wp-latest.zip latest-zh_CN.zip; then
echo "WordPress is up to date."
echo "update=false" >> $GITHUB_OUTPUT
else
echo "WordPress is updated."
echo "update=true" >> $GITHUB_OUTPUT
fi
else
echo "No previous version detected. Treating as an update."
echo "update=true" >> $GITHUB_OUTPUT
fi
- name: Save new version if updated
if: steps.check_update.outputs.update == 'true'
run: |
mv latest-zh_CN.zip wp-latest.zip
- name: Commit and Push Changes
if: steps.check_update.outputs.update == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add wp-latest.zip
git commit -m "Update WordPress to latest version"
git push origin HEAD