Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Dec 14, 2023
1 parent 2592c14 commit 5dec1d4
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 486 deletions.
105 changes: 90 additions & 15 deletions .github/workflows/ci.ml
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,19 @@ let install_sys_packages packages ~descr ?cond platforms =

let install_sys_opam ?cond = install_sys_packages ["opam"] ~descr:"Install system's opam package" ?cond
let install_sys_dune ?cond = install_sys_packages ["dune"; "ocaml"] ~descr:"Install system's dune and ocaml packages" ?cond

(*
oc:out_channel ->
workflow:'a ->
platforms:'b Lib.platform list ->
keys:(string * string) list ->
(Lib.job -> oc:out_channel -> workflow:'a -> 'c) -> 'c
*)
let analyse_job ~oc ~workflow ~platforms ~keys f =
let oses = List.map os_of_platform platforms in
let outputs =
let f (key, _) = (key, Printf.sprintf "${{ steps.keys.outputs.%s }}" key) in
List.map f keys
@ ["binary_label", "${{ steps.label.outputs.binary_label }}"]
in
let keys =
let set_key (name, value) =
Expand All @@ -289,10 +296,21 @@ let analyse_job ~oc ~workflow ~platforms ~keys f =
else
None
in
let upload_binary =
run "Determine uploading binary label"
~shell:"bash" ~env:["GH_TOKEN","${{ secrets.GITHUB_TOKEN }}"]
~id:"label"
[
{|binary_label=$(gh api --jq '.labels.[].name' /repos/${{ github.repository }}/pulls/${{ github.event.number }} | grep "PR:BINARIES" || echo "other")|};
{|echo "$binary_label"|};
{|echo "binary_label=$binary_label" >> $GITHUB_OUTPUT|}
]
in
job ~oc ~workflow ~runs_on:(Runner platforms) ~outputs ~section:"Caches" "Analyse"
++ only_with Windows (git_lf_checkouts ~cond:(Predicate(true, Runner Windows)) ~shell:"cmd" ~title:"Configure Git for Windows" ())
++ checkout ()
++ run "Determine cache keys" ~id:"keys" keys
++ upload_binary
++ cache ?cond:linux_guard ~key_prefix:"steps.keys" ~check_only:true Archives
++ build_cache ?cond:not_windows_guard Archives
++ end_job f
Expand Down Expand Up @@ -328,6 +346,49 @@ let main_build_job ~analyse_job ~cygwin_job ?section runner start_version ~oc ~w
let matrix = ((platform <> Windows), matrix, includes) in
let needs = if platform = Windows then [analyse_job; cygwin_job] else [analyse_job] in
let host = host_of_platform platform in
let upload_binaries =
let cond =
let label =
Predicate (true, Compare ("needs.Analyse.outputs.binary_label", "PR:BINARIES"))
in
match runner with
| MacOS -> label
| Windows ->
And (label,
Predicate (true, EndsWith ("matrix.host", "-pc-cygwin")))
| Linux ->
And (label,
Predicate (true, Compare ("matrix.ocamlv", "4.14.1")))
in
let withs =
let name =
match runner with
| Linux | MacOS ->
Literal ["opam-exe-${{ runner.os }}-${{ matrix.ocamlv }}"]
| Windows ->
Literal
["opam-exe-${{ matrix.host }}-${{ matrix.ocamlv }}-${{ matrix.build }}"]
in
let paths =
let prefix =
match runner with
| MacOS -> "/Users/runner/local/bin/"
| Linux -> "/home/runner/local/bin/"
| Windows -> "D:\\Local\\bin\\"
in
let binaries = ["opam-installer"; "opam"] in
match runner with
| MacOS | Linux ->
Literal ((List.rev_map (fun s -> prefix ^ s)) binaries)
| Windows ->
Literal ((List.rev_map (fun s -> prefix ^ s ^ ".exe"))
("opam-putenv":: binaries))
in
[ "name", name; "path", paths; ]
in
uses "Upload opam binaries" "actions/upload-artifact@v3"
~cond ~withs ~continue_on_error:true
in
job ~oc ~workflow ~runs_on:(Runner [runner]) ?shell ?section ~needs ~matrix ("Build-" ^ name_of_platform platform)
++ only_on Linux (run "Install bubblewrap" ["sudo apt install bubblewrap"])
++ only_on Windows (git_lf_checkouts ~cond:(Predicate(true, EndsWith("matrix.host", "-pc-cygwin"))) ~shell:"cmd" ~title:"Configure LF checkout for Cygwin" ())
Expand All @@ -338,6 +399,7 @@ let main_build_job ~analyse_job ~cygwin_job ?section runner start_version ~oc ~w
++ only_on Windows (unpack_cygwin "${{ matrix.build }}" "${{ matrix.host }}")
++ build_cache OCaml platform "${{ matrix.ocamlv }}" host
++ run "Build" ["bash -exu .github/scripts/main/main.sh " ^ host]
++ upload_binaries
++ not_on Windows (run "Test (basic)" ["bash -exu .github/scripts/main/test.sh"])
++ only_on Windows (run "Test (basic - Cygwin)" ~cond:(Predicate(true, EndsWith("matrix.host", "-pc-cygwin"))) ["bash -exu .github/scripts/main/test.sh"])
++ only_on Windows (run "Test (basic - native Windows)" ~env:[("OPAMROOT", {|D:\a\opam\opam\.opam|})] ~shell:"cmd" ~cond:(Predicate(false, EndsWith("matrix.host", "-pc-cygwin")))
Expand Down Expand Up @@ -463,6 +525,17 @@ let hygiene_job (type a) ~analyse_job (platform : a platform) ~oc ~workflow f =
++ run "Hygiene" ~cond:(Or(Predicate(true, Contains("steps.files.outputs.modified", "configure.ac")), Predicate(true, Contains("steps.files.outputs.all", "src_ext")))) ~env:[("BASE_REF_SHA", "${{ github.event.pull_request.base.sha }}"); ("PR_REF_SHA", "${{ github.event.pull_request.head.sha }}")] ["bash -exu .github/scripts/main/hygiene.sh"]
++ end_job f

let empty_job ~oc ~workflow f
~analyse_job:_
(* ~cygwin_job:_ *)
(* ~build_Windows_job:_ *)
(* ~build_Linux_job:_ *)
(* ~build_macOS_job:_ *)
=
job ~oc ~workflow ~runs_on:(Runner [Linux]) "NO-OP"
++ run "no-op" ["echo something"]
++ end_job f

let main oc : unit =
let env = [
("OPAMBSVERSION", "2.1.0");
Expand All @@ -486,20 +559,22 @@ let main oc : unit =
("opam-bs-cache", "${{ hashFiles('.github/scripts/main/opam-bs-cache.sh', '*.opam', '.github/scripts/main/preamble.sh') }}");
] in
workflow ~oc ~env "Builds, tests & co"
++ analyse_job ~keys ~platforms:[Linux] (fun analyse_job ->
cygwin_job ~analyse_job (fun cygwin_job ->
main_build_job ~analyse_job ~cygwin_job ~section:"Build" Linux (4, 08) (fun build_linux_job ->
main_build_job ~analyse_job ~cygwin_job Windows latest_ocaml (fun build_windows_job ->
main_build_job ~analyse_job ~cygwin_job MacOS latest_ocaml (fun build_macOS_job ->
main_test_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Opam tests" Linux (fun _ ->
main_test_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job MacOS (fun _ ->
cold_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Opam cold" Linux (fun _ ->
solvers_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Compile solver backends" Linux (fun _ ->
solvers_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job MacOS (fun _ ->
upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Upgrade from 1.2 to current" Linux (fun _ ->
upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job MacOS (fun _ ->
hygiene_job ~analyse_job (Specific (Linux, "22.04")) (fun _ ->
end_workflow)))))))))))))
++ analyse_job ~keys ~platforms:[Linux] @@ fun analyse_job ->
empty_job ~analyse_job @@ fun cygwin_job ->
main_build_job ~analyse_job ~cygwin_job ~section:"Build" Linux (4, 08) @@ fun build_linux_job ->
(*
main_build_job ~analyse_job ~cygwin_job Windows latest_ocaml @@ fun build_windows_job ->
main_build_job ~analyse_job ~cygwin_job MacOS latest_ocaml @@ fun build_macOS_job ->
main_test_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Opam tests" Linux @@ fun _ ->
main_test_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job MacOS @@ fun _ ->
cold_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Opam cold" Linux @@ fun _ ->
solvers_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Compile solver backends" Linux @@ fun _ ->
solvers_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job MacOS @@ fun _ ->
upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job ~section:"Upgrade from 1.2 to current" Linux @@ fun _ ->
upgrade_job ~analyse_job ~build_linux_job ~build_windows_job ~build_macOS_job MacOS @@ fun _ ->
hygiene_job ~analyse_job (Specific (Linux, "22.04")) @@ fun _ ->
*)
end_workflow

let () =
let oc = open_out "main.yml" in
Expand Down
Loading

0 comments on commit 5dec1d4

Please sign in to comment.