Files
blog/.github/workflows/upy.yml
T
2026-01-30 22:30:11 +08:00

137 lines
4.0 KiB
YAML

name: Deploy to UpYun
on:
push:
branches:
- main # 根据您的实际情况修改分支名称
schedule:
- cron: '0 */12 * * *' # 每十二小时自动构建一次
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.128.2'
extended: true
- name: Run Pre-Build Scripts
shell: pwsh
run: |
# 1. 自动生成友链 JSON (即使本地漏提交也能保证是最新的)
./scripts/update_link_lite_json.ps1
# 2. 自动处理隐藏文章 (防止 status: hidden 的文章意外泄露)
./scripts/add_draft_to_hidden.ps1
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Node.js dependencies
run: npm install
- name: Generate AI Comments
env:
SILICONFLOW_API_KEY: ${{ secrets.SILICONFLOW_API_KEY }}
AI_PROVIDER: siliconflow
run: node scripts/ai_comment.js
- name: Commit AI Comments
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-generate ai comments [skip ci]"
git push
else
echo "No changes to commit"
fi
- name: Generate Friend Circle Data
run: node scripts/generate_circle_data.js
- name: Build
run: rm -rf public && hugo --minify
- name: Debug Environment Variables
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
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: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d %H:%M:%S')"
- name: Send deployment success 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: 部署成功通知 - ${{ github.repository }}
to: ${{ secrets.MAIL_USERNAME }}
from: GitHub Actions <${{ secrets.MAIL_USERNAME }}>
body: |
🎉 部署已成功完成!
📦 仓库信息
----------------------------------
仓库: ${{ github.repository }}
分支: ${{ github.ref_name }}
提交: ${{ github.sha }}
信息: ${{ github.event.head_commit.message }}
👤 触发信息
----------------------------------
触发人: ${{ github.actor }}
事件: ${{ github.event_name }}
工作流: ${{ github.workflow }}
时间: ${{ steps.date.outputs.date }}
🔗 详情链接
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}