From f9f5c1e2b81068b479438f01b0b4d6060a622d0a Mon Sep 17 00:00:00 2001 From: Xika Date: Thu, 14 May 2026 18:34:25 +0000 Subject: [PATCH] fix(ci): use git reset --hard for staging deploy; fix rollback to avoid pushing reverts (BIT-22325) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Staging CT had diverged local commits from a previous rollback that pushed a revert commit to the remote. git pull --ff-only was failing with "Not possible to fast-forward". Replace with git reset --hard origin/ so staging always matches remote state regardless of local history. Rollback now uses git reset --hard HEAD@{1} locally instead of reverting and pushing to origin — staging rollback has no business touching the remote repo. Paperclip-Issue: BIT-22325 Paperclip-Agent: tiago-neves --- .gitea/workflows/deploy-staging.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/deploy-staging.yml b/.gitea/workflows/deploy-staging.yml index 2f576f5..0e73d99 100644 --- a/.gitea/workflows/deploy-staging.yml +++ b/.gitea/workflows/deploy-staging.yml @@ -45,7 +45,7 @@ jobs: set -euo pipefail BRANCH="${STAGING_GIT_BRANCH:?STAGING_GIT_BRANCH is required}" bash tools/ci/gitea-actions-ssh-config.sh staging "$STAGING_HOST" "$STAGING_USER" "$STAGING_PORT" "$STAGING_SSH_KEY" "$STAGING_SSH_KNOWN_HOSTS" - ssh -F "${HOME}/.ssh/gitea_ci_staging.conf" staging "cd /opt/bitreport/ai-news-writer && git fetch origin && git pull --ff-only origin ${BRANCH} && npm ci --omit=dev" + ssh -F "${HOME}/.ssh/gitea_ci_staging.conf" staging "cd /opt/bitreport/ai-news-writer && git fetch origin && git checkout ${BRANCH} && git reset --hard origin/${BRANCH} && npm ci --omit=dev" ssh -F "${HOME}/.ssh/gitea_ci_staging.conf" staging "cd /opt/bitreport/ai-news-writer && pm2 startOrReload ecosystem.config.cjs --update-env" - name: Health check — staging @@ -75,9 +75,8 @@ jobs: BRANCH="${STAGING_GIT_BRANCH:?STAGING_GIT_BRANCH is required}" bash tools/ci/gitea-actions-ssh-config.sh staging "$STAGING_HOST" "$STAGING_USER" "$STAGING_PORT" "$STAGING_SSH_KEY" "$STAGING_SSH_KNOWN_HOSTS" echo "Attempting automatic rollback to previous commit..." - ssh -F "${HOME}/.ssh/gitea_ci_staging.conf" staging "cd /opt/bitreport/ai-news-writer && git log --oneline -2" - ssh -F "${HOME}/.ssh/gitea_ci_staging.conf" staging "cd /opt/bitreport/ai-news-writer && git revert HEAD -m 1 --no-edit && git push origin ${BRANCH}" - ssh -F "${HOME}/.ssh/gitea_ci_staging.conf" staging "cd /opt/bitreport/ai-news-writer && git fetch origin && git pull --ff-only origin ${BRANCH} && npm ci --omit=dev && pm2 startOrReload ecosystem.config.cjs --update-env" + ssh -F "${HOME}/.ssh/gitea_ci_staging.conf" staging "cd /opt/bitreport/ai-news-writer && git log --oneline -3" + ssh -F "${HOME}/.ssh/gitea_ci_staging.conf" staging "cd /opt/bitreport/ai-news-writer && git reset --hard HEAD@{1} && npm ci --omit=dev && pm2 startOrReload ecosystem.config.cjs --update-env" echo "Staging deployment failed — rollback attempted" exit 1 -- 2.47.3