Spaces:
Runtime error
Runtime error
File size: 1,348 Bytes
d76619e 2cd2947 7860e2c d76619e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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()
subprocess.run(["git", "config", "--global", "user.name", "izum00"], check=True)
subprocess.run(["git", "config", "--global", "user.email", os.getenv("mail")], check=True)
subprocess.run(["git", "config", "--global", "--add", "safe.directory", "/app"], check=True)
# .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)
|