|
@ -15,20 +15,15 @@ epmet_root_svc_name_reg = "^([^/]+)/.*$" |
|
|
epmet_module_svc_name_reg = "^epmet-module/([^/]+)/.*$" |
|
|
epmet_module_svc_name_reg = "^epmet-module/([^/]+)/.*$" |
|
|
commit_regex = "^([0-9a-z]{40}) .*$" |
|
|
commit_regex = "^([0-9a-z]{40}) .*$" |
|
|
|
|
|
|
|
|
max_commit_qty = 20 |
|
|
# 项目绝对路径 |
|
|
|
|
|
git_project_env = os.environ.get('JWHT_GIT_PROJECT_DIR') |
|
|
|
|
|
git_project_dir = git_project_env if git_project_env else "epmet-saas" |
|
|
|
|
|
|
|
|
def findIndexOfLastCommit(commits: list, last_commit_ver: str): |
|
|
# 上一次提交记录文件 |
|
|
idx: int = None |
|
|
last_deploy_commit_record = os.environ.get('JWHT_LAST_DEPLOY_COMMIT_RECORD') |
|
|
for c in commits: |
|
|
commit_record_file_path = last_deploy_commit_record if last_deploy_commit_record else "./lastcommit.txt" |
|
|
if c.startswith(last_commit_ver): |
|
|
|
|
|
return idx |
|
|
|
|
|
else: |
|
|
|
|
|
if not idx: |
|
|
|
|
|
idx = 0 |
|
|
|
|
|
idx += 1 |
|
|
|
|
|
|
|
|
|
|
|
return idx |
|
|
max_commit_qty = 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def findLatestCommits(commits: list, last_commit_ver: str, max_amount: int): |
|
|
def findLatestCommits(commits: list, last_commit_ver: str, max_amount: int): |
|
@ -63,7 +58,7 @@ def findModuleList(commits: str): |
|
|
service_set: set = set() |
|
|
service_set: set = set() |
|
|
for c in commits: |
|
|
for c in commits: |
|
|
try: |
|
|
try: |
|
|
rst = os.popen("cd epmet-saas && git show {} --stat --name-only|grep 'epmet-'".format(c)) |
|
|
rst = os.popen("cd {} && git show {} --stat --name-only|grep 'epmet-'".format(git_project_dir, c)) |
|
|
files = rst.readlines() |
|
|
files = rst.readlines() |
|
|
for file in files: |
|
|
for file in files: |
|
|
svc_name = find_service_name_from_file(file) |
|
|
svc_name = find_service_name_from_file(file) |
|
@ -97,7 +92,7 @@ def read_last_commit_ver(): |
|
|
读取上次发布到的版本号(包含) |
|
|
读取上次发布到的版本号(包含) |
|
|
:return: |
|
|
:return: |
|
|
""" |
|
|
""" |
|
|
with open('./lastcommit.txt', 'rt') as lastcommit_file: |
|
|
with open(commit_record_file_path, 'rt') as lastcommit_file: |
|
|
line_contents = lastcommit_file.readlines() |
|
|
line_contents = lastcommit_file.readlines() |
|
|
if len(line_contents) > 0: |
|
|
if len(line_contents) > 0: |
|
|
return line_contents[0] |
|
|
return line_contents[0] |
|
@ -108,7 +103,7 @@ def write_last_commit_ver(new_ver): |
|
|
写入上次发布到的版本号(包含) |
|
|
写入上次发布到的版本号(包含) |
|
|
:return: |
|
|
:return: |
|
|
""" |
|
|
""" |
|
|
with open('./lastcommit.txt', 'wt') as lastcommit_file: |
|
|
with open(commit_record_file_path, 'wt') as lastcommit_file: |
|
|
lastcommit_file.write(new_ver) |
|
|
lastcommit_file.write(new_ver) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -127,15 +122,15 @@ def deploy_svcs(svc_list): |
|
|
|
|
|
|
|
|
def do(): |
|
|
def do(): |
|
|
# 切换分支 |
|
|
# 切换分支 |
|
|
os.system("cd epmet-saas && git checkout dev") |
|
|
os.system("cd {} && git checkout dev".format(git_project_dir)) |
|
|
|
|
|
|
|
|
# 更新代码 |
|
|
# 更新代码 |
|
|
os.system("cd epmet-saas && git pull") |
|
|
os.system("cd {} && git pull".format(git_project_dir)) |
|
|
|
|
|
|
|
|
last_commit_ver = read_last_commit_ver() |
|
|
last_commit_ver = read_last_commit_ver() |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
stream = os.popen("cd epmet-saas && git log --pretty=oneline --no-merges -20") |
|
|
stream = os.popen("cd {} && git log --pretty=oneline --no-merges -20".format(git_project_dir)) |
|
|
commits = stream.readlines() |
|
|
commits = stream.readlines() |
|
|
|
|
|
|
|
|
# 根据commits找出最近提交的commits |
|
|
# 根据commits找出最近提交的commits |
|
@ -159,12 +154,16 @@ def do(): |
|
|
finally: |
|
|
finally: |
|
|
stream.close() |
|
|
stream.close() |
|
|
|
|
|
|
|
|
@app.route(rule='/on-dev-push', methods=['GET']) |
|
|
|
|
|
def on_dev_push(): |
|
|
if __name__ == '__main__': |
|
|
do() |
|
|
do() |
|
|
return "success" |
|
|
|
|
|
|
|
|
# @app.route(rule='/on-dev-push', methods=['GET']) |
|
|
|
|
|
# def on_dev_push(): |
|
|
|
|
|
# do() |
|
|
|
|
|
# return "success" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.run(host="0.0.0.0", port=7998, debug=True) # 多线程模式 |
|
|
# app.run(host="0.0.0.0", port=7998, debug=True) # 多线程模式 |
|
|
|
|
|
|
|
|
# python main.py runserver 0.0.0.0:7999 |
|
|
# python main.py runserver 0.0.0.0:7999 |