Compare commits
No commits in common. "bc82e7485d8b5762cc49ec91d1b4d4f6b711b7ad" and "068faa48d586031d8f7a62c61679cdc81e3ca701" have entirely different histories.
bc82e7485d
...
068faa48d5
51
commit.py
51
commit.py
|
@ -24,8 +24,8 @@ 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.json")
|
CONFIG_FILE_LOCATION = Path(CONFIG_FILE_DIRECTORY + "\commit_config.env")
|
||||||
else:
|
else:
|
||||||
XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME')
|
XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME')
|
||||||
if XDG_CONFIG_HOME is None:
|
if XDG_CONFIG_HOME is None:
|
||||||
|
@ -36,7 +36,7 @@ else:
|
||||||
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.json"
|
CONFIG_FILE_LOCATION = CONFIG_FILE_DIRECTORY / "commit_config.env"
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -44,7 +44,7 @@ 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 = True
|
self.release_on_minor = False
|
||||||
self.main_branch = "main"
|
self.main_branch = "main"
|
||||||
self.patch_limit = -1
|
self.patch_limit = -1
|
||||||
|
|
||||||
|
@ -56,8 +56,6 @@ class Config:
|
||||||
j = json.load(f)
|
j = json.load(f)
|
||||||
obj = Config()
|
obj = Config()
|
||||||
[setattr(obj, key, val) for key, val in j.items() if hasattr(obj, key)]
|
[setattr(obj, key, val) for key, val in j.items() if hasattr(obj, key)]
|
||||||
if obj.branch_on_minor:
|
|
||||||
obj.branch_on_major = True
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def from_file(file):
|
def from_file(file):
|
||||||
|
@ -172,12 +170,6 @@ def make_branch(config: Config, name):
|
||||||
subprocess.call(["git", "merge", config.main_branch])
|
subprocess.call(["git", "merge", config.main_branch])
|
||||||
subprocess.call(["git", "checkout", config.main_branch])
|
subprocess.call(["git", "checkout", config.main_branch])
|
||||||
|
|
||||||
def sync_branch(config: Config, version_parts, args):
|
|
||||||
if config.branch_on_major:
|
|
||||||
# Branch will be created.
|
|
||||||
if args.minor:
|
|
||||||
return;
|
|
||||||
|
|
||||||
def make_release(env: EnvData, name):
|
def make_release(env: EnvData, name):
|
||||||
print(f"Making new release {name}")
|
print(f"Making new release {name}")
|
||||||
repos_v = open_process(["git", "remote", "-v"])[0].splitlines()
|
repos_v = open_process(["git", "remote", "-v"])[0].splitlines()
|
||||||
|
@ -220,17 +212,10 @@ 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:
|
||||||
|
@ -241,6 +226,9 @@ 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}")
|
||||||
|
@ -279,37 +267,18 @@ def main():
|
||||||
version_parts = split_version(cmake_text)[0]
|
version_parts = split_version(cmake_text)[0]
|
||||||
if args.major:
|
if args.major:
|
||||||
if config.branch_on_major:
|
if config.branch_on_major:
|
||||||
if not args.no_branch:
|
|
||||||
make_branch(config, "v" + str(version_parts[0]))
|
make_branch(config, "v" + str(version_parts[0]))
|
||||||
|
|
||||||
if args.minor:
|
if args.minor:
|
||||||
if config.branch_on_minor:
|
if config.branch_on_minor:
|
||||||
if not args.no_branch:
|
|
||||||
make_branch(config, "v" + str(version_parts[0]) + "." + str(version_parts[1]))
|
make_branch(config, "v" + str(version_parts[0]) + "." + str(version_parts[1]))
|
||||||
elif config.branch_on_major:
|
|
||||||
subprocess.call(["git", "checkout", "v" + str(version_parts[0])])
|
|
||||||
subprocess.call(["git", "rebase", config.main_branch])
|
|
||||||
subprocess.call(["git", "checkout", config.main_branch])
|
|
||||||
|
|
||||||
if args.patch:
|
|
||||||
if config.branch_on_minor:
|
|
||||||
subprocess.call(["git", "checkout", "v" + str(version_parts[0]) + "." + str(version_parts[1])])
|
|
||||||
subprocess.call(["git", "rebase", config.main_branch])
|
|
||||||
subprocess.call(["git", "checkout", config.main_branch])
|
|
||||||
elif config.branch_on_major:
|
|
||||||
subprocess.call(["git", "checkout", "v" + str(version_parts[0])])
|
|
||||||
subprocess.call(["git", "rebase", config.main_branch])
|
|
||||||
subprocess.call(["git", "checkout", config.main_branch])
|
|
||||||
|
|
||||||
sync_branch(config=config, version_parts=version_parts, args=args)
|
|
||||||
|
|
||||||
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 args.major:
|
||||||
if not args.no_release and 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 args.minor:
|
||||||
if not args.no_release and 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]))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue