Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Run opam-ci-check lints before submit #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 34 additions & 8 deletions src/publishMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/publishSubmit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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