From 045dbcf23dde48e5eacaa275e6f61bccee1ef4f9 Mon Sep 17 00:00:00 2001 From: Robur Date: Wed, 3 Nov 2021 14:40:04 +0000 Subject: [PATCH] adapt to builder 0.2.0 changes --- lib/builder_web.ml | 5 ++-- lib/model.ml | 58 ++++++++++++++++++++++++++++------------------ test/dune | 2 +- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/lib/builder_web.ml b/lib/builder_web.ml index 514ef93..13ab83f 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -301,6 +301,7 @@ let add_routes datadir = let upload_binary req = let job = Dream.param "job" req in + let platform = Dream.param "platform" req in let binary_name = Dream.query "binary_name" req |> Option.map Fpath.of_string @@ -326,7 +327,7 @@ let add_routes datadir = let datadir = Dream.global datadir_global req in let exec = let now = Ptime_clock.now () in - ({ Builder.name = job ; script = "" }, uuid, [], now, now, Builder.Exited 0, + ({ Builder.name = job ; platform ; script = "" }, uuid, [], now, now, Builder.Exited 0, [ (Fpath.(v "bin" // binary_name), body) ]) in (Lwt.return (Dream.local Authorization.user_info_local req |> @@ -351,5 +352,5 @@ let add_routes datadir = Dream.get "/hash" (w hash); Dream.get "/compare/:build_left/:build_right/opam-switch" (w compare_opam); Dream.post "/upload" (Authorization.authenticate (w upload)); - Dream.post "/job/:job/upload" (Authorization.authenticate (w upload_binary)); + Dream.post "/job/:job/platform/:platform/upload" (Authorization.authenticate (w upload_binary)); ] diff --git a/lib/model.ml b/lib/model.ml index b16dcb6..d32321d 100644 --- a/lib/model.ml +++ b/lib/model.ml @@ -228,7 +228,7 @@ let commit_files datadir staging_dir job_name uuid = Lwt.return (Bos.OS.Dir.create job_dir) >>= fun _ -> Lwt.return (Bos.OS.Path.move staging_dir dest) -let infer_section_and_synopsis name artifacts = +let infer_section_and_synopsis platform name artifacts = let opam_switch = match List.find_opt (fun (p, _) -> String.equal (Fpath.basename p) "opam-switch") artifacts with | None -> None @@ -245,35 +245,47 @@ let infer_section_and_synopsis name artifacts = | Some opam -> OpamFile.OPAM.synopsis opam, OpamFile.OPAM.descr_body opam in let infer_section_from_packages switch = - let influx = OpamPackage.Name.of_string "metrics-influx" in - if OpamPackage.Set.exists (fun p -> OpamPackage.Name.equal p.OpamPackage.name influx) - switch.OpamFile.SwitchExport.selections.OpamTypes.sel_installed - then - "Unikernels (with metrics reported to Influx)" + let root = switch.OpamFile.SwitchExport.selections.OpamTypes.sel_roots in + if OpamPackage.Set.cardinal root <> 1 then + None else - "Unikernels" + let root = OpamPackage.Set.choose root in + let root_pkg_name = OpamPackage.Name.to_string root.OpamPackage.name in + if Astring.String.is_prefix ~affix:"mirage-unikernel-" root_pkg_name then + let influx = OpamPackage.Name.of_string "metrics-influx" in + if OpamPackage.Set.exists (fun p -> OpamPackage.Name.equal p.OpamPackage.name influx) + switch.OpamFile.SwitchExport.selections.OpamTypes.sel_installed + then + Some "Unikernels (with metrics reported to Influx)" + else + Some "Unikernels" + else + None in - let infer_section_from_name name = - let map = [ - "-freebsd", "FreeBSD" ; - "-debian", "Debian" ; - "-ubuntu", "Ubuntu" ; - ] in - match - List.find_opt (fun (affix, _) -> Astring.String.is_infix ~affix name) map - with - | None -> None - | Some (_, os) -> Some (os ^ " Packages") + let infer_section_from_platform_or_name = + if String.equal platform "no-platform" then + let map = [ + "-freebsd", "FreeBSD" ; + "-debian", "Debian" ; + "-ubuntu", "Ubuntu" ; + ] in + match + List.find_opt (fun (affix, _) -> Astring.String.is_infix ~affix name) map + with + | None -> None + | Some (_, os) -> Some (os ^ " Packages") + else + Some (platform ^ " Packages") in match opam_switch with | None -> None, (None, None) | Some opam_switch -> let section = - match infer_section_from_name name with - | Some x -> x - | None -> infer_section_from_packages opam_switch + match infer_section_from_packages opam_switch with + | None -> infer_section_from_platform_or_name + | Some x -> Some x in - Some section, infer_synopsis_and_descr opam_switch + section, infer_synopsis_and_descr opam_switch let compute_input_id artifacts = let get_hash filename = @@ -358,7 +370,7 @@ let add_build console; script; main_binary = None; input_id; user_id; job_id } >>= fun () -> Db.find last_insert_rowid () >>= fun id -> - let sec_syn = infer_section_and_synopsis job_name raw_artifacts in + let sec_syn = infer_section_and_synopsis job.Builder.platform job_name raw_artifacts in let add_or_update tag_id tag_value = Db.find_opt Job_tag.get_value (tag_id, job_id) >>= function | None -> Db.exec Job_tag.add (tag_id, tag_value, job_id) diff --git a/test/dune b/test/dune index d728f6c..68a0b92 100644 --- a/test/dune +++ b/test/dune @@ -1,3 +1,3 @@ (test (name builder_db) - (libraries builder_db caqti.blocking alcotest mirage-crypto-rng.unix)) + (libraries builder_db caqti.blocking alcotest mirage-crypto-rng.unix rresult))