@@ -68,50 +68,48 @@ jobs:
6868 git config --global user.email chainreactorbot@gmail.com
6969 git config --global user.name chainreactorbot
7070
71- # Stash any changes in master branch (like today_pick.md)
72- git stash push -m "Temporary stash for today_pick.md" || true
73-
7471 # Get date variables
7572 year=$(date -d yesterday +'%Y')
7673 month=$(date -d yesterday +'%m')
7774 day=$(date -d yesterday +'%d')
7875
79- # Move archive directory to temporary location
80- temp_archive="/tmp/archive_temp_${year}_${month}_${day}"
81- if [ -d "archive/${year}/${month}/${day}" ]; then
82- mkdir -p "$temp_archive"
83- mv "archive/${year}/${month}/${day}" "$temp_archive/"
84- fi
85-
8676 # Fetch archive branch
87- git fetch origin archive
88-
89- # Use sparse-checkout to avoid long filename issues
90- git config core.sparseCheckout true
91- echo "archive/${year}/" > .git/info/sparse-checkout
77+ git fetch origin archive:archive 2>/dev/null || echo "Archive branch will be created"
9278
93- # Checkout archive branch with sparse checkout
79+ # Create a worktree for archive branch
80+ worktree_path="/tmp/archive_worktree_$$"
9481 if git show-ref --verify --quiet refs/heads/archive; then
95- git checkout -f archive
82+ # Archive branch exists, create worktree from it with sparse-checkout
83+ git worktree add --no-checkout "$worktree_path" archive
84+ cd "$worktree_path"
85+ git sparse-checkout set "archive/${year}/"
86+ git checkout
9687 else
97- git checkout -b archive origin/archive 2>/dev/null || git checkout --orphan archive
88+ # Create orphan branch
89+ git worktree add --detach "$worktree_path"
90+ cd "$worktree_path"
91+ git checkout --orphan archive
92+ git rm -rf . 2>/dev/null || true
9893 fi
9994
100- # Move files back
101- if [ -d "$temp_archive /${day}" ]; then
95+ # Copy new files to worktree
96+ if [ -d "/home/runner/work/picker/picker/archive/${year}/${month} /${day}" ]; then
10297 mkdir -p "archive/${year}/${month}"
103- mv "$temp_archive /${day}" "archive/${year}/${month}/"
98+ cp -r "/home/runner/work/picker/picker/archive/${year}/${month} /${day}" "archive/${year}/${month}/"
10499 fi
105100
106- # Add and commit changes
101+ # Commit and push
107102 git add "archive/${year}/${month}/${day}/"
108- git diff --staged --quiet || git commit -m "每日精选汇总(`date +'%Y-%m-%d'`)"
109-
110- # Push to archive branch
111- git push origin archive
103+ if git diff --staged --quiet; then
104+ echo "No changes to commit"
105+ else
106+ git commit -m "每日精选汇总(`date +'%Y-%m-%d'`)"
107+ git push origin archive
108+ fi
112109
113- # Disable sparse-checkout for next steps
114- git config core.sparseCheckout false
110+ # Cleanup
111+ cd /home/runner/work/picker/picker
112+ git worktree remove "$worktree_path" --force
115113
116114 - name : Update today_pick.md in master
117115 run : |
0 commit comments