Files
blog/.github/workflows/deploy.yml
T

159 lines
4.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@v2
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: |
# 自动处理隐藏文章 (防止 status: hidden 的文章意外泄露)
./scripts/add_draft_to_hidden.ps1
- name: Setup Node
uses: actions/setup-node@v3
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: Generate AI Comments
continue-on-error: true
env:
SILICONFLOW_API_KEY: ${{ secrets.SILICONFLOW_API_KEY }}
AI_PROVIDER: siliconflow
run: node scripts/ai_comment.js
- name: Commit Optimized Images and AI Comments
continue-on-error: true
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git add content/post
if ! git diff --staged --quiet; then
git commit -m "chore: auto-optimize images and generate ai comments [skip ci]"
git fetch origin main
git rebase origin/main
git push origin HEAD:main
else
echo "No changes to commit"
fi
- name: Check Link Status
continue-on-error: true
run: node scripts/check_links.js
- name: Read Failed Links Summary
continue-on-error: true
if: always()
run: |
if [ -f failed_links_summary.txt ]; then
echo "LINK_SUMMARY<<EOF" >> $GITHUB_ENV
cat failed_links_summary.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
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: Debug Environment Variables
continue-on-error: true
run: |
echo "Bucket: ${{ secrets.UPYUN_BUCKET }}"
echo "Operator: ${{ secrets.UPYUN_OPERATOR }}"
# 不推荐打印密码,但可以确认是否为空字符串
if [ -z "${{ secrets.UPYUN_PASSWORD }}" ]; then
echo "Password is empty or not set"
else
echo "Password is set"
fi
- 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: '/' # 发布到 UpYun 的根目录
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: pip install requests
- 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: python scripts/RefreshCDN.py
- 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 }}