优化github action 逻辑
This commit is contained in:
1 parent
f91be983d4
commit
2c6bd1c964
12 files changed
+118
-775
No files matched your search
@@ -3,9 +3,9 @@ name: Deploy to Production
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main # 根据您的实际情况修改分支名称
|
||||
- main
|
||||
schedule:
|
||||
- cron: '0 1 * * *' # UTC 01:00 = 北京时间 09:00
|
||||
- cron: '0 1 * * *' # UTC 01:00 = 北京时间 09:00
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -34,11 +34,10 @@ jobs:
|
||||
- name: Run Pre-Build Scripts
|
||||
shell: pwsh
|
||||
run: |
|
||||
# 自动处理隐藏文章 (防止 status: hidden 的文章意外泄露)
|
||||
./scripts/add_draft_to_hidden.ps1
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: 'npm'
|
||||
@@ -50,43 +49,18 @@ jobs:
|
||||
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
|
||||
- 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/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
|
||||
git commit -m "chore: auto-optimize images [skip ci]"
|
||||
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
|
||||
|
||||
@@ -97,34 +71,14 @@ jobs:
|
||||
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
|
||||
dir: 'public'
|
||||
publish_dir: '/'
|
||||
|
||||
- name: Refresh DogeCloud CDN
|
||||
continue-on-error: true
|
||||
@@ -132,7 +86,18 @@ jobs:
|
||||
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
|
||||
run: node scripts/refresh_cdn.js
|
||||
|
||||
- name: Push Image Optimizations
|
||||
continue-on-error: true
|
||||
run: |
|
||||
git fetch origin main
|
||||
git rebase origin/main
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user