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

opam-ci-check: Command to list-revdeps in docker image #410

Merged
merged 1 commit into from
Jan 26, 2025
Merged
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
42 changes: 41 additions & 1 deletion opam-ci-check/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ let build_run_spec ~variant ~hash ~no_cache ~only_print ~with_tests
~base config
|> Result.map_error (fun _ -> "Failed to build and test the package")

let list_revdep_spec ~variant ~hash ~no_cache ~only_print ~pkg ~opam_repository
=
let pkg = OpamPackage.of_string pkg in
let base =
let hash =
Stdlib.Option.(hash |> map (fun h -> "@" ^ h) |> value ~default:"")
in
let image =
Printf.sprintf "ocaml/opam:%s%s" (Variant.docker_tag variant) hash
in
Spec.Docker image
in
let config = Spec.opam_list_revdeps ~variant ~opam_version:`Dev pkg in
Test.build_run_spec ~use_cache:(not no_cache) ~only_print ?opam_repository
~base config
|> Result.map_error (fun _ -> "Failed to list revdeps for the package")

let make_abs_path s =
if Filename.is_relative s then Filename.concat (Sys.getcwd ()) s else s

Expand Down Expand Up @@ -498,11 +515,34 @@ let build_cmd =
in
Cmd.v info term

let list_revdeps_cmd =
let doc =
"List reverse dependencies for a package using the [opam-ci-check] [list] \
command inside a Docker image."
in
let term =
to_exit_code
@@
let+ variant = variant
and+ hash = hash
and+ no_cache = no_cache
and+ only_print = only_print
and+ pkg = pkg_term
and+ opam_repository = local_opam_repo_term in
list_revdep_spec ~variant ~hash ~no_cache ~only_print ~pkg ~opam_repository
in
let info =
Cmd.info "list-revdeps" ~doc ~sdocs:"COMMON OPTIONS"
~exits:Cmd.Exit.defaults
in
Cmd.v info term

let cmd : Cmd.Exit.code Cmd.t =
let doc = "A tool to list revdeps and test the revdeps locally" in
let exits = Cmd.Exit.defaults in
let default = Term.(ret (const (fun _ -> `Help (`Pager, None)) $ const ())) in
let info = Cmd.info "opam-ci-check" ~doc ~sdocs:"COMMON OPTIONS" ~exits in
Cmd.group ~default info [ lint_cmd; list_cmd; test_cmd; build_cmd ]
Cmd.group ~default info
[ lint_cmd; list_cmd; test_cmd; build_cmd; list_revdeps_cmd ]

let () = exit (Cmd.eval' cmd)
4 changes: 4 additions & 0 deletions opam-ci-check/lib/spec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ let opam ?revdep ~variant ~lower_bounds ~with_tests ~opam_version pkg =
let ty = `Opam (`Build { revdep; lower_bounds; with_tests; opam_version }, pkg) in
{ variant; ty }

let opam_list_revdeps ~variant ~opam_version pkg =
let ty = `Opam (`List_revdeps { opam_version }, pkg) in
{ variant; ty }

let pp_pkg ?revdep f pkg =
match revdep with
| Some revdep -> Fmt.pf f "%s with %s" (OpamPackage.to_string revdep) (OpamPackage.to_string pkg)
Expand Down
5 changes: 5 additions & 0 deletions opam-ci-check/lib/spec.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ val opam :
lower_bounds:bool ->
with_tests:bool -> opam_version:Opam_version.t -> package -> t

(** Generate configuration for a [list_revdeps] job *)
val opam_list_revdeps :
variant:Variant.t ->
opam_version:Opam_version.t -> package -> t

val pp_ty :
Format.formatter ->
[< `Opam of
Expand Down