feat: 优化书签工作流步骤
This commit is contained in:
157
.github/workflows/deploy.yml
vendored
157
.github/workflows/deploy.yml
vendored
@@ -16,11 +16,17 @@ permissions:
|
|||||||
|
|
||||||
# 允许一个并发部署
|
# 允许一个并发部署
|
||||||
concurrency:
|
concurrency:
|
||||||
group: 'pages'
|
# 说明:
|
||||||
|
# - 本工作流在检测到 bookmarks/*.html 时会自动导入并 push 回主分支
|
||||||
|
# - 若 concurrency group 统一为固定值,会导致“自触发的 push run”取消当前正在部署的 run(cancel-in-progress)
|
||||||
|
# - 这里仅对 actions bot 的 push run 单独分组,避免误取消当前 run;其余触发保持全局串行
|
||||||
|
group: ${{ github.event_name == 'push' && github.actor == 'github-actions[bot]' && 'pages-bot-push' || 'pages' }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_and_deploy:
|
build_and_deploy:
|
||||||
|
# 防自触发:CI 自己 push 产生的 push 事件不需要再部署(本次 run 已完成导入并继续部署)
|
||||||
|
if: ${{ github.event_name != 'push' || github.actor != 'github-actions[bot]' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -59,120 +65,47 @@ jobs:
|
|||||||
echo "Processing bookmark files..."
|
echo "Processing bookmark files..."
|
||||||
node src/bookmark-processor.js
|
node src/bookmark-processor.js
|
||||||
|
|
||||||
- name: Debug directory contents
|
- name: Commit & push bookmark import result (single commit)
|
||||||
if: steps.check_bookmark_files.outputs.found == 'true'
|
if: steps.check_bookmark_files.outputs.found == 'true'
|
||||||
run: |
|
|
||||||
echo "Current directory contents:"
|
|
||||||
ls -la
|
|
||||||
echo "Checking config/user/pages directory:"
|
|
||||||
if [ -d config/user/pages ]; then
|
|
||||||
echo "Directory exists, listing contents:"
|
|
||||||
ls -la config/user/pages/
|
|
||||||
if [ -f config/user/pages/bookmarks.yml ]; then
|
|
||||||
echo "✓ bookmarks.yml exists in config/user/pages/"
|
|
||||||
cat config/user/pages/bookmarks.yml | head -n 10
|
|
||||||
else
|
|
||||||
echo "✗ bookmarks.yml does not exist in config/user/pages/"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "✗ config/user/pages directory does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Commit bookmark configuration changes
|
|
||||||
if: steps.check_bookmark_files.outputs.found == 'true'
|
|
||||||
run: |
|
|
||||||
git config --local user.email "action@github.com"
|
|
||||||
git config --local user.name "GitHub Action (Bookmarks)"
|
|
||||||
|
|
||||||
# Check if config/user/pages/bookmarks.yml exists
|
|
||||||
if [ -f config/user/pages/bookmarks.yml ]; then
|
|
||||||
# Check if this is a new file or it has changes
|
|
||||||
if git ls-files --error-unmatch config/user/pages/bookmarks.yml 2>/dev/null; then
|
|
||||||
echo "config/user/pages/bookmarks.yml exists and is tracked by git"
|
|
||||||
# Check if it has changes
|
|
||||||
if ! git diff --quiet config/user/pages/bookmarks.yml; then
|
|
||||||
echo "config/user/pages/bookmarks.yml has changes, committing..."
|
|
||||||
git add config/user/pages/bookmarks.yml
|
|
||||||
git commit -m "Update bookmarks configuration from imported bookmarks"
|
|
||||||
else
|
|
||||||
echo "No changes to bookmarks configuration"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "config/user/pages/bookmarks.yml exists but is not tracked by git (new file)"
|
|
||||||
git add config/user/pages/bookmarks.yml
|
|
||||||
git commit -m "Add bookmarks configuration from imported bookmarks"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Also check for site.yml changes(导航已合并到 site.yml)
|
|
||||||
if [ -f config/user/site.yml ]; then
|
|
||||||
if ! git diff --quiet config/user/site.yml; then
|
|
||||||
echo "config/user/site.yml has changes, committing..."
|
|
||||||
git add config/user/site.yml
|
|
||||||
git commit -m "Update site configuration for bookmarks"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
echo "ERROR: config/user/pages/bookmarks.yml does not exist! Bookmark processing may have failed."
|
|
||||||
echo "Current directory contents:"
|
|
||||||
ls -la config/user/pages/ || echo "Directory does not exist"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Clean up processed bookmark files
|
|
||||||
if: steps.check_bookmark_files.outputs.found == 'true'
|
|
||||||
run: |
|
|
||||||
# 先记录当前HTML文件列表
|
|
||||||
HTML_FILES=$(find bookmarks -type f -name "*.html" 2>/dev/null)
|
|
||||||
if [ -n "$HTML_FILES" ]; then
|
|
||||||
git config --local user.email "action@github.com"
|
|
||||||
git config --local user.name "GitHub Action (Cleanup)"
|
|
||||||
echo "HTML files before cleanup:"
|
|
||||||
echo "$HTML_FILES" | tee html_files_before.txt
|
|
||||||
|
|
||||||
# 计算文件数量
|
|
||||||
FILE_COUNT=$(echo "$HTML_FILES" | wc -l)
|
|
||||||
echo "Found $FILE_COUNT HTML files to clean up."
|
|
||||||
|
|
||||||
# 执行删除操作
|
|
||||||
echo "Cleaning up HTML files..."
|
|
||||||
find bookmarks -type f -name "*.html" -delete
|
|
||||||
|
|
||||||
# 验证文件已被删除
|
|
||||||
REMAINING=$(find bookmarks -type f -name "*.html" 2>/dev/null)
|
|
||||||
if [ -z "$REMAINING" ]; then
|
|
||||||
echo "All HTML files successfully deleted."
|
|
||||||
# 不管git diff结果如何,只要有文件被删除就提交
|
|
||||||
git add bookmarks/
|
|
||||||
git commit -m "Clean up processed bookmark files ($FILE_COUNT files removed)"
|
|
||||||
echo "Changes committed."
|
|
||||||
else
|
|
||||||
echo "WARNING: Some HTML files could not be deleted:"
|
|
||||||
echo "$REMAINING"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "No HTML files found to clean up."
|
|
||||||
fi
|
|
||||||
# --- 书签处理步骤结束 ---
|
|
||||||
- name: Push configuration changes (if any)
|
|
||||||
# 只有在书签处理步骤修改了文件时才推送
|
|
||||||
# 使用 GITHUB_TOKEN 推送
|
|
||||||
if: steps.check_bookmark_files.outputs.found == 'true'
|
|
||||||
run: |
|
|
||||||
echo "Checking git status before pushing..."
|
|
||||||
git status
|
|
||||||
|
|
||||||
echo "Checking config/user/pages directory before pushing..."
|
|
||||||
if [ -d config/user/pages ]; then
|
|
||||||
echo "✓ config/user/pages directory exists"
|
|
||||||
ls -la config/user/pages/
|
|
||||||
else
|
|
||||||
echo "✗ WARNING: config/user/pages directory does not exist before pushing!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Pushing changes to repository..."
|
|
||||||
git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" HEAD:${{ github.ref_name }}
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# 校验导入结果(核心产物必须存在)
|
||||||
|
if [ ! -f config/user/pages/bookmarks.yml ]; then
|
||||||
|
echo "ERROR: config/user/pages/bookmarks.yml does not exist! Bookmark processing may have failed."
|
||||||
|
echo "Directory listing for config/user/pages:"
|
||||||
|
ls -la config/user/pages/ || echo "Directory does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Cleaning up processed bookmark HTML files..."
|
||||||
|
HTML_FILES=$(find bookmarks -type f -name "*.html" 2>/dev/null || true)
|
||||||
|
FILE_COUNT=0
|
||||||
|
if [ -n "${HTML_FILES}" ]; then
|
||||||
|
FILE_COUNT=$(echo "${HTML_FILES}" | wc -l | tr -d ' ')
|
||||||
|
find bookmarks -type f -name "*.html" -delete
|
||||||
|
echo "Removed ${FILE_COUNT} HTML files."
|
||||||
|
else
|
||||||
|
echo "No HTML files found to clean up."
|
||||||
|
fi
|
||||||
|
|
||||||
|
git config --local user.email "action@github.com"
|
||||||
|
git config --local user.name "github-actions[bot]"
|
||||||
|
|
||||||
|
# 注意:配置系统采用“完全替换”,一旦写回 config/user/,后续构建会忽略 config/_default/
|
||||||
|
# 因此这里必须整体提交 config/user/(避免只提交书签页导致其它页面配置缺失)
|
||||||
|
git add -A config/user bookmarks
|
||||||
|
|
||||||
|
if git diff --cached --quiet; then
|
||||||
|
echo "No changes to commit."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
git commit -m "chore(bookmarks): 导入书签并写回用户配置"
|
||||||
|
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" HEAD:${{ github.ref_name }}
|
||||||
|
# --- 书签处理步骤结束 ---
|
||||||
|
|
||||||
# --- 网站构建和部署步骤 ---
|
# --- 网站构建和部署步骤 ---
|
||||||
# 同步时效性数据(best-effort):projects 仓库信息、articles RSS 聚合
|
# 同步时效性数据(best-effort):projects 仓库信息、articles RSS 聚合
|
||||||
|
|||||||
Reference in New Issue
Block a user