Handle jobs without successful build in migrations
The migrations migrate-2021-06-29 and migrate-2021-06-30 would not apply if a job exists without any successful build. Now the migrations script silently skips jobs without succesful builds.
This commit is contained in:
parent
bd0ab7f554
commit
37e68f91f4
2 changed files with 37 additions and 32 deletions
|
@ -34,7 +34,7 @@ let jobs =
|
||||||
"SELECT id FROM job"
|
"SELECT id FROM job"
|
||||||
|
|
||||||
let latest_successful_build =
|
let latest_successful_build =
|
||||||
Caqti_request.find
|
Caqti_request.find_opt
|
||||||
Builder_db.Rep.id
|
Builder_db.Rep.id
|
||||||
Builder_db.Rep.id
|
Builder_db.Rep.id
|
||||||
{| SELECT b.id
|
{| SELECT b.id
|
||||||
|
@ -138,18 +138,21 @@ let migrate datadir (module Db : Caqti_blocking.CONNECTION) =
|
||||||
Db.find find_tag "description" >>= fun descr_id ->
|
Db.find find_tag "description" >>= fun descr_id ->
|
||||||
Db.collect_list jobs () >>= fun jobs ->
|
Db.collect_list jobs () >>= fun jobs ->
|
||||||
Grej.list_iter_result (fun job ->
|
Grej.list_iter_result (fun job ->
|
||||||
Db.find latest_successful_build job >>= fun build ->
|
Db.find_opt latest_successful_build job >>= function
|
||||||
Db.collect_list build_artifacts build >>= fun artifacts ->
|
| None ->
|
||||||
List.fold_left (fun acc (fpath, lpath) ->
|
Ok ()
|
||||||
acc >>= fun acc ->
|
| Some build ->
|
||||||
Bos.OS.File.read Fpath.(append datadir lpath) >>= fun data ->
|
Db.collect_list build_artifacts build >>= fun artifacts ->
|
||||||
Ok ((fpath, data) :: acc))
|
List.fold_left (fun acc (fpath, lpath) ->
|
||||||
(Ok [])
|
acc >>= fun acc ->
|
||||||
artifacts >>= fun files ->
|
Bos.OS.File.read Fpath.(append datadir lpath) >>= fun data ->
|
||||||
let sec_syn = infer_section_and_synopsis files in
|
Ok ((fpath, data) :: acc))
|
||||||
(match fst sec_syn with None -> Ok () | Some s -> Db.exec insert_job_tag (section_id, s, job)) >>= fun () ->
|
(Ok [])
|
||||||
(match snd sec_syn with None, _ -> Ok () | Some s, _ -> Db.exec insert_job_tag (synopsis_id, s, job)) >>= fun () ->
|
artifacts >>= fun files ->
|
||||||
(match snd sec_syn with _, None -> Ok () | _, Some s -> Db.exec insert_job_tag (descr_id, s, job)))
|
let sec_syn = infer_section_and_synopsis files in
|
||||||
|
(match fst sec_syn with None -> Ok () | Some s -> Db.exec insert_job_tag (section_id, s, job)) >>= fun () ->
|
||||||
|
(match snd sec_syn with None, _ -> Ok () | Some s, _ -> Db.exec insert_job_tag (synopsis_id, s, job)) >>= fun () ->
|
||||||
|
(match snd sec_syn with _, None -> Ok () | _, Some s -> Db.exec insert_job_tag (descr_id, s, job)))
|
||||||
jobs >>= fun () ->
|
jobs >>= fun () ->
|
||||||
Db.exec (Grej.set_version new_version) ()
|
Db.exec (Grej.set_version new_version) ()
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ let jobs =
|
||||||
"SELECT id FROM job"
|
"SELECT id FROM job"
|
||||||
|
|
||||||
let latest_successful_build =
|
let latest_successful_build =
|
||||||
Caqti_request.find
|
Caqti_request.find_opt
|
||||||
Builder_db.Rep.id
|
Builder_db.Rep.id
|
||||||
Builder_db.Rep.id
|
Builder_db.Rep.id
|
||||||
{| SELECT b.id
|
{| SELECT b.id
|
||||||
|
@ -63,24 +63,26 @@ let migrate datadir (module Db : Caqti_blocking.CONNECTION) =
|
||||||
Db.find find_tag "readme.md" >>= fun readme_id ->
|
Db.find find_tag "readme.md" >>= fun readme_id ->
|
||||||
Db.collect_list jobs () >>= fun jobs ->
|
Db.collect_list jobs () >>= fun jobs ->
|
||||||
Grej.list_iter_result (fun job ->
|
Grej.list_iter_result (fun job ->
|
||||||
Db.find latest_successful_build job >>= fun build ->
|
Db.find_opt latest_successful_build job >>= function
|
||||||
Db.collect_list build_artifacts build >>= fun artifacts ->
|
| None -> Ok ()
|
||||||
List.fold_left (fun acc (fpath, lpath) ->
|
| Some build ->
|
||||||
acc >>= fun acc ->
|
Db.collect_list build_artifacts build >>= fun artifacts ->
|
||||||
Bos.OS.File.read Fpath.(append datadir lpath) >>= fun data ->
|
List.fold_left (fun acc (fpath, lpath) ->
|
||||||
Ok ((fpath, data) :: acc))
|
acc >>= fun acc ->
|
||||||
(Ok [])
|
Bos.OS.File.read Fpath.(append datadir lpath) >>= fun data ->
|
||||||
artifacts >>= fun files ->
|
Ok ((fpath, data) :: acc))
|
||||||
let readme =
|
(Ok [])
|
||||||
List.find_opt (fun (p, _) -> Fpath.(equal (v "README.md") p)) files
|
artifacts >>= fun files ->
|
||||||
in
|
let readme =
|
||||||
let readme_anywhere =
|
List.find_opt (fun (p, _) -> Fpath.(equal (v "README.md") p)) files
|
||||||
List.find_opt (fun (p, _) -> String.equal "README.md" (Fpath.basename p)) files
|
in
|
||||||
in
|
let readme_anywhere =
|
||||||
(match readme, readme_anywhere with
|
List.find_opt (fun (p, _) -> String.equal "README.md" (Fpath.basename p)) files
|
||||||
| None, None -> Ok ()
|
in
|
||||||
| Some (_, data), _ | None, Some (_, data) ->
|
(match readme, readme_anywhere with
|
||||||
Db.exec insert_job_tag (readme_id, data, job)))
|
| None, None -> Ok ()
|
||||||
|
| Some (_, data), _ | None, Some (_, data) ->
|
||||||
|
Db.exec insert_job_tag (readme_id, data, job)))
|
||||||
jobs >>= fun () ->
|
jobs >>= fun () ->
|
||||||
Db.exec (Grej.set_version new_version) ()
|
Db.exec (Grej.set_version new_version) ()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue