From dcbb5e0e05aaf11e6bdfe36930fde38953dc89aa Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Fri, 25 Oct 2024 17:52:13 +0200 Subject: [PATCH] Generate the commit message with the actual commit of main --- bin/dune | 1 + bin/push.ml | 24 +++++++++++++++++++++++- blogger.opam | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bin/dune b/bin/dune index cc61281..a815cf0 100644 --- a/bin/dune +++ b/bin/dune @@ -14,6 +14,7 @@ fmt.tty logs.fmt git-unix + bos yocaml yocaml_git yocaml_syndication diff --git a/bin/push.ml b/bin/push.ml index ed381bb..b65e992 100644 --- a/bin/push.ml +++ b/bin/push.ml @@ -15,12 +15,34 @@ let reporter ppf = in { Logs.report } +let run_git_rev_parse () = + let open Bos in + let value = OS.Cmd.run_out + Cmd.(v "git" % "describe" % "--always" % "--dirty" + % "--exclude=*" % "--abbrev=0") + in + match OS.Cmd.out_string value with + | Ok (value, (_, `Exited 0)) -> Some value + | Ok (value, (run_info, _)) -> + Logs.warn (fun m -> m "Failed to get commit id: %a: %s" + Cmd.pp (OS.Cmd.run_info_cmd run_info) + value); + None + | Error `Msg e -> + Logs.warn (fun m -> m "Failed to get commit id: %s" e); + None + +let message () = + match run_git_rev_parse () with + | Some hash -> Fmt.str "Pushed by YOCaml 2 from %s" hash + | None -> Fmt.str "Pushed by YOCaml 2" + let () = Fmt_tty.setup_std_outputs ~style_renderer:`Ansi_tty ~utf_8:true () let () = Logs.set_reporter (reporter Fmt.stdout) (* let () = Logs.set_level ~all:true (Some Logs.Debug) *) let author = ref "The Robur Team" let email = ref "team@robur.coop" -let message = ref "Pushed by YOCaml 2" +let message = ref (message ()) let remote = ref "git@git.robur.coop:robur/blog.robur.coop.git#gh-pages" let host = ref "https://blog.robur.coop" diff --git a/blogger.opam b/blogger.opam index a5bfb6b..aaf5726 100644 --- a/blogger.opam +++ b/blogger.opam @@ -24,6 +24,7 @@ depends: [ "logs" {>= "0.7.0" } "cmdliner" { >= "1.0.0"} "http-lwt-client" + "bos" "yocaml" {>= "2.0.1"} "yocaml_unix" "yocaml_yaml"