Skip to content

Commit

Permalink
Fix spec for integration test and add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
benmandrew committed Mar 25, 2024
1 parent 13819f2 commit 9e4b14b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/cluster_build.ml
Expand Up @@ -107,9 +107,9 @@ module Op = struct
let base = Spec.base_to_string base in
match ty with
| `Opam (`List_revdeps { opam_version }, pkg) ->
Opam_build.revdeps ~for_docker ~opam_version ~base ~variant ~pkg
Opam_build.revdeps ~for_docker ~opam_version ~base ~variant pkg
| `Opam (`Build { revdep; lower_bounds; with_tests; opam_version }, pkg) ->
Opam_build.spec ~for_docker ~opam_version ~base ~variant ~revdep ~lower_bounds ~with_tests ~pkg
Opam_build.spec ~for_docker ~opam_version ~base ~variant ~revdep ~lower_bounds ~with_tests pkg
in
Current.Job.write job
(Fmt.str "@.\
Expand Down
11 changes: 6 additions & 5 deletions lib/local_build.ml
Expand Up @@ -77,6 +77,7 @@ module Op = struct
master : Current_git.Commit.t;
urgent : ([`High | `Low] -> bool) option;
base : Spec.base;
test_config : Integration_test.t option;
}

let id = "ci-build"
Expand Down Expand Up @@ -138,7 +139,7 @@ module Op = struct
end
| _ -> Lwt_result.return ""

let build { config; master = _; urgent = _; base } job
let build { config; master = _; urgent = _; base; test_config } job
{ Key.commit; ty; variant } =
let { docker_context; pool; build_timeout } = config in
let os = match Variant.os variant with
Expand All @@ -148,9 +149,9 @@ module Op = struct
let base = Spec.base_to_string base in
match ty with
| `Opam (`List_revdeps { opam_version }, pkg) ->
Opam_build.revdeps ~for_docker:true ~opam_version ~base ~variant ~pkg
Opam_build.revdeps ~test_config ~for_docker:true ~opam_version ~base ~variant pkg
| `Opam (`Build { revdep; lower_bounds; with_tests; opam_version }, pkg) ->
Opam_build.spec ~for_docker:true ~opam_version ~base ~variant ~revdep ~lower_bounds ~with_tests ~pkg
Opam_build.spec ~for_docker:true ~opam_version ~base ~variant ~revdep ~lower_bounds ~with_tests pkg
in
let base =
match base with
Expand Down Expand Up @@ -209,7 +210,7 @@ let v ?test_config ~label ~spec ~base ~master ~urgent commit =
and> commit = Git.fetch commit
and> master
and> urgent in
let t = { Op.config = local_builder; master; urgent; base } in
let t = { Op.config = local_builder; master; urgent; base; test_config } in
match test_config with
| None ->
BC.get t { commit; ty; variant }
Expand All @@ -236,7 +237,7 @@ let list_revdeps ?test_config ~variant ~opam_version ~pkgopt ~base ~master ~afte
and> commit = Git.fetch commit
and> master
and> () = after in
let t = { Op.config = local_builder; master; urgent; base } in
let t = { Op.config = local_builder; master; urgent; base; test_config } in
let ty = `Opam (`List_revdeps {Spec.opam_version}, pkg) in
let f () =
BC.get t { commit; ty; variant }
Expand Down
18 changes: 15 additions & 3 deletions lib/opam_build.ml
Expand Up @@ -117,7 +117,7 @@ let setup_repository ~variant ~for_docker ~opam_version =
(* TODO: MacOS seems to have a bug in (copy ...) so I am forced to remove the (workdir ...) here.
Otherwise the "opam pin" after the "opam repository set-url" will fail (cannot find the new package for some reason) *)
run "%s -f %s/bin/opam-%s %s/bin/opam" ln prefix opam_version_str prefix ::
run ~network "opam init --reinit%s -ni" opamrc :: (* TODO: Remove ~network when https://github.com/ocurrent/ocaml-dockerfile/pull/132 is merged *)
run "opam init --reinit%s -ni" opamrc ::
run "uname -rs && opam exec -- ocaml -version && opam --version" ::
env "OPAMDOWNLOADJOBS" "1" :: (* Try to avoid github spam detection *)
env "OPAMERRLOGLEN" "0" :: (* Show the whole log if it fails *)
Expand All @@ -137,7 +137,7 @@ let set_personality ~variant =
else
[]

let spec ~for_docker ~opam_version ~base ~variant ~revdep ~lower_bounds ~with_tests ~pkg =
let spec ~for_docker ~opam_version ~base ~variant ~revdep ~lower_bounds ~with_tests pkg =
let opam_install = opam_install ~variant ~opam_version in
let revdep = match revdep with
| None -> []
Expand All @@ -159,11 +159,23 @@ let spec ~for_docker ~opam_version ~base ~variant ~revdep ~lower_bounds ~with_te
@ tests
)

let revdeps ~for_docker ~opam_version ~base ~variant ~pkg =
(* If we are integration-testing the revdeps, we replace the
existing opam-repository with a dummy one. However, this
removes the required base compiler packages. This command
pins them to keep them around.
Related: https://github.com/ocaml/opam/issues/5895 *)
let keep_installed = function
| Some Integration_test.List_revdeps -> [
Obuilder_spec.run "for pkg in $(opam list -s --installed) ; do opam pin --current \"$pkg\" ; done"
]
| _ -> []

let revdeps ?(test_config=None) ~for_docker ~opam_version ~base ~variant pkg =
let open Obuilder_spec in
let pkg = Filename.quote (OpamPackage.to_string pkg) in
Obuilder_spec.stage ~from:base (
setup_repository ~variant ~for_docker ~opam_version
@ keep_installed test_config
@ [
run "echo '@@@OUTPUT' && \
opam list -s --color=never --depends-on %s --coinstallable-with %s --installable --all-versions --depopts && \
Expand Down
5 changes: 3 additions & 2 deletions lib/opam_build.mli
Expand Up @@ -6,13 +6,14 @@ val spec :
revdep:OpamPackage.t option ->
lower_bounds:bool ->
with_tests:bool ->
pkg:OpamPackage.t ->
OpamPackage.t ->
Obuilder_spec.t

val revdeps :
?test_config:Integration_test.t option ->
for_docker:bool ->
opam_version:[`V2_0 | `V2_1 | `Dev] ->
base:string ->
variant:Variant.t ->
pkg:OpamPackage.t ->
OpamPackage.t ->
Obuilder_spec.t
26 changes: 26 additions & 0 deletions test/patches/a-1-insignificant-change.patch
@@ -0,0 +1,26 @@
diff --git a/packages/a-1/a-1.0.0.1/opam b/packages/a-1/a-1.0.0.1/opam
index 5246a83..c17a1ba 100644
--- a/packages/a-1/a-1.0.0.1/opam
+++ b/packages/a-1/a-1.0.0.1/opam
@@ -1,7 +1,7 @@
opam-version: "2.0"
synopsis: "Synopsis"
description: "Description"
-maintainer: "Maintainer"
+maintainer: "Another maintainer"
author: "Author"
license: "Apache-2.0"
homepage: "https://github.com/ocurrent/opam-repo-ci"
diff --git a/packages/a-1/a-1.0.0.2/opam b/packages/a-1/a-1.0.0.2/opam
index 5246a83..c018682 100644
--- a/packages/a-1/a-1.0.0.2/opam
+++ b/packages/a-1/a-1.0.0.2/opam
@@ -1,7 +1,7 @@
opam-version: "2.0"
synopsis: "Synopsis"
description: "Description"
-maintainer: "Maintainer"
+maintainer: "Someone else"
author: "Author"
license: "Apache-2.0"
homepage: "https://github.com/ocurrent/opam-repo-ci"
3 changes: 2 additions & 1 deletion test/revdeps-correct.t → test/revdeps.t
Expand Up @@ -7,4 +7,5 @@
$ git add .
$ git commit -qm a-1-update
$ opam-repo-ci-local --repo="." --branch=new-branch --revdeps-only
Ok ()
b.0.0.1
b.0.0.2

0 comments on commit 9e4b14b

Please sign in to comment.