Compare commits
2 Commits
60258b0ba6
...
7e50ac4f06
Author | SHA1 | Date |
---|---|---|
Brett | 7e50ac4f06 | |
Brett | ee4918ca36 |
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
project(COSC-4P80-Assignment-1 VERSION 13.4.0)
|
project(COSC-4P80-Assignment-1 VERSION 13.6.0)
|
||||||
|
|
||||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||||
|
|
77
commit.py
77
commit.py
|
@ -24,14 +24,19 @@ USER_HOME = Path.home()
|
||||||
ENVIRONMENT_DATA_LOCATION = USER_HOME / ".brett_scripts.env"
|
ENVIRONMENT_DATA_LOCATION = USER_HOME / ".brett_scripts.env"
|
||||||
|
|
||||||
if sys.platform.startswith("win"):
|
if sys.platform.startswith("win"):
|
||||||
CONFIG_FILE_DIRECTORY = Path(os.getenv('APPDATA') + "\BLT")
|
CONFIG_FILE_DIRECTORY = Path(os.getenv('APPDATA') + "\blt")
|
||||||
CONFIG_FILE_LOCATION = Path(CONFIG_FILE_DIRECTORY + "\commit_config.env")
|
CONFIG_FILE_LOCATION = Path(CONFIG_FILE_DIRECTORY + "\commit_config.json")
|
||||||
else:
|
else:
|
||||||
XDG_CONFIG_HOME = Path(os.environ.get('XDG_CONFIG_HOME'))
|
XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME')
|
||||||
|
if XDG_CONFIG_HOME is None:
|
||||||
|
XDG_CONFIG_HOME = USER_HOME / ".config"
|
||||||
|
else:
|
||||||
|
XDG_CONFIG_HOME = Path(XDG_CONFIG_HOME)
|
||||||
|
|
||||||
if len(str(XDG_CONFIG_HOME)) == 0:
|
if len(str(XDG_CONFIG_HOME)) == 0:
|
||||||
XDG_CONFIG_HOME = USER_HOME
|
XDG_CONFIG_HOME = USER_HOME
|
||||||
CONFIG_FILE_DIRECTORY = XDG_CONFIG_HOME / "blt"
|
CONFIG_FILE_DIRECTORY = XDG_CONFIG_HOME / "blt"
|
||||||
CONFIG_FILE_LOCATION = CONFIG_FILE_DIRECTORY / "commit_config.env"
|
CONFIG_FILE_LOCATION = CONFIG_FILE_DIRECTORY / "commit_config.json"
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -39,31 +44,30 @@ class Config:
|
||||||
self.branch_on_major = True
|
self.branch_on_major = True
|
||||||
self.branch_on_minor = False
|
self.branch_on_minor = False
|
||||||
self.release_on_major = True
|
self.release_on_major = True
|
||||||
self.release_on_minor = False
|
self.release_on_minor = True
|
||||||
self.main_branch = "main"
|
self.main_branch = "main"
|
||||||
self.patch_limit = -1
|
self.patch_limit = -1
|
||||||
|
|
||||||
|
def toJSON(self):
|
||||||
|
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||||
|
|
||||||
|
def fromJSON(file):
|
||||||
|
with open(file, "r") as f:
|
||||||
|
j = json.load(f)
|
||||||
|
obj = Config()
|
||||||
|
[setattr(obj, key, val) for key, val in j.items() if hasattr(obj, key)]
|
||||||
|
return obj
|
||||||
|
|
||||||
def from_file(file):
|
def from_file(file):
|
||||||
values = {}
|
values = {}
|
||||||
if (not os.path.exists(file)):
|
if (not os.path.exists(file)):
|
||||||
return Config()
|
return Config()
|
||||||
|
|
||||||
with open(file, "rt") as f:
|
with open(file, "r") as f:
|
||||||
for line in f:
|
j = json.load(f)
|
||||||
if line.startswith("export"):
|
obj = Config()
|
||||||
content = line.split("=")
|
[setattr(obj, key, val) for key, val in j.items() if hasattr(obj, key)]
|
||||||
for idx, c in enumerate(content):
|
return obj
|
||||||
content[idx] = c.replace("export", "").strip()
|
|
||||||
values[content[0]] = content[1].replace("\"", "").replace("'", "")
|
|
||||||
config = Config()
|
|
||||||
config.branch_on_major = values["branch_on_major"].lower() == "true"
|
|
||||||
config.branch_on_minor = values["branch_on_minor"].lower() == "true"
|
|
||||||
config.release_on_major = values["release_on_major"].lower() == "true"
|
|
||||||
config.release_on_minor = values["release_on_minor"].lower() == "true"
|
|
||||||
config.main_branch = values["main_branch"]
|
|
||||||
config.patch_limit = int(values["patch_limit"])
|
|
||||||
|
|
||||||
return config;
|
|
||||||
|
|
||||||
def save_to_file(self, file):
|
def save_to_file(self, file):
|
||||||
dir_index = str(file).rfind("/")
|
dir_index = str(file).rfind("/")
|
||||||
|
@ -71,13 +75,8 @@ class Config:
|
||||||
if not os.path.exists(dir):
|
if not os.path.exists(dir):
|
||||||
print(f"Creating config directory {dir}")
|
print(f"Creating config directory {dir}")
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
with open(file, 'w') as f:
|
with open(file, "w") as f:
|
||||||
f.write("export branch_on_major=" + str(self.branch_on_major) + "\n")
|
json.dump(self, f, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||||
f.write("export branch_on_minor=" + str(self.branch_on_minor) + "\n")
|
|
||||||
f.write("export release_on_major=" + str(self.release_on_major) + "\n")
|
|
||||||
f.write("export release_on_minor=" + str(self.release_on_minor) + "\n")
|
|
||||||
f.write('export main_branch="' + self.main_branch + '"' + "\n")
|
|
||||||
f.write("export patch_limit=" + str(self.patch_limit) + "\n")
|
|
||||||
|
|
||||||
|
|
||||||
class EnvData:
|
class EnvData:
|
||||||
|
@ -145,7 +144,6 @@ def recombine(cmake_text, version_parts, begin, end):
|
||||||
constructed_text_end = cmake_text[end::]
|
constructed_text_end = cmake_text[end::]
|
||||||
return constructed_text_begin + constructed_version + constructed_text_end
|
return constructed_text_begin + constructed_version + constructed_text_end
|
||||||
|
|
||||||
|
|
||||||
def inc_major(cmake_text):
|
def inc_major(cmake_text):
|
||||||
version_parts, begin, end = split_version(cmake_text)
|
version_parts, begin, end = split_version(cmake_text)
|
||||||
version_parts[0] = str(int(version_parts[0]) + 1)
|
version_parts[0] = str(int(version_parts[0]) + 1)
|
||||||
|
@ -214,10 +212,17 @@ def main():
|
||||||
parser.add_argument("-M", "--major", action='store_true', default=False, required=False)
|
parser.add_argument("-M", "--major", action='store_true', default=False, required=False)
|
||||||
parser.add_argument('-e', "--env", help="environment file", required=False, default=None)
|
parser.add_argument('-e', "--env", help="environment file", required=False, default=None)
|
||||||
parser.add_argument('-c', "--config", help="config file", required=False, default=None)
|
parser.add_argument('-c', "--config", help="config file", required=False, default=None)
|
||||||
parser.add_argument("--create_default_config", action="store_true", default=False, required=False)
|
parser.add_argument("--create-default-config", action="store_true", default=False, required=False)
|
||||||
|
parser.add_argument("--no-release", action="store_true", default=False, required=False)
|
||||||
|
parser.add_argument("--no-branch", action="store_true", default=False, required=False)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.create_default_config:
|
||||||
|
config = Config()
|
||||||
|
config.save_to_file(args.config if args.config is not None else CONFIG_FILE_LOCATION)
|
||||||
|
return
|
||||||
|
|
||||||
if args.env is not None:
|
if args.env is not None:
|
||||||
env = EnvData.get_env_from_file(args.e)
|
env = EnvData.get_env_from_file(args.e)
|
||||||
else:
|
else:
|
||||||
|
@ -228,9 +233,6 @@ def main():
|
||||||
else:
|
else:
|
||||||
config = Config.from_file(CONFIG_FILE_LOCATION)
|
config = Config.from_file(CONFIG_FILE_LOCATION)
|
||||||
|
|
||||||
if args.create_default_config:
|
|
||||||
config.save_to_file(args.config if args.config is not None else CONFIG_FILE_LOCATION)
|
|
||||||
|
|
||||||
cmake_text = load_cmake()
|
cmake_text = load_cmake()
|
||||||
cmake_version = get_version(cmake_text)[0]
|
cmake_version = get_version(cmake_text)[0]
|
||||||
print(f"Current Version: {cmake_version}")
|
print(f"Current Version: {cmake_version}")
|
||||||
|
@ -262,25 +264,24 @@ def main():
|
||||||
print("Selected patch")
|
print("Selected patch")
|
||||||
write_cmake(inc_patch(config, cmake_text))
|
write_cmake(inc_patch(config, cmake_text))
|
||||||
|
|
||||||
|
|
||||||
subprocess.call(["git", "add", "*"])
|
subprocess.call(["git", "add", "*"])
|
||||||
subprocess.call(["git", "commit"])
|
subprocess.call(["git", "commit"])
|
||||||
|
|
||||||
cmake_text = load_cmake()
|
cmake_text = load_cmake()
|
||||||
version_parts = split_version(cmake_text)[0]
|
version_parts = split_version(cmake_text)[0]
|
||||||
if args.major:
|
if not args.no_branch and args.major:
|
||||||
if config.branch_on_major:
|
if config.branch_on_major:
|
||||||
make_branch(config, "v" + str(version_parts[0]))
|
make_branch(config, "v" + str(version_parts[0]))
|
||||||
if args.minor:
|
if not args.no_branch and args.minor:
|
||||||
if config.branch_on_minor:
|
if config.branch_on_minor:
|
||||||
make_branch(config, "v" + str(version_parts[0]) + "." + str(version_parts[1]))
|
make_branch(config, "v" + str(version_parts[0]) + "." + str(version_parts[1]))
|
||||||
|
|
||||||
subprocess.call(["sh", "-c", "git remote | xargs -L1 git push --all"])
|
subprocess.call(["sh", "-c", "git remote | xargs -L1 git push --all"])
|
||||||
|
|
||||||
if args.major:
|
if not args.no_release and args.major:
|
||||||
if config.release_on_major:
|
if config.release_on_major:
|
||||||
make_release(env, "v" + str(version_parts[0]))
|
make_release(env, "v" + str(version_parts[0]))
|
||||||
if args.minor:
|
if not args.no_release and args.minor:
|
||||||
if config.release_on_minor:
|
if config.release_on_minor:
|
||||||
make_release(env, "v" + str(version_parts[0]) + "." + str(version_parts[1]))
|
make_release(env, "v" + str(version_parts[0]) + "." + str(version_parts[1]))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue