package main // Exhibit 6. Root records every deploy in the app's own facts: deploy.json has the live and staging // commit, when it arrived and who pushed it. The footer of this page reads it. import "core:fmt" import "core:strings" import "ratcloud:rc" e06 :: proc() -> Exhibit { return { n = 6, wing = "Deploy", title = "A push is a deploy", promise = "Pushing to main puts the code live within a minute.", block = "git push is the deploy. What is running, and since when, is in the fact deploy.json (rc.fact), written by root, readable by the app.", src = {"e06_push_is_deploy.odin", #load("e06_push_is_deploy.odin", string)}, show = proc(me: ^rc.User) -> string { d := fact("deploy.json") b := strings.builder_make() strings.write_string(&b, `") return strings.to_string(b) }, // The commit running here must be the newest one pushed to this environment's branch. check = proc() -> Check { e := env().env running := jget(fact("deploy.json"), e) pushes := jarr(fact("pushes.json")) if running == nil || pushes == nil do return fail("the facts have no deploy.json or pushes.json") for p in pushes { if jstr(p, "env") != e || !strings.has_prefix(jstr(p, "result"), "deployed") do continue if jstr(p, "commit") != jstr(running, "commit") do return fail(fmt.tprintf("running %s but the last push to %s was %s", short(jstr(running, "commit"), 10), e, short(jstr(p, "commit"), 10))) lag := parse_time(jstr(running, "at")) - parse_time(jstr(p, "at")) if lag > 60 do return fail(fmt.tprintf("the last push took %ds to go live", lag)) return pass(fmt.tprintf("running %s, the last push to %s, live %ds after the push", short(jstr(running, "commit"), 10), e, lag)) } return fail(fmt.tprintf("no successful push to %s is recorded", e)) }, } }