fix(ci): save previous HEAD for reliable change detection
Some checks failed
Deploy API Server / current-integration (push) Has been cancelled
Deploy API Server / backward-compat (push) Has been cancelled
Deploy API Server / deploy (push) Has been cancelled
Deploy API Server / build-and-unit (push) Has been cancelled

- build-and-unit saves git rev-parse HEAD before reset
- backward-compat uses saved PREV to compute exact diff
- Falls back to HEAD~3 diff if prev-head is missing

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-20 14:05:05 +08:00
parent 96b0094c5a
commit ade2f58ac5

View File

@ -25,9 +25,13 @@ jobs:
- name: Checkout - name: Checkout
run: | run: |
if [ -d $WORKDIR ]; then if [ -d $WORKDIR ]; then
cd $WORKDIR && git fetch origin && git reset --hard origin/main cd $WORKDIR
# Save previous HEAD before reset — used by backward-compat for change detection
git rev-parse HEAD > /tmp/prev-head 2>/dev/null || true
git fetch origin && git reset --hard origin/main
else else
git clone http://10.2.0.7:3000/wangdl/api-server.git $WORKDIR git clone http://10.2.0.7:3000/wangdl/api-server.git $WORKDIR
git rev-parse HEAD > /tmp/prev-head 2>/dev/null || true
fi fi
- name: Install dependencies - name: Install dependencies
@ -126,9 +130,19 @@ jobs:
echo "run_compat=true" > /tmp/compat-decision echo "run_compat=true" > /tmp/compat-decision
exit 0 exit 0
fi fi
# Diff against origin/main to catch all changes in this push # Diff HEAD against previous HEAD saved by build-and-unit checkout step.
git fetch origin main 2>/dev/null || true # This catches exactly what changed in this push.
CHANGED=$(git diff --name-only origin/main...HEAD 2>/dev/null || git diff --name-only HEAD~1..HEAD 2>/dev/null || echo "") PREV=$(cat /tmp/prev-head 2>/dev/null || echo "")
if [ -n "$PREV" ] && [ "$PREV" != "$(git rev-parse HEAD)" ]; then
CHANGED=$(git diff --name-only $PREV..HEAD 2>/dev/null || echo "")
else
# Fallback: check last 3 commits
CHANGED=""
for n in 1 2 3; do
CHANGED="$CHANGED $(git diff --name-only HEAD~$n..HEAD 2>/dev/null || echo "")"
done
fi
echo "Previous HEAD: ${PREV:-none}"
echo "Changed files: $CHANGED" echo "Changed files: $CHANGED"
if echo "$CHANGED" | grep -qE "prisma/schema.prisma|prisma/migrations/|src/modules/ai-analysis/|src/workers/ai-analysis.worker.ts|src/infrastructure/queue/|src/infrastructure/outbox/|src/modules/ai-runtime/ai-job"; then if echo "$CHANGED" | grep -qE "prisma/schema.prisma|prisma/migrations/|src/modules/ai-analysis/|src/workers/ai-analysis.worker.ts|src/infrastructure/queue/|src/infrastructure/outbox/|src/modules/ai-runtime/ai-job"; then
echo "DB-related changes detected — running backward compatibility" echo "DB-related changes detected — running backward compatibility"