From ade2f58ac554017b8bdaa5ae77bf28f93786ebba Mon Sep 17 00:00:00 2001 From: wangdl Date: Sat, 20 Jun 2026 14:05:05 +0800 Subject: [PATCH] fix(ci): save previous HEAD for reliable change detection - 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 --- .gitea/workflows/deploy.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index ee6b611..fee7094 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -25,9 +25,13 @@ jobs: - name: Checkout run: | 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 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 - name: Install dependencies @@ -126,9 +130,19 @@ jobs: echo "run_compat=true" > /tmp/compat-decision exit 0 fi - # Diff against origin/main to catch all changes in this push - git fetch origin main 2>/dev/null || true - CHANGED=$(git diff --name-only origin/main...HEAD 2>/dev/null || git diff --name-only HEAD~1..HEAD 2>/dev/null || echo "") + # Diff HEAD against previous HEAD saved by build-and-unit checkout step. + # This catches exactly what changed in this push. + 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" 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"