Skip to content

Commit

Permalink
Check that opam repository directory is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
punchagan committed Nov 29, 2024
1 parent f5f69ac commit 32c4f2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
7 changes: 4 additions & 3 deletions opam-ci-check/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ let lint (changed_pkgs, new_pkgs) local_repo_dir =
in
let errors = Lint.lint_packages ~opam_repo_dir all_lint_packages in
match errors with
| [] ->
| Ok [] ->
print_endline "No errors";
Ok ()
| errors ->
| Ok errors ->
errors |> List.map Lint.msg_of_error |> String.concat "\n"
|> Printf.sprintf "%s\n" |> Result.error)
|> Printf.sprintf "%s\n" |> Result.error
| Error _ as e -> e)

let show_revdeps pkg local_repo_dir no_transitive_revdeps =
(* Get revdeps for the package *)
Expand Down
14 changes: 8 additions & 6 deletions opam-ci-check/lib/lint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,11 @@ let get_package_names repo_dir =
get_files (repo_dir // "packages") |> List.sort String.compare

let lint_packages ~opam_repo_dir metas =
let repo_package_names = get_package_names opam_repo_dir in
metas
|> List.map (fun { pkg; newly_published; pkg_src_dir; opam } ->
Checks.lint_package ~opam_repo_dir ~pkg ~pkg_src_dir
~repo_package_names ~newly_published opam)
|> List.concat
if Sys.file_exists (opam_repo_dir // "packages") then
let repo_package_names = get_package_names opam_repo_dir in
metas
|> List.map (fun { pkg; newly_published; pkg_src_dir; opam } ->
Checks.lint_package ~opam_repo_dir ~pkg ~pkg_src_dir
~repo_package_names ~newly_published opam)
|> List.concat |> Result.ok
else Error (Printf.sprintf "Invalid opam repository: %s" opam_repo_dir)
10 changes: 6 additions & 4 deletions opam-ci-check/lib/lint.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ val v :
*)

val lint_packages :
opam_repo_dir:string -> t list -> (OpamPackage.t * error) list
opam_repo_dir:string ->
t list ->
((OpamPackage.t * error) list, string) result
(** [lint_packages ~opam_repo_dir metas] is a list of all the
errors detected while linting the packages in the [metas] list in the
context of the opam repository located at [opam_repo_dir].
Expand All @@ -42,9 +44,9 @@ val lint_packages :
{[
let passes_all_checks = assert (lint_packages ~opam_repo_dir metas |> List.length = 0)
let failed_some_checks = assert (lint_packages ~opam_repo_dir metas |> List.length > 0)
let passes_all_checks = assert (lint_packages ~opam_repo_dir metas |> Result.get_ok |> List.length = 0)
let failed_some_checks = assert (lint_packages ~opam_repo_dir metas |> Result.get_ok |> List.length > 0)
let messages_for_all_failed_checks =
lint_packages ~opam_repo_dir ~repo_packages metas
|> List.map msg_of_error
|> Result.get_ok |> List.map msg_of_error
]} *)

0 comments on commit 32c4f2e

Please sign in to comment.