Fix CI change detection: save old HEAD before fetch/reset

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).
This commit is contained in:
giles
2026-02-24 20:03:16 +00:00
parent f42042ccb7
commit 1b3922d46d

View File

@@ -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