代码拉取完成,页面将自动刷新
import typer
import os
import subprocess
from typing_extensions import Annotated
from rich.progress import Progress, BarColumn, TextColumn, TaskProgressColumn
from enum import Enum
from datetime import datetime
app = typer.Typer()
class DeployEnum(Enum):
IRT_1 = "irt-common-redis-starter"
IRT_2 = "irt-common-core"
IRT_3 = "irt-log-api"
IRT_4 = "irt-cfg-api"
IRT_5 = "irt-subject-api"
IRT_6 = "irt-supply-api"
IRT_7 = "irt-rand-api"
IRT_8 = "irt-report-api"
base = r"D:\Projects"
branch = "develop"
successlist = ""
failedlist = ""
@app.command()
def deploy(name: str):
global successlist, failedlist
print()
print(f"Deploying {name}...")
project_path = find_project_path(base, name)
if project_path is None:
typer.echo(f"Failed: '{name}'")
failedlist += f"{name}\n"
return
print(f"Project path: {project_path}")
os.chdir(project_path)
switch_to_branch(branch)
if run_maven_command("mvn clean deploy -Dmaven.test.skip=true"):
print(f"Success: {name}")
successlist += f"{name}\n"
else:
print(f"Compile failed: {name}")
failedlist += f"{name}\n"
@app.command()
def deployAll(path: Annotated[str, typer.Argument()], env: Annotated[str, typer.Argument()]):
global base, branch
base = path
branch = env
print(f"Base path: {base}")
print(f"Current branch: {branch}")
start_time = datetime.now()
# 1 irt-common-redis-starter, 2 irt-common-core, 3 irt-log-api, 4 irt-cfg-api,
# 5 irt-subject-api, 6 irt-supply-api, 7 irt-rand-api, 8 irt-report-api
#deployList = [DeployEnum.IRT_2, DeployEnum.IRT_3, DeployEnum.IRT_4, DeployEnum.IRT_5, DeployEnum.IRT_6, DeployEnum.IRT_7, DeployEnum.IRT_8]
deployList = [DeployEnum.IRT_2, DeployEnum.IRT_4, DeployEnum.IRT_6]
with Progress(
TextColumn("[progress.description] {task.description}"),
BarColumn(),
TaskProgressColumn()
) as progress:
task = progress.add_task("[cyan]Deploying progress", total = len(deployList))
for item in deployList:
progress.update(task, advance = 1)
deploy(item.value)
end_time = datetime.now()
print(f"Start time: {start_time}")
print(f"End time: {end_time}")
print(f"Processed {len(deployList)} packages")
print(f"Cost {(end_time - start_time).seconds} seconds")
if len(successlist) > 0:
print(f"Success List: \n{successlist}")
if len(failedlist) > 0:
print(f"Failed List: \n{failedlist}")
def find_project_path(base_path: str, project_folder: str) -> str:
for root, dirs, files in os.walk(base_path):
if project_folder in dirs:
return os.path.join(root, project_folder)
return None
def switch_to_branch(branch_name: str):
os.system(f"git checkout {branch_name}")
os.system("git pull")
def run_maven_command(command: str):
try:
subprocess.check_output(command, shell=True)
return True
except subprocess.CalledProcessError as e:
return False
if __name__ == "__main__":
app()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。