跑一条流水线看结果
(贯穿本条的小模型:流水线固定按 build → test → lint 三步跑,run_pipeline(结果) 遇第一个失败就停、交回 (跑了几步, 'PASS' 或失败的步名);all_green 三步全过才 True;first_fail 交回第一个失败的步名。)
流水线 build 过、test 挂、lint 过,跑一遍打印结果:
STAGES = ["build", "test", "lint"]
def run_pipeline(results):
"""按 STAGES 固定顺序跑,遇第一个失败就停(fail-fast)。交回 (跑了几个阶段, 'PASS' 或第一个失败阶段名)。"""
ran = 0
for s in STAGES:
ran += 1
if not results.get(s, True):
return ran, s
return ran, "PASS"
def all_green(results):
"""三个阶段全过才 True。"""
return all(results.get(s, True) for s in STAGES)
def first_fail(results):
"""第一个失败的阶段名;全过交回空串。"""
for s in STAGES:
if not results.get(s, True):
return s
return ""
ran, res = run_pipeline({"build": True, "test": False, "lint": True})
print(str(ran) + "/" + res)
全部评论