1 import Base 2 import ../release/type.bend as Rl 3 import ../release/ops.bend as RlO 4 import ../release/plugin/ops.bend as PlO 5 import ./type.bend as P 6 7 def visibility(p: Bool) -> String: 8 match p: 9 case True{}: 10 "public" 11 case False{}: 12 "private" 13 14 # ---- the repository: Bend only and no dead code come first, then GitHub ---- 15 def repo_steps(+fs: List<&2, String>, +reached: List<&2, String>) -> List<&2, P.Step>: 16 List.append(&2, P.Step, 17 Bool.pick(List<&2, P.Step>, String.is_empty(RlO.not_bend(fs)), [], 18 [P.Blocked{"repository", RlO.not_bend(fs) ++ " is not Bend"}]), 19 List.append(&2, P.Step, 20 Bool.pick(List<&2, P.Step>, String.is_empty(RlO.dead(fs, reached)), [], 21 [P.Blocked{"repository", RlO.dead(fs, reached) ++ " is dead code: no entry reaches it"}]), 22 Bool.pick(List<&2, P.Step>, String.is_empty(RlO.hub_refused(reached)), [], 23 [P.Blocked{"repository", RlO.hub_refused(reached) ++ ": the Bend hub refuses this path (segments of letters, digits and _)"}]))) 24 25 def remote_step(+repo: Rl.Repository, rm: P.Remote) -> P.Step: 26 match repo rm: 27 case Rl.Repository{+name, +public} P.Remote{+origin, +vis, clean, pushed}: 28 Bool.pick(P.Step, String.contains(origin, name), 29 Bool.pick(P.Step, String.eq(vis, visibility(public)), 30 Bool.pick(P.Step, clean, 31 Bool.pick(P.Step, pushed, P.Current{"github " ++ name}, P.Push{name}), 32 P.Blocked{"github " ++ name, "uncommitted changes"}), 33 P.Blocked{"github " ++ name, "GitHub says " ++ Bool.pick(String, String.is_empty(vis), "nothing (unreachable)", vis) ++ ", declared " ++ visibility(public)}), 34 P.Blocked{"github " ++ name, "origin is " ++ origin}) 35 36 # ---- each package: already published as it is, new, or changed without a new version ---- 37 def package_step(p: Rl.Package, h: P.Hub) -> P.Step: 38 match p: 39 case Rl.Package{+n, +v, e, _}: 40 match h: 41 case P.Same{}: 42 P.Current{"package " ++ n ++ "@" ++ v} 43 case P.Unpublished{}: 44 P.Publish{n, v, e} 45 case P.Differs{f}: 46 P.Blocked{"package " ++ n ++ "@" ++ v, f ++ " changed since it was published; give it a new version"} 47 48 def package_steps(ps: List<&2, Rl.Package>, hs: List<&2, P.Hub>) -> List<&2, P.Step>: 49 match ps: 50 case []: 51 [] 52 case p <> prest: 53 match hs: 54 case []: 55 [] 56 case h <> hrest: 57 package_step(p, h) <> package_steps(prest, hrest) 58 59 # ---- each plugin: released as it builds, new, or changed without a new version ---- 60 def plugin_step(g: Rl.Plugin, t: P.Tag) -> P.Step: 61 match g t: 62 case Rl.Plugin{+n, ver, _, _, Rl.Repository{+r, _}} P.Tag{repo, tagged, +built, valid, differs}: 63 +v = PlO.version_show(ver) 64 +what = "plugin " ++ n ++ "@" ++ v 65 Bool.pick(P.Step, Bool.not(PlO.name_ok(n)), P.Blocked{what, "the name breaks Agent Plugins 1.0's rule: 1 to 64 of a-z, 0-9, . and -, a letter or digit at each end, no -- or .."}, 66 Bool.pick(P.Step, String.is_empty(built), P.Blocked{what, "does not build"}, 67 Bool.pick(P.Step, Bool.not(String.eq(built, v)), P.Blocked{what, "builds as version " ++ built}, 68 Bool.pick(P.Step, Bool.not(valid), P.Blocked{what, "claude plugin validate rejects the build"}, 69 Bool.pick(P.Step, Bool.not(repo), P.ReleasePlugin{n, v, r, True{}}, 70 Bool.pick(P.Step, Bool.not(tagged), P.ReleasePlugin{n, v, r, False{}}, 71 Bool.pick(P.Step, differs, P.Blocked{what, "changed since " ++ n ++ "-v" ++ v ++ " was released; give it a new version"}, 72 P.Current{what}))))))) 73 74 def plugin_steps(gs: List<&2, Rl.Plugin>, ts: List<&2, P.Tag>) -> List<&2, P.Step>: 75 match gs: 76 case []: 77 [] 78 case g <> grest: 79 match ts: 80 case []: 81 [] 82 case t <> trest: 83 plugin_step(g, t) <> plugin_steps(grest, trest) 84 85 # The plan: what a deploy would do, from the release and what was observed. 86 def plan(r: Rl.Release, o: P.Observed) -> List<&2, P.Step>: 87 match r o: 88 case Rl.Release{repo, ps, gs} P.Observed{+fs, +reached, hs, rm, ts}: 89 List.append(&2, P.Step, repo_steps(fs, reached), List.append(&2, P.Step, package_steps(ps, hs), 90 List.append(&2, P.Step, plugin_steps(gs, ts), [remote_step(repo, rm)]))) 91 92 def blocked(s: P.Step) -> Bool: 93 match s: 94 case P.Blocked{_, _}: 95 True{} 96 case _: 97 False{} 98 99 def any_blocked(ss: List<&2, P.Step>) -> Bool: 100 match ss: 101 case []: 102 False{} 103 case s <> rest: 104 blocked(s) || any_blocked(rest) 105 106 def show(s: P.Step) -> String: 107 match s: 108 case P.Current{w}: 109 "current " ++ w 110 case P.Publish{n, v, _}: 111 "publish " ++ n ++ "@" ++ v 112 case P.Push{r}: 113 "push github " ++ r 114 case P.ReleasePlugin{+n, +v, r, create}: 115 "release plugin " ++ n ++ "@" ++ v ++ " to marketplace github " ++ r ++ " as tag " ++ n ++ "-v" ++ v ++ Bool.pick(String, create, " (a new repository)", "") 116 case P.Launch{l, _, _, _}: 117 "launch " ++ l 118 case P.Install{_, t}: 119 "install " ++ t 120 case P.Rebuild{h, _, _}: 121 "rebuild nix-darwin " ++ h 122 case P.ServePort{p, t, _}: 123 "serve :" ++ U32.show(p) ++ " -> " ++ t 124 case P.Change{w, now, want}: 125 "change " ++ w ++ ": " ++ now ++ " -> " ++ want 126 case P.Blocked{w, why}: 127 "blocked " ++ w ++ ": " ++ why 128 129 def show_all(ss: List<&2, P.Step>) -> String: 130 match ss: 131 case []: 132 "" 133 case s <> rest: 134 show(s) ++ "\n" ++ show_all(rest)