From 589112902da44356ee9ba97dee6a9951cb9d8200 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 24 Sep 2024 16:49:15 +0530 Subject: [PATCH] Parse opam-ci-check errors from the job log --- lib/lint.ml | 37 +++++++++++++++++++++++++++++++++++++ test/lint.t | 26 ++++++++++++++++++++------ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/lib/lint.ml b/lib/lint.ml index 858eb3ee..d9fee97d 100644 --- a/lib/lint.ml +++ b/lib/lint.ml @@ -13,6 +13,32 @@ module Check = struct let marshal () = Yojson.Safe.to_string `Null let unmarshal _ = () + let parse_errors_from_log job = + let job_id = Current.Job.id job in + let path = Current.Job.log_path job_id in + match path with + | Ok path -> + Lwt_io.with_file ~mode:Lwt_io.input (Fpath.to_string path) (fun ch -> + let rec aux acc = + (* We choose the relevant output lines by filtering lines starting + with Error/Warning. The other log lines in the file would start + with a timestamp (logged info), or not start with the + Error/Warning prefix (other text output from the CLI tool). *) + Lwt_io.read_line_opt ch >>= function + | Some line -> + if (String.starts_with ~prefix:"Error" line || + String.starts_with ~prefix:"Warning" line) + then + aux (line :: acc) + else + aux acc + | None -> Lwt.return acc + in + aux [] >>= function + | [] -> Lwt.return (Error (`Msg "Could not find any Error/Warning lines in CLI output.")) + | errors -> Lwt.return (Ok (String.concat "\n" errors))) + | Error (`Msg m) -> Lwt.return (Error (`Msg (Fmt.str "Could not find the log file for job <%s>: %s" job_id m))) + let of_dir ~master ~job ~packages cwd = let master = Current_git.Commit.hash master in exec ~cwd ~job [|"git"; "merge"; "-q"; "--"; master|] >>/= fun () -> @@ -38,6 +64,17 @@ module Check = struct in let cmd = ["opam-ci-check"; "lint"; "--opam-repository"; "."] @ changed @ new_ in exec ~cwd ~job (cmd |> Array.of_list) + >>= function + | Error (`Msg err) -> + (* The exec function doesn't capture stdout when the command fails; so we + parse the command output from the log file, instead. *) + parse_errors_from_log job >>= (function + | Ok errors -> Lwt_result.fail (`Msg errors) + | Error (`Msg msg) -> + let error_msg = (Fmt.str "internal error: %s - %s" err msg) in + Lwt_result.fail (`Msg error_msg)) + | Ok () -> + Lwt_result.return () end module Lint = struct diff --git a/test/lint.t b/test/lint.t index 92f1fe9d..b54e25f4 100644 --- a/test/lint.t +++ b/test/lint.t @@ -29,8 +29,16 @@ Tests the following: * b-incorrect-opam (HEAD -> new-branch-1) * a-1 (tag: initial-state, master) $ opam-repo-ci-local --repo="." --branch=new-branch-1 --lint-only --no-web-server - Error "Command "opam-ci-check" "lint" "--opam-repository" "." "--newly-published" - "b.0.0.1,b.0.0.2,b.0.0.3,system-b.0.0.1" exited with status 1" + Error "Warning in system-b.0.0.1: package name has restricted prefix 'system-' + Error in system-b.0.0.1: package with prefix 'system-' requires conflict class 'ocaml-system' + Error in system-b.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer + Error in b.0.0.3: package with conflict class 'ocaml-host-arch' requires name prefix 'host-arch-' + Error in b.0.0.3: pin-depends present. This is not allowed in the opam-repository. + Error in b.0.0.3: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer + Error in b.0.0.2: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer + Error in b.0.0.2: error 3: File format error in 'unknown-field' at line 11, column 0: Invalid field unknown-field + Error in b.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer + Error in b.0.0.1: warning 25: Missing field 'authors'" Reset commit and clear build cache @@ -47,8 +55,8 @@ of a package [a_1] that conflicts with the existing [a-1] package * a_1-name-collision (HEAD -> new-branch-1) * a-1 (tag: initial-state, master) $ opam-repo-ci-local --repo="." --branch=new-branch-1 --lint-only --no-web-server - Error "Command "opam-ci-check" "lint" "--opam-repository" "." "--newly-published" - "a_1.0.0.1" exited with status 1" + Error "Warning in a_1.0.0.1: Possible name collision with package 'a-1' + Error in a_1.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer" Delete OCurrent cache @@ -72,5 +80,11 @@ test various positive and negative cases * levenshtein-1 (master) * a-1 (tag: initial-state) $ opam-repo-ci-local --repo="." --branch=new-branch-2 --lint-only --no-web-server - Error "Command "opam-ci-check" "lint" "--opam-repository" "." "--changed-packages" - "field1.0.0.2" "--newly-published" "fieffind.0.0.1,fieffinder.0.0.1,fielf.0.0.1" exited with status 1" + Error "Error in field1.0.0.2: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer + Warning in fielf.0.0.1: Possible name collision with package 'field1' + Error in fielf.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer + Warning in fieffinder.0.0.1: Possible name collision with package 'fieffind' + Error in fieffinder.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer + Warning in fieffind.0.0.1: Possible name collision with package 'fieldfind' + Warning in fieffind.0.0.1: Possible name collision with package 'fieffinder' + Error in fieffind.0.0.1: Maintainer email missing. Please add a maintainer email to the opam file. Maintainer: Maintainer"