Skip to content

Commit 3deea7d

Browse files
authored
Add support for @coqbot inline-stdlib=yes resume ci minimize ci-foo (#262)
Also for `@coqbot extra-arg=--inline-coqlib resume ci minimize ci-foo` and `@coqbot extra-arg=--inline-coqlib ci minimize ci-foo` For coq/coq#16967 (comment), in conjunction with JasonGross/coq-tools#144
2 parents fb0e357 + 5212d20 commit 3deea7d

7 files changed

+107
-53
lines changed

coq_bug_minimizer.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
22

3-
# usage: coq_bug_minimizer.sh 'script' comment_thread_id comment_author github_token bot_name bot_domain owner repo coq_version ocaml_version
3+
# usage: coq_bug_minimizer.sh 'script' comment_thread_id comment_author github_token bot_name bot_domain owner repo coq_version ocaml_version minimizer_extra_arguments
44

55
set -ex
66

7-
if [ $# != 10 ]; then >&2 echo Bad argument count; exit 1; fi
7+
if [ $# != 11 ]; then >&2 echo Bad argument count; exit 1; fi
88

99
script=$1
1010
comment_thread_id=$2
@@ -16,6 +16,7 @@ owner=$7
1616
repo=$8
1717
coq_version=$9
1818
ocaml_version=${10}
19+
minimizer_extra_arguments=${11}
1920
branch_id=$(($(od -A n -t uI -N 5 /dev/urandom | tr -d ' ')))
2021
repo_name="coq-community/run-coq-bug-minimizer"
2122
branch_name="run-coq-bug-minimizer-$branch_id"
@@ -29,6 +30,7 @@ pushd "$wtree"
2930
printf "%s %s %s %s %s %s" "$comment_thread_id" "$comment_author" "$repo_name" "$branch_name" "$owner" "$repo" > coqbot-request-stamp
3031
test -z "${coq_version}" || sed -i 's~^\(\s*\)[^:\s]*coq_version:.*$~\1coq_version: '"'${coq_version}'~" .github/workflows/main.yml
3132
test -z "${ocaml_version}" || sed -i 's~^\(\s*\)[^:\s]*ocaml_version:.*$~\1ocaml_version: '"'${ocaml_version}'~" .github/workflows/main.yml
33+
printf "%s" "${minimizer_extra_arguments}" | tr ' ' '\n' > coqbot.extra-args
3234
printf "%s\n" "$script" > coqbot.sh
3335
sed -i 's/\r$//g' coqbot.sh
3436
echo "https://$bot_domain/coq-bug-minimizer" > coqbot.url

run_ci_minimization.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
22

3-
# usage: coq_bug_minimizer.sh comment_thread_id github_token bot_name bot_domain owner repo pr_number docker_image target opam_switch failing_urls passing_urls base head [bug_file]
3+
# usage: coq_bug_minimizer.sh comment_thread_id github_token bot_name bot_domain owner repo pr_number docker_image target opam_switch failing_urls passing_urls base head minimizer_extra_arguments [bug_file]
44

55
set -ex
66

7-
if [ $# != 14 ] && [ $# != 15 ]; then >&2 echo Bad argument count; exit 1; fi
7+
if [ $# != 15 ] && [ $# != 16 ]; then >&2 echo Bad argument count; exit 1; fi
88

99
comment_thread_id=$1
1010
token=$2
@@ -20,7 +20,8 @@ failing_urls=${11}
2020
passing_urls=${12}
2121
base=${13}
2222
head=${14}
23-
bug_file=${15}
23+
minimizer_extra_arguments=${15}
24+
bug_file=${16}
2425
branch_id=$(($(od -A n -t uI -N 5 /dev/urandom | tr -d ' ')))
2526
repo_name="coq-community/run-coq-bug-minimizer"
2627
branch_name="run-coq-bug-minimizer-$branch_id"
@@ -33,6 +34,7 @@ resumption_args=(
3334
"${passing_urls}"
3435
"${base}"
3536
"${head}"
37+
"${minimizer_extra_arguments}"
3638
)
3739

3840
if [ -f "${bug_file}" ]; then
@@ -56,6 +58,7 @@ echo "${passing_urls}" > coqbot.passing-artifact-urls
5658
echo "${head}" > coqbot.failing-sha
5759
echo "${base}" > coqbot.passing-sha
5860
echo "${pr_number}" > coqbot.issue-number
61+
printf "%s" "${minimizer_extra_arguments}" | tr ' ' '\n' > coqbot.extra-args
5962
echo "https://$bot_domain/ci-minimization" > coqbot.url
6063
echo "https://$bot_domain/resume-ci-minimization" > coqbot.resume-minimization-url
6164
rm -f coqbot.resumption-args

src/actions.ml

+61-28
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ type ci_minimization_info =
736736
; passing_urls: string }
737737

738738
let run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo ~pr_number
739-
~base ~head ~ci_minimization_infos ~bug_file_contents =
739+
~base ~head ~ci_minimization_infos ~bug_file_contents
740+
~minimizer_extra_arguments =
740741
(* for convenience of control flow, we always create the temporary
741742
file, but we only pass in the file name if the bug file contents
742743
is non-None *)
@@ -752,7 +753,7 @@ let run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo ~pr_number
752753
(fun {target; opam_switch; failing_urls; passing_urls; docker_image} ->
753754
git_run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo
754755
~pr_number ~docker_image ~target ~opam_switch ~failing_urls
755-
~passing_urls ~base ~head ~bug_file_name
756+
~passing_urls ~base ~head ~minimizer_extra_arguments ~bug_file_name
756757
>>= fun result -> Lwt.return (target, result) )
757758
ci_minimization_infos )
758759
>>= fun results ->
@@ -1176,9 +1177,43 @@ let suggest_ci_minimization_for_pr = function
11761177
| _ ->
11771178
Suggest
11781179

1180+
let format_options_for_getopts options =
1181+
" " ^ options ^ " " |> Str.global_replace (Str.regexp "[\n\r\t]") " "
1182+
1183+
let getopts options ~opt =
1184+
map_string_matches
1185+
~regexp:(f " %s\\(\\.\\|[ =:-]\\|: \\)\\([^ ]+\\) " opt)
1186+
~f:(fun () -> Str.matched_group 2 options)
1187+
options
1188+
1189+
let getopt options ~opt =
1190+
options |> getopts ~opt |> List.hd |> Option.value ~default:""
1191+
1192+
let accumulate_extra_minimizer_arguments options =
1193+
let extra_args = getopts ~opt:"extra-arg" options in
1194+
let inline_stdlib = getopt ~opt:"inline-stdlib" options in
1195+
( if String.equal inline_stdlib "yes" then Lwt.return ["--inline-coqlib"]
1196+
else
1197+
( if not (String.equal inline_stdlib "") then
1198+
Lwt_io.printlf
1199+
"Ignoring invalid option to inline-stdlib '%s' not equal to 'yes'"
1200+
inline_stdlib
1201+
else Lwt.return_unit )
1202+
>>= fun () -> Lwt.return_nil )
1203+
>>= fun inline_stdlib_args -> inline_stdlib_args @ extra_args |> Lwt.return
1204+
11791205
let minimize_failed_tests ~bot_info ~owner ~repo ~pr_number
11801206
~head_pipeline_summary ~request ~comment_on_error ~bug_file_contents
1181-
?base_sha ?head_sha () =
1207+
~options ?base_sha ?head_sha () =
1208+
let options = format_options_for_getopts options in
1209+
accumulate_extra_minimizer_arguments options
1210+
>>= fun minimizer_extra_arguments ->
1211+
Lwt_io.printlf
1212+
"Parsed options for the bug minimizer at %s/%s#%d from '%s' into \
1213+
{minimizer_extra_arguments: '%s'}"
1214+
owner repo pr_number options
1215+
(String.concat ~sep:" " minimizer_extra_arguments)
1216+
>>= fun () ->
11821217
fetch_ci_minimization_info ~bot_info ~owner ~repo ~pr_number
11831218
~head_pipeline_summary ?base_sha ?head_sha ()
11841219
>>= function
@@ -1264,7 +1299,8 @@ let minimize_failed_tests ~bot_info ~owner ~repo ~pr_number
12641299
>>= fun () ->
12651300
run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo
12661301
~pr_number:(Int.to_string pr_number) ~base ~head
1267-
~ci_minimization_infos:jobs_to_minimize ~bug_file_contents
1302+
~ci_minimization_infos:jobs_to_minimize ~minimizer_extra_arguments
1303+
~bug_file_contents
12681304
>>= fun (jobs_minimized, jobs_that_could_not_be_minimized) ->
12691305
let pluralize word ?plural ls =
12701306
match (ls, plural) with
@@ -1717,7 +1753,7 @@ let minimize_failed_tests ~bot_info ~owner ~repo ~pr_number
17171753
"Error while attempting to find jobs to minimize from PR #%d:\n%s"
17181754
pr_number err
17191755

1720-
let ci_minimize ~bot_info ~comment_info ~requests ~comment_on_error
1756+
let ci_minimize ~bot_info ~comment_info ~requests ~comment_on_error ~options
17211757
~bug_file_contents =
17221758
minimize_failed_tests ~bot_info ~owner:comment_info.issue.issue.owner
17231759
~repo:comment_info.issue.issue.repo ~pr_number:comment_info.issue.number
@@ -1730,7 +1766,7 @@ let ci_minimize ~bot_info ~comment_info ~requests ~comment_on_error
17301766
RequestAll
17311767
| requests ->
17321768
RequestExplicit requests )
1733-
~comment_on_error ~bug_file_contents ()
1769+
~comment_on_error ~options ~bug_file_contents ()
17341770

17351771
let pipeline_action ~bot_info pipeline_info ~gitlab_mapping : unit Lwt.t =
17361772
let gitlab_full_name = pipeline_info.project_path in
@@ -1862,7 +1898,7 @@ let pipeline_action ~bot_info pipeline_info ~gitlab_mapping : unit Lwt.t =
18621898
| "coq", "coq", "failed", Some pr_number ->
18631899
minimize_failed_tests ~bot_info ~owner ~repo ~pr_number
18641900
~head_pipeline_summary:(Some summary) ~request:Auto
1865-
~comment_on_error:false ~bug_file_contents:None
1901+
~comment_on_error:false ~options:"" ~bug_file_contents:None
18661902
?base_sha:pipeline_info.common_info.base_commit
18671903
~head_sha:pipeline_info.common_info.head_commit ()
18681904
| _ ->
@@ -1874,25 +1910,21 @@ type coqbot_minimize_script_data =
18741910

18751911
let run_coq_minimizer ~bot_info ~script ~comment_thread_id ~comment_author
18761912
~owner ~repo ~options =
1877-
let options =
1878-
" " ^ options ^ " " |> Str.global_replace (Str.regexp "[\n\r\t]") " "
1913+
let options = format_options_for_getopts options in
1914+
let getopt_version opt =
1915+
options |> getopt ~opt |> Str.replace_first (Str.regexp "^[vV]") ""
18791916
in
1880-
let getopt opt =
1881-
if
1882-
string_match
1883-
~regexp:(f " %s\\(\\.\\|[ =:-]\\|: \\)[vV]?\\([^ ]+\\) " opt)
1884-
options
1885-
then Str.matched_group 2 options
1886-
else ""
1887-
in
1888-
let coq_version = getopt "[Cc]oq" in
1889-
let ocaml_version = getopt "[Oo][Cc]aml" in
1917+
accumulate_extra_minimizer_arguments options
1918+
>>= fun minimizer_extra_arguments ->
1919+
let coq_version = getopt_version "[Cc]oq" in
1920+
let ocaml_version = getopt_version "[Oo][Cc]aml" in
18901921
Lwt_io.printlf
18911922
"Parsed options for the bug minimizer at %s/%s@%s from '%s' into \
1892-
{coq_version: '%s'; ocaml_version: '%s'}"
1923+
{coq_version: '%s'; ocaml_version: '%s'; minimizer_extra_arguments: '%s'}"
18931924
owner repo
18941925
(GitHub_ID.to_string comment_thread_id)
18951926
options coq_version ocaml_version
1927+
(String.concat ~sep:" " minimizer_extra_arguments)
18961928
>>= fun () ->
18971929
( match script with
18981930
| MinimizeScript {quote_kind; body} ->
@@ -1912,7 +1944,7 @@ let run_coq_minimizer ~bot_info ~script ~comment_thread_id ~comment_author
19121944
)
19131945
|> fun script ->
19141946
git_coq_bug_minimizer ~bot_info ~script ~comment_thread_id ~comment_author
1915-
~owner ~repo ~coq_version ~ocaml_version
1947+
~owner ~repo ~coq_version ~ocaml_version ~minimizer_extra_arguments
19161948
>>= function
19171949
| Ok () ->
19181950
GitHub_mutations.post_comment ~id:comment_thread_id
@@ -1972,12 +2004,12 @@ let coq_bug_minimizer_resume_ci_minimization_action ~bot_info ~key ~app_id body
19722004
; pr_number ] -> (
19732005
message |> String.split ~on:'\n'
19742006
|> function
1975-
| docker_image
1976-
:: target
1977-
:: opam_switch
1978-
:: failing_urls
1979-
:: passing_urls :: base :: head :: bug_file_lines ->
1980-
(let bug_file_contents = String.concat ~sep:"\n" bug_file_lines in
2007+
| docker_image :: target :: opam_switch :: failing_urls :: passing_urls
2008+
:: base :: head :: extra_arguments_joined :: bug_file_lines ->
2009+
(let minimizer_extra_arguments =
2010+
String.split ~on:' ' extra_arguments_joined
2011+
in
2012+
let bug_file_contents = String.concat ~sep:"\n" bug_file_lines in
19812013
fun () ->
19822014
init_git_bare_repository ~bot_info
19832015
>>= fun () ->
@@ -1986,6 +2018,7 @@ let coq_bug_minimizer_resume_ci_minimization_action ~bot_info ~key ~app_id body
19862018
(run_ci_minimization
19872019
~comment_thread_id:(GitHub_ID.of_string comment_thread_id)
19882020
~owner ~repo ~base ~pr_number ~head
2021+
~minimizer_extra_arguments
19892022
~ci_minimization_infos:
19902023
[ { target
19912024
; opam_switch
@@ -2430,7 +2463,7 @@ let run_ci_action ~bot_info ~comment_info ?full_ci ~gitlab_mapping
24302463
Lwt_io.printl "Unauthorized user: doing nothing." |> Lwt_result.ok
24312464
)
24322465
|> Fn.flip Lwt_result.bind_lwt_err (fun err ->
2433-
Lwt_io.printf "Error: %s\n" err ))
2466+
Lwt_io.printf "Error: %s\n" err ) )
24342467
>>= fun _ -> Lwt.return_unit )
24352468
|> Lwt.async ;
24362469
Server.respond_string ~status:`OK

src/actions.mli

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ val ci_minimize :
8787
-> comment_info:GitHub_types.comment_info
8888
-> requests:string list
8989
-> comment_on_error:bool
90+
-> options:string
9091
-> bug_file_contents:string option
9192
-> unit Lwt.t
9293

src/bot.ml

+27-16
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,23 @@ let callback _conn req body =
105105
if
106106
string_match
107107
~regexp:
108-
( f "@%s:? [Cc][Ii][- ][Mm]inimize:?\\([^\n]*\\)"
108+
( f "@%s:?\\( [^\n]*\\)\\b[Cc][Ii][- ][Mm]inimize:?\\([^\n]*\\)"
109109
@@ Str.quote bot_name )
110110
body
111111
then
112-
let requests = Str.matched_group 1 body in
113-
Some (requests |> parse_minimiation_requests)
112+
let options, requests =
113+
(Str.matched_group 1 body, Str.matched_group 2 body)
114+
in
115+
Some (options, requests |> parse_minimiation_requests)
114116
else None
115117
in
116118
let coqbot_resume_ci_minimize_text_of_body body =
117119
if
118120
string_match
119121
~regexp:
120122
( f
121-
"@%s:? resume [Cc][Ii][- ][Mm]inimiz\\(e\\|ation\\):?\\([^\n\
123+
"@%s:?\\( [^\n\
124+
]*\\)\\bresume [Cc][Ii][- ][Mm]inimiz\\(e\\|ation\\):?\\([^\n\
122125
]*\\)\n\
123126
+```[^\n\
124127
]*\n\
@@ -127,11 +130,15 @@ let callback _conn req body =
127130
@@ Str.quote bot_name )
128131
body
129132
then
130-
let requests, body =
131-
(Str.matched_group 2 body, Str.matched_group 3 body)
133+
let options, requests, body =
134+
( Str.matched_group 1 body
135+
, Str.matched_group 3 body
136+
, Str.matched_group 4 body )
132137
in
133138
Some
134-
(requests |> parse_minimiation_requests, body |> extract_minimize_file)
139+
( options
140+
, requests |> parse_minimiation_requests
141+
, body |> extract_minimize_file )
135142
else None
136143
in
137144
( coqbot_minimize_text_of_body
@@ -298,34 +305,38 @@ let callback _conn req body =
298305
Server.respond_string ~status:`OK ~body:"Handling minimization."
299306
()
300307
| None -> (
301-
match coqbot_ci_minimize_text_of_body body with
302-
| Some requests ->
308+
(* Since both ci minimization resumption and ci
309+
minimization will match the resumption string, and we
310+
don't want to parse "resume" as an option, we test
311+
resumption first *)
312+
match coqbot_resume_ci_minimize_text_of_body body with
313+
| Some (options, requests, bug_file_contents) ->
303314
(fun () ->
304315
init_git_bare_repository ~bot_info
305316
>>= fun () ->
306317
action_as_github_app ~bot_info ~key ~app_id
307318
~owner:comment_info.issue.issue.owner
308319
~repo:comment_info.issue.issue.repo
309320
(ci_minimize ~comment_info ~requests ~comment_on_error:true
310-
~bug_file_contents:None ) )
321+
~options ~bug_file_contents:(Some bug_file_contents) ) )
311322
|> Lwt.async ;
312323
Server.respond_string ~status:`OK
313-
~body:"Handling CI minimization." ()
324+
~body:"Handling CI minimization resumption." ()
314325
| None -> (
315-
match coqbot_resume_ci_minimize_text_of_body body with
316-
| Some (requests, bug_file_contents) ->
326+
match coqbot_ci_minimize_text_of_body body with
327+
| Some (options, requests) ->
317328
(fun () ->
318329
init_git_bare_repository ~bot_info
319330
>>= fun () ->
320331
action_as_github_app ~bot_info ~key ~app_id
321332
~owner:comment_info.issue.issue.owner
322333
~repo:comment_info.issue.issue.repo
323334
(ci_minimize ~comment_info ~requests
324-
~comment_on_error:true
325-
~bug_file_contents:(Some bug_file_contents) ) )
335+
~comment_on_error:true ~options ~bug_file_contents:None )
336+
)
326337
|> Lwt.async ;
327338
Server.respond_string ~status:`OK
328-
~body:"Handling CI minimization resumption." ()
339+
~body:"Handling CI minimization." ()
329340
| None ->
330341
if
331342
string_match

src/git_utils.ml

+6-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ let git_test_modified ~base ~head pattern =
130130
Error (f "%s stopped by signal %d." command signal)
131131

132132
let git_coq_bug_minimizer ~bot_info ~script ~comment_thread_id ~comment_author
133-
~owner ~repo ~coq_version ~ocaml_version =
133+
~owner ~repo ~coq_version ~ocaml_version ~minimizer_extra_arguments =
134134
(* To push a new branch we need to identify as coqbot the GitHub
135135
user, who is a collaborator on the run-coq-bug-minimizer repo,
136136
not coqbot the GitHub App *)
@@ -144,12 +144,13 @@ let git_coq_bug_minimizer ~bot_info ~script ~comment_thread_id ~comment_author
144144
; owner
145145
; repo
146146
; coq_version
147-
; ocaml_version ]
147+
; ocaml_version
148+
; minimizer_extra_arguments |> String.concat ~sep:" " ]
148149
|> execute_cmd
149150

150151
let git_run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo ~pr_number
151152
~docker_image ~target ~opam_switch ~failing_urls ~passing_urls ~base ~head
152-
~bug_file_name =
153+
~minimizer_extra_arguments ~bug_file_name =
153154
(* To push a new branch we need to identify as coqbot the GitHub
154155
user, who is a collaborator on the run-coq-bug-minimizer repo,
155156
not coqbot the GitHub App *)
@@ -166,7 +167,8 @@ let git_run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo ~pr_number
166167
; failing_urls
167168
; passing_urls
168169
; base
169-
; head ]
170+
; head
171+
; minimizer_extra_arguments |> String.concat ~sep:" " ]
170172
@
171173
match bug_file_name with Some bug_file_name -> [bug_file_name] | None -> [] )
172174
|> Stdlib.Filename.quote_command "./run_ci_minimization.sh"

0 commit comments

Comments
 (0)