File: ci.ml

package info (click to toggle)
ocaml-spawn 0.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 212 kB
  • sloc: ansic: 569; ml: 374; makefile: 22
file content (37 lines) | stat: -rw-r--r-- 903 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
open StdLabels

let run cmd args =
  (* broken when arguments contain spaces but it's good enough for now. *)
  let cmd = String.concat ~sep:" " (cmd :: args) in
  match Sys.command cmd with
  | 0 -> ()
  | n ->
    Printf.eprintf "'%s' failed with code %d" cmd n;
    exit n

let opam args = run "opam" args

let build () =
  opam [ "install"; "."; "--deps-only"; "--with-test" ]

let test () =
  run "dune" [ "runtest" ]

let fmt () =
  let version_of_ocamlformat =
    let ic = open_in ".ocamlformat" in
    let v = Scanf.sscanf (input_line ic) "version=%s" (fun x -> x) in
    close_in ic;
    v
  in
  opam [ "install"; "ocamlformat." ^ version_of_ocamlformat ];
  run "dune" [ "build"; "@fmt" ]

let () =
  match Sys.argv with
  | [| _; "build" |] -> build ()
  | [| _; "test" |] -> test ()
  | [| _; "fmt" |] -> fmt ()
  | _ ->
    prerr_endline "Usage: ci.ml [ build | test | fmt ]";
    exit 1