From 640f0870dd9c7bd6a696268fd8afe36c806db22f Mon Sep 17 00:00:00 2001 From: Louis Gesbert Date: Thu, 19 Oct 2023 12:26:39 +0200 Subject: [PATCH 1/2] Add a --no-confirmation option This might be required for some complex release pipelines where the package is already guaranteed to be well reviewed and checked before `opam-publish` is called. I took care to add some safeguards to avoid copy-paste of ill-advised one-liners that would result in people submitting unreviewed releases and increasing the strain on the repository maintainers. --- src/publishMain.ml | 16 ++++++++++++++-- src/publishSubmit.ml | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/publishMain.ml b/src/publishMain.ml index a093f1f..938f395 100644 --- a/src/publishMain.ml +++ b/src/publishMain.ml @@ -515,6 +515,10 @@ module Args = struct and `descr`). This can be useful on legacy repositories, but is \ deprecated." + let no_confirmation = + value & flag & + info ["no-confirmation"] ~docs ~doc: + "Skip all confirmations. This should only ever be used in very special circumstances, like automated publishing CI workflows where measures to ensure the submission has been reviewed have already taken place." end let identical f = function @@ -650,7 +654,7 @@ let to_files ?(split=false) ~packages_dir meta_opams = let main_term root = let run args force tag version dry_run output_patch no_browser repo - target_branch packages_dir title msg split = + target_branch packages_dir title msg split no_confirmation = let dirs, opams, urls, projects, names = List.fold_left (fun (dirs, opams, urls, projects, names) -> function | `Dir d -> (dirs @ [d], opams, urls, projects, names) @@ -661,6 +665,13 @@ let main_term root = ([], [], [], [], []) args in + if no_confirmation then + if OpamStd.Sys.tty_in then + OpamConsole.error_and_exit `Bad_arguments + "'--no-confirmation' is not allowed in interactive mode. Please \ + review before submitting" + else + OpamCoreConfig.update ~confirm_level:`unsafe_yes (); let meta_opams = get_opams force dirs opams urls projects tag names version in @@ -685,7 +696,8 @@ let main_term root = let open Args in Term.(const run $ src_args $ force $ tag $ version $ dry_run $ output_patch $ no_browser - $ repo $ target_branch $ packages_dir $ title $ msg_file $ split) + $ repo $ target_branch $ packages_dir $ title $ msg_file $ split + $ no_confirmation) let main_info = diff --git a/src/publishSubmit.ml b/src/publishSubmit.ml index 4c0df51..a4731ae 100644 --- a/src/publishSubmit.ml +++ b/src/publishSubmit.ml @@ -285,7 +285,8 @@ let add_files_and_pr (fst repo) (snd repo) (OpamFilename.to_string out) end; if output_patch <> None || dry_run then OpamStd.Sys.exit_because `Success; - if not (OpamConsole.confirm "\nFile a pull-request for this patch ?") then + if not (OpamConsole.confirm ~require_unsafe_yes:true + "\nFile a pull-request for this patch ?") then OpamStd.Sys.exit_because `Aborted; let url = GH.pull_request title user token repo ~text:message branch target_branch From c566396ed17b5ce9d020353a38183984f8cb1a35 Mon Sep 17 00:00:00 2001 From: Kate Date: Mon, 23 Oct 2023 19:21:26 +0100 Subject: [PATCH 2/2] Update src/publishMain.ml --- src/publishMain.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/publishMain.ml b/src/publishMain.ml index 938f395..0657563 100644 --- a/src/publishMain.ml +++ b/src/publishMain.ml @@ -665,13 +665,14 @@ let main_term root = ([], [], [], [], []) args in - if no_confirmation then + if no_confirmation then begin if OpamStd.Sys.tty_in then OpamConsole.error_and_exit `Bad_arguments "'--no-confirmation' is not allowed in interactive mode. Please \ review before submitting" else - OpamCoreConfig.update ~confirm_level:`unsafe_yes (); + OpamCoreConfig.update ~confirm_level:`unsafe_yes () + end; let meta_opams = get_opams force dirs opams urls projects tag names version in