Infer section from job name rather than extension

This commit is contained in:
Hannes Mehnert 2021-08-02 16:11:58 +02:00 committed by Gitea
parent cdce07c808
commit cd633087d5

View file

@ -218,7 +218,7 @@ let commit_files datadir staging_dir job_name uuid =
Lwt.return (Bos.OS.Dir.create job_dir) >>= fun _ -> Lwt.return (Bos.OS.Dir.create job_dir) >>= fun _ ->
Lwt.return (Bos.OS.Path.move staging_dir dest) Lwt.return (Bos.OS.Path.move staging_dir dest)
let infer_section_and_synopsis artifacts = let infer_section_and_synopsis name artifacts =
let opam_switch = let opam_switch =
match List.find_opt (fun (p, _) -> String.equal (Fpath.basename p) "opam-switch") artifacts with match List.find_opt (fun (p, _) -> String.equal (Fpath.basename p) "opam-switch") artifacts with
| None -> None | None -> None
@ -239,24 +239,27 @@ let infer_section_and_synopsis artifacts =
if OpamPackage.Set.exists (fun p -> OpamPackage.Name.equal p.OpamPackage.name influx) if OpamPackage.Set.exists (fun p -> OpamPackage.Name.equal p.OpamPackage.name influx)
switch.OpamFile.SwitchExport.selections.OpamTypes.sel_installed switch.OpamFile.SwitchExport.selections.OpamTypes.sel_installed
then then
"Unikernel (with metrics reported to Influx)" "Unikernels (with metrics reported to Influx)"
else else
"Unikernel" "Unikernels"
in in
let infer_section_from_extension = let infer_section_from_name name =
match List.find_opt (fun (p, _) -> Fpath.(is_prefix (v "bin/") p)) artifacts with let map = [
| None -> None "-freebsd", "FreeBSD" ;
| Some (p, _) -> "-debian", "Debian" ;
match Fpath.get_ext p with "-ubuntu", "Ubuntu" ;
| ".deb" -> Some "Debian Package" ] in
| ".txz" -> Some "FreeBSD Package" match
| _ -> None List.find_opt (fun (affix, _) -> Astring.String.is_infix ~affix name) map
with
| None -> None
| Some (_, os) -> os ^ " Packages"
in in
match opam_switch with match opam_switch with
| None -> None, (None, None) | None -> None, (None, None)
| Some opam_switch -> | Some opam_switch ->
let section = let section =
match infer_section_from_extension with match infer_section_from_name name with
| Some x -> x | Some x -> x
| None -> infer_section_from_packages opam_switch | None -> infer_section_from_packages opam_switch
in in
@ -323,7 +326,7 @@ let add_build
console; script = job.Builder.script; console; script = job.Builder.script;
main_binary = None; input_id; user_id; job_id } >>= fun () -> main_binary = None; input_id; user_id; job_id } >>= fun () ->
Db.find last_insert_rowid () >>= fun id -> Db.find last_insert_rowid () >>= fun id ->
let sec_syn = infer_section_and_synopsis raw_artifacts in let sec_syn = infer_section_and_synopsis job_name raw_artifacts in
let add_or_update tag_id tag_value = let add_or_update tag_id tag_value =
Db.find_opt Job_tag.get_value (tag_id, job_id) >>= function Db.find_opt Job_tag.get_value (tag_id, job_id) >>= function
| None -> Db.exec Job_tag.add (tag_id, tag_value, job_id) | None -> Db.exec Job_tag.add (tag_id, tag_value, job_id)