脚本跑到哪停了

👁️ 3 人浏览 💬 0 人评论 ❤️ 添加收藏

(本地 CI 脚本:ci_run(步骤) 按顺序跑、遇失败停,交回 (跑过几步, 退出码)(全过 0 否则 1);summary 交回一行小结:过的标步名、第一个失败标「×步名」、之后没跑的标「-步名」。)

三步 build 过、test 挂、lint 过,问跑过几步、退出码几:

def ci_run(steps):
    """本地 CI 脚本:steps 是 [(步名, 通过?)],按顺序跑、遇失败就停。交回 (跑过几步, 退出码)——全过 0,否则 1。"""
    passed = 0
    for name, ok in steps:
        if not ok:
            return passed, 1
        passed += 1
    return passed, 0


def summary(steps):
    """跑完的一行小结:过的标步名、第一个失败标 '×步名'、它之后没跑到的标 '-步名',用逗号连起来。"""
    out = []
    stopped = False
    for name, ok in steps:
        if stopped:
            out.append("-" + name)
        elif ok:
            out.append(name)
        else:
            out.append("×" + name)
            stopped = True
    return ",".join(out)

p, code = ci_run([("build", True), ("test", False), ("lint", True)])
print(str(p) + "/" + str(code))
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论