Update wrapper/wrapper.py

This commit is contained in:
frarol96 2025-08-24 13:09:17 +00:00
parent f28ea8cf9f
commit 7d509f5b98

View File

@ -2,11 +2,12 @@ import os, sys, time, shutil, subprocess, signal, json, pathlib, re, datetime
from typing import Tuple from typing import Tuple
# ---------- Config (env) ---------- # ---------- Config (env) ----------
REPO_URL = os.getenv("REPO_URL", "").strip() # Provide sane defaults so a plain run works without envs.
REPO_URL = os.getenv("REPO_URL", "https://git.rolfsvaag.no/frarol96/shaiwatcher.git").strip()
REPO_BRANCH = os.getenv("REPO_BRANCH", "main").strip() REPO_BRANCH = os.getenv("REPO_BRANCH", "main").strip()
REPO_TOKEN = os.getenv("REPO_TOKEN", "").strip() # optional REPO_TOKEN = os.getenv("REPO_AHTOKEN", os.getenv("REPO_TOKEN", "")).strip() # optional
# prefer CHECK_TIME_UTC; fall back to old RECHECK_UTC # prefer CHECK_TIME_UTC; fall back to old RECHECK_UTC (kept for compatibility with your wrapper envs only)
CHECK_TIME_UTC = os.getenv("CHECK_TIME_UTC", os.getenv("RECHECK_UTC", "03:00")).strip() CHECK_TIME_UTC = os.getenv("CHECK_TIME_UTC", os.getenv("RECHECK_UTC", "03:00")).strip()
# 1 = ignore test-only bumps (e.g. v1.2.3.4-T3 -> v1.2.3.4-T4) # 1 = ignore test-only bumps (e.g. v1.2.3.4-T3 -> v1.2.3.4-T4)
@ -133,12 +134,12 @@ def pip_install(cwd: pathlib.Path):
log(e.stdout + "\n" + e.stderr) log(e.stdout + "\n" + e.stderr)
def set_boot_env(status: str, old_ver: str, new_ver: str, commit: str = "", subject: str = ""): def set_boot_env(status: str, old_ver: str, new_ver: str, commit: str = "", subject: str = ""):
# Env passed to the bot; bot should read and post to modlog on_ready # Env passed to the bot; if you later choose to use them, they're non-SHAI now.
os.environ["SHAI_BOOT_STATUS"] = status os.environ["BOOT_STATUS"] = status
os.environ["SHAI_BOOT_OLDVER"] = old_ver os.environ["BOOT_OLDVER"] = old_ver
os.environ["SHAI_BOOT_NEWVER"] = new_ver os.environ["BOOT_NEWVER"] = new_ver
os.environ["SHAI_BUILD_COMMIT"] = commit os.environ["BUILD_COMMIT"] = commit
os.environ["SHAI_BUILD_SUBJECT"]= subject os.environ["BUILD_SUBJECT"] = subject
def get_head_info(cwd: pathlib.Path) -> Tuple[str,str]: def get_head_info(cwd: pathlib.Path) -> Tuple[str,str]:
try: try:
@ -152,8 +153,8 @@ def get_head_info(cwd: pathlib.Path) -> Tuple[str,str]:
def start_bot(cwd: pathlib.Path) -> subprocess.Popen: def start_bot(cwd: pathlib.Path) -> subprocess.Popen:
env = os.environ.copy() env = os.environ.copy()
# Make sure data dir exists (the bot should use SHAI_DATA or SHAI_DATA_FILE or config) # Make sure data file env is present under the new name (no SHAI_).
env.setdefault("SHAI_DATA", "/data/data.json") env.setdefault("DATA_FILE", "/data/data.json")
# Run from the cached code directory # Run from the cached code directory
return subprocess.Popen([sys.executable, "-u", "bot.py"], cwd=cwd, env=env) return subprocess.Popen([sys.executable, "-u", "bot.py"], cwd=cwd, env=env)
@ -207,7 +208,8 @@ def run_loop():
while True: while True:
# sleep until next check (03:00 UTC by default) # sleep until next check (03:00 UTC by default)
delay = next_utc(CHECK_TIME_UTC) delay = next_utc(CHECK_TIME_UTC)
log(f"sleeping {int(delay)}s until {RECHECK_UTC} UTC for update check") # FIX: use CHECK_TIME_UTC here (your original printed RECHECK_UTC)
log(f"sleeping {int(delay)}s until {CHECK_TIME_UTC} UTC for update check")
time.sleep(delay) time.sleep(delay)
# check for update # check for update