From aee3733b49a1e2c1f3a039892a084dde9e67d8c5 Mon Sep 17 00:00:00 2001 From: Deeman Date: Sat, 28 Feb 2026 21:02:30 +0100 Subject: [PATCH] fix(supervisor+ci): self-restart on deploy, CI creates date-based tags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit supervisor: after git checkout + uv sync, os.execv replaces the running process so new code takes effect immediately without a manual systemd restart. systemd sees the same PID, so the unit stays "active". ci: changed tag format from v{run_number} to v{YYYYMMDDHHMM}, matching the supervisor's deploy tag convention. Sequential v tags conflicted with manual date-based tags causing an infinite redeploy loop. No more manual tagging needed — CI tags automatically after green tests. Co-Authored-By: Claude Sonnet 4.6 --- .gitea/workflows/ci.yaml | 11 ++++++----- src/padelnomics/supervisor.py | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index f8f0087..2225e11 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -17,9 +17,9 @@ jobs: - run: uv run pytest web/tests/ -x -q -p no:faulthandler - run: uv run ruff check web/src/ web/tests/ - # Creates v tag after tests pass. The on-server supervisor polls for new - # tags every 60s and deploys automatically. No SSH keys or deploy credentials - # needed in CI — only the built-in github.token. + # Creates a v{YYYYMMDDHHMM} tag after tests pass on master. + # The on-server supervisor polls for new tags every 60s and deploys + # automatically. No SSH keys or deploy credentials needed in CI. tag: needs: [test] runs-on: ubuntu-latest @@ -32,5 +32,6 @@ jobs: run: | git config user.name "CI" git config user.email "ci@noreply" - git tag "v${{ github.run_number }}" - git push origin "v${{ github.run_number }}" + TAG="v$(date -u +%Y%m%d%H%M)" + git tag "$TAG" + git push origin "$TAG" diff --git a/src/padelnomics/supervisor.py b/src/padelnomics/supervisor.py index 8815c90..d5cd8f4 100644 --- a/src/padelnomics/supervisor.py +++ b/src/padelnomics/supervisor.py @@ -327,6 +327,10 @@ def git_pull_and_sync() -> None: run_shell(f"git checkout --detach {latest}") run_shell("sops --input-type dotenv --output-type dotenv -d .env.prod.sops > .env") run_shell("uv sync --all-packages") + # Re-exec so the new code is loaded. os.execv replaces this process in-place; + # systemd sees it as the same PID and does not restart the unit. + logger.info("Deploy complete — re-execing to load new code") + os.execv(sys.executable, sys.argv) # ---------------------------------------------------------------------------