ci: make canary

This commit is contained in:
ryan
2026-08-16 10:13:39 +08:00
parent 20830d31bd
commit b9b42e3174
+18 -8
View File
@@ -110,30 +110,40 @@ dev:
fi
# Merge local feat into canary, push canary, then restore the previous branch.
# Does not leave the working tree on canary when started from another branch.
# Merge the current local branch into canary, push canary, then restore it.
# Dirty worktrees are auto-stashed and restored after the operation.
canary:
@set -e; \
if ! git rev-parse --git-dir >/dev/null 2>&1; then \
echo "Error: not a git repository"; exit 1; \
fi; \
if [ -n "$$(git status --porcelain)" ]; then \
echo "Error: working tree is dirty; commit or stash first"; exit 1; \
fi; \
orig=$$(git rev-parse --abbrev-ref HEAD); \
if [ "$$orig" = "HEAD" ]; then \
echo "Error: detached HEAD; checkout a branch first"; exit 1; \
fi; \
if [ "$$orig" = "canary" ]; then \
echo "Error: already on canary; checkout a source branch first"; exit 1; \
fi; \
stashed=0; \
if [ -n "$$(git status --porcelain)" ]; then \
echo "Working tree is dirty; stashing local changes..."; \
git stash push -u -m "make canary auto-stash from $$orig"; \
stashed=1; \
fi; \
cleanup() { \
cur=$$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true); \
if [ "$$cur" != "$$orig" ]; then \
echo "Restoring branch $$orig..."; \
git checkout -q "$$orig"; \
fi; \
if [ "$$stashed" = "1" ]; then \
echo "Restoring stashed local changes..."; \
git stash pop; \
fi; \
}; \
trap cleanup EXIT; \
echo "Merging feat -> canary (started from $$orig)..."; \
echo "Merging $$orig -> canary..."; \
git checkout canary; \
git merge --no-edit feat; \
git merge --no-edit "$$orig"; \
git push -u origin canary; \
echo "Done: feat merged into canary and pushed."
echo "Done: $$orig merged into canary and pushed."