Skip to content

Commit

Permalink
opam-ci-check: Command to list-revdeps in docker image
Browse files Browse the repository at this point in the history
The `opam-ci-check list` command can be run locally to list revdeps for
a package. It creates an isolated opam root for some isolation, but for
a greater extent of isolation, this commit adds a list-revdeps command
that can be used to list-revdeps locally using a Docker image.

This makes it easier to reproduce the CI runs more closely, when trying
to reproduce locally. And adds extra flexibility to be able to test on
different OSes etc.
  • Loading branch information
punchagan authored and shonfeder committed Jan 26, 2025
1 parent 5016ba2 commit a81c407
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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

0 comments on commit a81c407

Please sign in to comment.