Repository navigation
Expand file tree
/
Copy pathpush_to_github.py
More file actions
121 lines (96 loc) · 3.5 KB
/
Copy pathpush_to_github.py
File metadata and controls
121 lines (96 loc) · 3.5 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
"""
ViaFabricPlus Bedrock Backport — GitHub push helper
Usage:
python push_to_github.py <github_token> <repo_url>
Example:
python push_to_github.py ghp_xxxx https://github.com/kullanici/viafabricplus-backport.git
"""
import subprocess
import sys
import os
def run(cmd: list[str], check: bool = True) -> subprocess.CompletedProcess:
print(f" $ {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.stdout.strip():
print(result.stdout.strip())
if result.stderr.strip():
print(result.stderr.strip())
if check and result.returncode != 0:
print(f"\n[HATA] Komut basarisiz oldu: {' '.join(cmd)}")
sys.exit(1)
return result
def main():
if len(sys.argv) < 3:
print(__doc__)
sys.exit(1)
token = sys.argv[1].strip()
repo_url = sys.argv[2].strip()
# Token'i URL'ye göm (https://token@github.com/...)
if repo_url.startswith("https://github.com/"):
auth_url = repo_url.replace("https://", f"https://{token}@")
elif repo_url.startswith("https://token@github.com/"):
auth_url = repo_url
else:
print("[HATA] Repo URL'si 'https://github.com/...' formatinda olmali.")
sys.exit(1)
project_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(project_dir)
print(f"\n[*] Proje dizini: {project_dir}")
# Git durumunu kontrol et
is_git = os.path.isdir(os.path.join(project_dir, ".git"))
if not is_git:
print("\n[*] Git repo baslatiliyor...")
run(["git", "init"])
run(["git", "remote", "add", "origin", auth_url])
else:
print("\n[*] Mevcut git repo kullaniliyor...")
result = run(["git", "remote", "get-url", "origin"], check=False)
if result.returncode != 0:
run(["git", "remote", "add", "origin", auth_url])
else:
run(["git", "remote", "set-url", "origin", auth_url])
# .gitignore yoksa oluştur
gitignore_path = os.path.join(project_dir, ".gitignore")
if not os.path.exists(gitignore_path):
print("\n[*] .gitignore olusturuluyor...")
with open(gitignore_path, "w") as f:
f.write("""# Gradle
.gradle/
build/
out/
# IDE
.idea/
*.iml
.vscode/
# OS
.DS_Store
Thumbs.db
# Secrets
push_to_github.py
""")
# Branch adını belirle (main veya master)
result = run(["git", "symbolic-ref", "--short", "HEAD"], check=False)
branch = result.stdout.strip() if result.returncode == 0 else "main"
if not branch:
branch = "main"
print(f"\n[*] Branch: {branch}")
# Kullanici bilgisi
run(["git", "config", "user.email", "build-bot@viafabricplus.local"], check=False)
run(["git", "config", "user.name", "ViaFabricPlus Build Bot"], check=False)
# Stage & commit
print("\n[*] Dosyalar stage'e ekleniyor...")
run(["git", "add", "-A"])
result = run(["git", "status", "--porcelain"], check=False)
if not result.stdout.strip():
print("\n[OK] Yeni degisiklik yok, push atlandi.")
sys.exit(0)
run(["git", "commit", "-m", "fix: remove faulty block mixins, add GitHub Actions CI"])
# Push
print(f"\n[*] GitHub'a push ediliyor: {repo_url}")
run(["git", "push", "-u", "origin", f"HEAD:{branch}", "--force"])
print(f"\n[OK] Basariyla push edildi! Repo: {repo_url}")
print(f" GitHub Actions otomatik olarak JAR'i derleyecek.")
print(f" Ilerlemeyi buradan takip edin: {repo_url.replace('.git', '')}/actions")
if __name__ == "__main__":
main()