-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpush_to_github.py
More file actions
134 lines (100 loc) · 4 KB
/
push_to_github.py
File metadata and controls
134 lines (100 loc) · 4 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
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python
"""
Script to push OpenArchX to GitHub.
"""
import os
import sys
import subprocess
import argparse
def run_command(command, verbose=True):
"""Run a command and return its output."""
if verbose:
print(f"Running: {' '.join(command)}")
result = subprocess.run(command, capture_output=True, text=True)
if result.returncode != 0:
print(f"Error executing command: {' '.join(command)}")
print(f"Error message: {result.stderr}")
sys.exit(1)
return result.stdout.strip()
def check_git_installed():
"""Check if git is installed."""
try:
run_command(["git", "--version"], verbose=False)
return True
except FileNotFoundError:
print("Error: Git is not installed or not in the PATH.")
print("Please install Git and try again.")
return False
def check_git_repository():
"""Check if the current directory is a git repository."""
try:
run_command(["git", "rev-parse", "--is-inside-work-tree"], verbose=False)
return True
except subprocess.CalledProcessError:
return False
def setup_git_repository(repo_url):
"""Set up a git repository if it doesn't exist."""
if check_git_repository():
print("Git repository already set up.")
# Check remote URL
remote_url = run_command(["git", "config", "--get", "remote.origin.url"], verbose=False)
if remote_url != repo_url:
print(f"Updating remote URL from {remote_url} to {repo_url}")
run_command(["git", "remote", "set-url", "origin", repo_url])
else:
print("Initializing new Git repository")
run_command(["git", "init"])
run_command(["git", "remote", "add", "origin", repo_url])
def check_changes():
"""Check if there are any changes to commit."""
status = run_command(["git", "status", "--porcelain"])
return status != ""
def commit_changes(message):
"""Commit changes with the specified message."""
run_command(["git", "add", "."])
run_command(["git", "commit", "-m", message])
def push_to_github(branch="main", force=False):
"""Push changes to GitHub."""
command = ["git", "push", "origin", branch]
if force:
command.append("--force")
run_command(command)
def tag_release(version, message=None):
"""Tag a release with the specified version."""
if message is None:
message = f"Release version {version}"
run_command(["git", "tag", "-a", f"v{version}", "-m", message])
run_command(["git", "push", "origin", f"v{version}"])
def main():
"""Main function to push OpenArchX to GitHub."""
parser = argparse.ArgumentParser(description="Push OpenArchX to GitHub")
parser.add_argument("--repo", default="https://github.com/TnsaAi/OpenArchX.git",
help="GitHub repository URL")
parser.add_argument("--message", "-m", default="Update OpenArchX framework",
help="Commit message")
parser.add_argument("--branch", default="main", help="Branch to push to")
parser.add_argument("--tag", help="Tag version (e.g., 1.0.0)")
parser.add_argument("--tag-message", help="Tag message")
parser.add_argument("--force", "-f", action="store_true", help="Force push")
args = parser.parse_args()
# Check if git is installed
if not check_git_installed():
sys.exit(1)
# Set up git repository
setup_git_repository(args.repo)
# Check if there are changes to commit
if check_changes():
# Commit changes
commit_changes(args.message)
else:
print("No changes to commit")
# Push changes to GitHub
print(f"Pushing to GitHub ({args.branch})")
push_to_github(args.branch, args.force)
# Tag release if specified
if args.tag:
print(f"Tagging release v{args.tag}")
tag_release(args.tag, args.tag_message)
print("Successfully pushed to GitHub!")
if __name__ == "__main__":
main()