import os import subprocess import shutil # GitHubのリポジトリURL repo_url = "https://github.com/izum00/penguinmod-s4s" # 環境変数からトークンを取得 token = os.getenv("github_token") if not token: raise RuntimeError("環境変数 'github_token' が設定されていません。") # 認証情報付きのURLを作成 authed_url = repo_url.replace("https://", f"https://{token}@") # カレントディレクトリのパス current_dir = os.getcwd() # .gitディレクトリがなければ初期化 if not os.path.exists(os.path.join(current_dir, ".git")): subprocess.run(["git", "init"], check=True) subprocess.run(["git", "remote", "add", "origin", authed_url], check=True) else: subprocess.run(["git", "remote", "set-url", "origin", authed_url], check=True) # Gitの操作 subprocess.run(["git", "add", "."], check=True) subprocess.run(["git", "commit", "-m", "auto commit from script"], check=True) subprocess.run(["git", "branch", "-M", "main"], check=True) subprocess.run(["git", "push", "-u", "origin", "main", "--force"], check=True)