From 6a2b89019902e19b432da5efd5bb9f82f8cfd7c0 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 22 Nov 2024 19:17:25 +0530 Subject: [PATCH] WIP: Run opam-ci-check lints before submit --- src/dune | 10 +++++++++- src/publishMain.ml | 42 ++++++++++++++++++++++++++++++++++-------- src/publishSubmit.ml | 9 ++++++--- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/dune b/src/dune index 36c5277..da5fbaa 100644 --- a/src/dune +++ b/src/dune @@ -2,7 +2,15 @@ (public_name opam-publish) (package opam-publish) (name publishMain) - (libraries lwt opam-core opam-format opam-state cohttp github.unix cmdliner)) + (libraries + lwt + opam-core + opam-format + opam-state + cohttp + github.unix + cmdliner + opam-ci-check-lint)) (rule (targets version.ml) diff --git a/src/publishMain.ml b/src/publishMain.ml index ced3dff..7c5f7e6 100644 --- a/src/publishMain.ml +++ b/src/publishMain.ml @@ -12,6 +12,8 @@ open OpamStd.Op open OpamStd.Option.Op open PublishCommon +module Lint = Opam_ci_check_lint.Lint + type meta = { archive: OpamFilename.t option; opam: OpamFile.OPAM.t OpamFile.t option; @@ -673,6 +675,15 @@ let to_files ?(split=false) ~packages_dir meta_opams = [] |> List.rev +let opam_ci_lint ~opam_repo_dir meta_opams = + let opam_repo_dir = (OpamFilename.Dir.to_string opam_repo_dir) in + let lint_metas = OpamPackage.Map.fold (fun pkg (m, o) acc -> + let pkg_src_dir = Option.map OpamFilename.Dir.to_string m.dir in + let newly_published = None in + (Lint.v ~pkg ~pkg_src_dir ~newly_published o) :: acc + ) meta_opams [] in + Lint.lint_packages ~opam_repo_dir lint_metas + let main_term root = let run args force tag version dry_run output_patch no_browser repo @@ -707,14 +718,29 @@ let main_term root = let pr_title = title +! pr_title in let files = to_files ~split ~packages_dir meta_opams in let output_patch = OpamStd.Option.map OpamFilename.of_string output_patch in - PublishSubmit.submit - root - ~dry_run - ~output_patch - ~no_browser - repo target_branch pr_title pr_body - (OpamPackage.Map.keys meta_opams) - files + let opam_repo_dir, user, token = PublishSubmit.prepare_opam_repository ~target_branch ~repo root in + let lint_errors = + match repo with + | ("ocaml", "opam-repository") -> + opam_ci_lint ~opam_repo_dir meta_opams |> (function + | Ok [] -> Ok () + | Ok e -> Error (e |> List.map Lint.msg_of_error |> String.concat "\n") + | Error _ as e -> e) + | _ -> Ok () + in + match lint_errors with + | Error e -> OpamConsole.error "%s" e + | _ -> + PublishSubmit.submit + root + ~dry_run + ~output_patch + ~no_browser + ~user + ~token + repo target_branch pr_title pr_body + (OpamPackage.Map.keys meta_opams) + files in let open Args in Term.(const run diff --git a/src/publishSubmit.ml b/src/publishSubmit.ml index a4731ae..0be8f34 100644 --- a/src/publishSubmit.ml +++ b/src/publishSubmit.ml @@ -301,9 +301,7 @@ let add_files_and_pr with OpamSystem.Command_not_found _ -> () end -let submit - root ~dry_run ~output_patch ~no_browser - repo target_branch title msg packages files = +let prepare_opam_repository ~target_branch ~repo root = (* Prepare the repo *) let mirror_dir = repo_dir root repo in let user, token = @@ -317,6 +315,11 @@ let submit in (* pull-request processing *) update_mirror root repo ~user ~token target_branch; + mirror_dir, user, token + +let submit + root ~dry_run ~output_patch ~no_browser ~user ~token + repo target_branch title msg packages files = let branch = user_branch packages in add_files_and_pr root ~dry_run ~output_patch ~no_browser repo user token title msg branch target_branch files