128 lines
3.4 KiB
YAML
128 lines
3.4 KiB
YAML
name: Deploy to Production
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
schedule:
|
|
- cron: '0 1 * * *' # UTC 01:00 = 北京时间 09:00
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
env:
|
|
TZ: Asia/Shanghai
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Hugo
|
|
uses: peaceiris/actions-hugo@v2
|
|
with:
|
|
hugo-version: '0.128.2'
|
|
extended: true
|
|
|
|
- name: Run Pre-Build Scripts
|
|
shell: pwsh
|
|
run: |
|
|
./scripts/add_draft_to_hidden.ps1
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '22'
|
|
cache: 'npm'
|
|
|
|
- name: Install Node.js dependencies
|
|
run: npm ci
|
|
|
|
- name: Optimize Images
|
|
continue-on-error: true
|
|
run: node scripts/optimize_images.js
|
|
|
|
- name: Commit Optimized Images
|
|
continue-on-error: true
|
|
run: |
|
|
git config --global user.name "GitHub Actions"
|
|
git config --global user.email "actions@github.com"
|
|
git add content/posts static
|
|
if ! git diff --staged --quiet; then
|
|
git commit -m "chore: auto-optimize images [skip ci]"
|
|
else
|
|
echo "No changes to commit"
|
|
fi
|
|
|
|
- name: Build
|
|
run: rm -rf public && hugo --minify
|
|
|
|
- name: Deploy to EdgeOne Pages
|
|
env:
|
|
EDGEONE_API_TOKEN: ${{ secrets.EDGEONE_API_TOKEN }}
|
|
run: |
|
|
chmod +x scripts/deploy_edgeone.sh
|
|
./scripts/deploy_edgeone.sh hugo-blog ./public overseas
|
|
|
|
- name: Deploy to UpYun
|
|
uses: her-cat/upyun-deployer@v1.0.3
|
|
with:
|
|
bucket: ${{ secrets.UPYUN_BUCKET }}
|
|
operator: ${{ secrets.UPYUN_OPERATOR }}
|
|
password: ${{ secrets.UPYUN_PASSWORD }}
|
|
dir: 'public'
|
|
publish_dir: '/'
|
|
|
|
- name: Refresh DogeCloud CDN
|
|
continue-on-error: true
|
|
env:
|
|
DOGECLOUD_ACCESS_KEY: ${{ secrets.DOGECLOUD_ACCESS_KEY }}
|
|
DOGECLOUD_SECRET_KEY: ${{ secrets.DOGECLOUD_SECRET_KEY }}
|
|
CDN_URL_LIST: ${{ secrets.CDN_URL_LIST }}
|
|
run: node scripts/refresh_cdn.js
|
|
|
|
- name: Push Image Optimizations
|
|
continue-on-error: true
|
|
run: |
|
|
git fetch origin main
|
|
# stash任何未提交的更改,避免rebase失败
|
|
git stash push -m "temp stash for rebase"
|
|
git rebase origin/main
|
|
# 恢复stash的更改
|
|
git stash pop || true
|
|
if ! git log --oneline -1 | grep -q "\[skip ci\]"; then
|
|
echo "No auto-commits to push"
|
|
else
|
|
git push origin HEAD:main
|
|
fi
|
|
|
|
- name: Generate Notification Report
|
|
continue-on-error: true
|
|
run: node scripts/generate_notification_report.js
|
|
|
|
- name: Get current date (CN)
|
|
id: date
|
|
run: echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
|
|
|
|
- name: Send deployment notification
|
|
if: success()
|
|
uses: dawidd6/action-send-mail@v3
|
|
with:
|
|
server_address: smtp.qq.com
|
|
server_port: 465
|
|
secure: true
|
|
username: ${{ secrets.MAIL_USERNAME }}
|
|
password: ${{ secrets.MAIL_PASSWORD }}
|
|
subject: 部署报告 - ${{ steps.date.outputs.date }}
|
|
to: ${{ secrets.MAIL_USERNAME }}
|
|
from: GitHub Actions <${{ secrets.MAIL_USERNAME }}>
|
|
body: |
|
|
${{ env.DEPLOY_REPORT }}
|