import os import subprocess from pathlib import Path repo = Path(r"C:\Development\Songs2YT") token = os.environ["GITEA_TOKEN"] remote = f"https://oauth2:{token}@git.atakanozban.com/Songs2YT/songs2yt.git" safe_remote = "https://git.atakanozban.com/Songs2YT/songs2yt.git" def run(args: list[str], check: bool = True) -> subprocess.CompletedProcess: print(">>", " ".join(args), flush=True) result = subprocess.run( args, cwd=repo, capture_output=True, text=True, encoding="utf-8", errors="replace", ) if result.stdout.strip(): print(result.stdout.strip(), flush=True) if result.stderr.strip(): # redact token if somehow present err = result.stderr.replace(token, "***") print(err.strip(), flush=True) if check and result.returncode != 0: raise SystemExit(f"FAILED ({result.returncode})") return result os.chdir(repo) # Ensure gitignore covers secrets / junk gi = repo / ".gitignore" extra = [ "*.tgz", ".DS_Store", "basibozuk_cover.jpg", "bg-video/", "scripts/", "_restore/", ] text = gi.read_text(encoding="utf-8") if gi.exists() else "" for line in extra: if line not in text: text = text.rstrip() + "\n" + line + "\n" gi.write_text(text, encoding="utf-8") run(["git", "init", "-b", "main"]) run(["git", "config", "user.email", "songs2yt@atakanozban.com"]) run(["git", "config", "user.name", "Songs2YT"]) run(["git", "add", "-A"]) run(["git", "status", "--short"]) run( [ "git", "commit", "-m", "Initial open-source self-hosted Songs2YT edition", ] ) run(["git", "remote", "remove", "origin"], check=False) run(["git", "remote", "add", "origin", remote]) # Push and set upstream run(["git", "push", "-u", "origin", "main"]) # Replace remote URL without token for local safety run(["git", "remote", "set-url", "origin", safe_remote]) run(["git", "remote", "-v"]) run(["git", "log", "-1", "--oneline"]) print("PUBLISH_OK", flush=True)