1 Star 0 Fork 0

Jin/auto

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
auto.py 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
Jin 提交于 2024-05-10 10:51 . feat: 易用性优化 (#)
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/surick/auto.git
git@gitee.com:surick/auto.git
surick
auto
auto
main

搜索帮助

D67c1975 1850385 1daf7b77 1850385