From 1b3922d46db5e1dd0e732d836ea61fcad3f74a95 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 24 Feb 2026 20:03:16 +0000 Subject: [PATCH] Fix CI change detection: save old HEAD before fetch/reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The diff was comparing HEAD vs origin after fetch, but before the first real push they point to the same commit — producing an empty diff and skipping all builds. Now saves HEAD before fetch so the comparison works, and falls back to rebuild-all when HEAD hasn't moved (first deploy or CI re-run on same commit). --- .gitea/workflows/ci.yml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 852020c..e4161e3 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -34,18 +34,28 @@ jobs: run: | ssh "root@$DEPLOY_HOST" " cd ${{ env.COOP_DIR }} - git fetch origin ${{ github.ref_name }} - # Detect what changed since current HEAD - CHANGED=\$(git diff --name-only HEAD origin/${{ github.ref_name }}) + # Save current HEAD before updating + OLD_HEAD=\$(git rev-parse HEAD 2>/dev/null || echo none) + + git fetch origin ${{ github.ref_name }} git reset --hard origin/${{ github.ref_name }} + NEW_HEAD=\$(git rev-parse HEAD) + + # Detect what changed REBUILD_ALL=false - if echo \"\$CHANGED\" | grep -q '^shared/'; then - REBUILD_ALL=true - fi - if echo \"\$CHANGED\" | grep -q '^docker-compose.yml'; then + if [ \"\$OLD_HEAD\" = \"none\" ] || [ \"\$OLD_HEAD\" = \"\$NEW_HEAD\" ]; then + # First deploy or CI re-run on same commit — rebuild all REBUILD_ALL=true + else + CHANGED=\$(git diff --name-only \$OLD_HEAD \$NEW_HEAD) + if echo \"\$CHANGED\" | grep -q '^shared/'; then + REBUILD_ALL=true + fi + if echo \"\$CHANGED\" | grep -q '^docker-compose.yml'; then + REBUILD_ALL=true + fi fi for app in blog market cart events federation account; do