Skip to content

Commit 237e687

Browse files
committed
fix: streamline git fetch and commit process in CI workflow
1 parent 15e7eff commit 237e687

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

.github/workflows/ci_k8_base.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,11 @@ jobs:
283283
git worktree remove --force ../deploy-worktree || true
284284
fi
285285
286-
# Fetch remote branch into local if needed
287-
if ! git show-ref --verify --quiet refs/remotes/origin/$BRANCH; then
288-
git fetch origin $BRANCH:$BRANCH || git checkout --orphan $BRANCH
289-
else
290-
git fetch origin $BRANCH
291-
fi
286+
# Fetch latest remote branch
287+
git fetch origin $BRANCH || git checkout --orphan $BRANCH
292288
293289
# Add isolated worktree for that branch
294-
git worktree add ../deploy-worktree $BRANCH
290+
git worktree add ../deploy-worktree FETCH_HEAD
295291
296292
# Ensure destination directory exists
297293
mkdir -p "$(dirname ../deploy-worktree/$FILE)"
@@ -302,9 +298,13 @@ jobs:
302298
# Commit and push if there are changes
303299
cd ../deploy-worktree
304300
git add "$FILE"
305-
git commit -m "chore(ci): promote to $ENV [skip ci]" || echo "⚠️ Nothing to commit"
306-
git push origin $BRANCH
307-
301+
if git commit -m "chore(ci): promote to $ENV [skip ci]"; then
302+
# Rebase to preserve remote history
303+
git pull --rebase origin $BRANCH
304+
git push origin HEAD:$BRANCH
305+
else
306+
echo "⚠️ Nothing to commit"
307+
fi
308308
309309
- name: Check if there are commits between staging to main
310310
id: check_commits

0 commit comments

Comments
 (0)