Aggregate all builds (even failed builds)
This commit is contained in:
parent
082f2582dd
commit
46df7f92a7
3 changed files with 24 additions and 28 deletions
|
@ -352,30 +352,26 @@ module Build = struct
|
|||
|}
|
||||
|
||||
let get_builds_older_than =
|
||||
Caqti_type.(tup3 (id `job) (option string) Rep.ptime) ->* Caqti_type.(tup2 t file) @@
|
||||
{| SELECT b.uuid, b.start_d, b.start_ps, b.finish_d, b.finish_ps,
|
||||
b.result_code, b.result_msg, b.console, b.script,
|
||||
b.platform, b.main_binary, b.input_id, b.user, b.job,
|
||||
a.filepath, a.localpath, a.sha256, a.size
|
||||
FROM build_artifact a
|
||||
INNER JOIN build b ON b.id = a.build
|
||||
WHERE b.main_binary = a.id AND b.job = $1
|
||||
Caqti_type.(tup3 (id `job) (option string) Rep.ptime) ->* t @@
|
||||
{| SELECT uuid, start_d, start_ps, finish_d, finish_ps,
|
||||
result_code, result_msg, console, script,
|
||||
platform, main_binary, input_id, user, job
|
||||
FROM build
|
||||
WHERE job = $1
|
||||
AND ($2 IS NULL OR platform = $2)
|
||||
AND (b.finish_d < $3 OR (b.finish_d = $3 AND b.finish_ps <= $4))
|
||||
ORDER BY b.start_d DESC, b.start_ps DESC
|
||||
AND (finish_d < $3 OR (finish_d = $3 AND finish_ps <= $4))
|
||||
ORDER BY start_d DESC, start_ps DESC
|
||||
|}
|
||||
|
||||
let get_builds_excluding_latest_n =
|
||||
Caqti_type.(tup3 (id `job) (option string) int) ->* Caqti_type.tup2 t file @@
|
||||
{| SELECT b.uuid, b.start_d, b.start_ps, b.finish_d, b.finish_ps,
|
||||
b.result_code, b.result_msg, b.console, b.script,
|
||||
b.platform, b.main_binary, b.input_id, b.user, b.job,
|
||||
a.filepath, a.localpath, a.sha256, a.size
|
||||
FROM build_artifact a
|
||||
INNER JOIN build b ON b.id = a.build
|
||||
WHERE b.main_binary = a.id AND b.job = $1
|
||||
Caqti_type.(tup3 (id `job) (option string) int) ->* t @@
|
||||
{| SELECT uuid, start_d, start_ps, finish_d, finish_ps,
|
||||
result_code, result_msg, console, script,
|
||||
platform, main_binary, input_id, user, job
|
||||
FROM build
|
||||
WHERE job = $1
|
||||
AND ($2 IS NULL OR platform = $2)
|
||||
ORDER BY b.start_d DESC, b.start_ps DESC
|
||||
ORDER BY start_d DESC, start_ps DESC
|
||||
LIMIT -1 OFFSET $3
|
||||
|}
|
||||
(* "LIMIT -1 OFFSET n" is all rows except the first n *)
|
||||
|
|
|
@ -130,9 +130,9 @@ sig
|
|||
([`job] id * string option, t, [ `One | `Zero ])
|
||||
Caqti_request.t
|
||||
val get_builds_older_than :
|
||||
([`job] id * string option * Ptime.t, t * file, [ `Many | `One | `Zero ]) Caqti_request.t
|
||||
([`job] id * string option * Ptime.t, t, [ `Many | `One | `Zero ]) Caqti_request.t
|
||||
val get_builds_excluding_latest_n :
|
||||
([`job] id * string option * int, t * file, [ `Many | `One | `Zero ]) Caqti_request.t
|
||||
([`job] id * string option * int, t, [ `Many | `One | `Zero ]) Caqti_request.t
|
||||
val get_previous_successful_different_output :
|
||||
([`build] id, t, [ `One | `Zero ])
|
||||
Caqti_request.t
|
||||
|
|
|
@ -281,10 +281,10 @@ let test_get_builds_older_than (module Db : CONN) =
|
|||
let date = Option.get (Ptime.of_float_s (3600. /. 2.)) in
|
||||
Db.find_opt Builder_db.Job.get_id_by_name job_name >>= fail_if_none >>= fun job_id ->
|
||||
Db.collect_list Builder_db.Build.get_builds_older_than (job_id, None, date) >>= fun builds ->
|
||||
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
|
||||
let builds = List.map (fun { Builder_db.Build.uuid; _ } -> uuid) builds in
|
||||
Alcotest.(check (list Testable.uuid)) "last build" builds [ uuid ];
|
||||
Db.collect_list Builder_db.Build.get_builds_older_than (job_id, None, Ptime_clock.now ()) >>= fun builds ->
|
||||
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
|
||||
let builds = List.map (fun { Builder_db.Build.uuid; _ } -> uuid) builds in
|
||||
(* NOTE(dinosaure): from the most recent to the older. *)
|
||||
Alcotest.(check (list Testable.uuid)) "last builds" builds [ uuid'; uuid ];
|
||||
Ok ()
|
||||
|
@ -293,19 +293,19 @@ let test_builds_excluding_latest_n (module Db : CONN) =
|
|||
add_second_build (module Db) >>= fun () ->
|
||||
Db.find_opt Builder_db.Job.get_id_by_name job_name >>= fail_if_none >>= fun job_id ->
|
||||
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, 1) >>= fun builds ->
|
||||
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
|
||||
let builds = List.map (fun { Builder_db.Build.uuid; _ } -> uuid) builds in
|
||||
Alcotest.(check (list Testable.uuid)) "keep recent build" builds [ uuid ];
|
||||
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, 2) >>= fun builds ->
|
||||
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
|
||||
let builds = List.map (fun { Builder_db.Build.uuid; _ } -> uuid) builds in
|
||||
Alcotest.(check (list Testable.uuid)) "keep 2 builds" builds [];
|
||||
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, 3) >>= fun builds ->
|
||||
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
|
||||
let builds = List.map (fun { Builder_db.Build.uuid; _ } -> uuid) builds in
|
||||
Alcotest.(check (list Testable.uuid)) "last more builds than we have" builds [];
|
||||
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, 0) >>= fun builds ->
|
||||
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
|
||||
let builds = List.map (fun { Builder_db.Build.uuid; _ } -> uuid) builds in
|
||||
Alcotest.(check (list Testable.uuid)) "delete all builds" builds [ uuid'; uuid ];
|
||||
Db.collect_list Builder_db.Build.get_builds_excluding_latest_n (job_id, None, -1) >>= fun builds ->
|
||||
let builds = List.map (fun ({ Builder_db.Build.uuid; _ }, _) -> uuid) builds in
|
||||
let builds = List.map (fun { Builder_db.Build.uuid; _ } -> uuid) builds in
|
||||
Alcotest.(check (list Testable.uuid)) "test an incomprehensible argument (-1)" builds [ uuid'; uuid ];
|
||||
Ok ()
|
||||
|
||||
|
|
Loading…
Reference in a new issue