From ce4c5d2b37966c3df36363e26a5f3c9c8b9e03bc Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Thu, 18 Jan 2024 13:57:29 +0000 Subject: [PATCH] Fix the checking of the workflow generation --- .github/workflows/ci.ml | 11 ++++++++--- .github/workflows/lib.ml | 21 +++++++++++++++------ .github/workflows/main.yml | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.ml b/.github/workflows/ci.ml index 29101b22cd4..c82c7666980 100644 --- a/.github/workflows/ci.ml +++ b/.github/workflows/ci.ml @@ -216,7 +216,7 @@ let build_cache ?cond name = if cache.always_build then cond else - Option.map_default (fun cond -> Some (And (cond, miss))) (Some miss) cond + Option.map_default (fun cond -> Some (And [cond; miss])) (Some miss) cond in run ?cond ?shell:cache.build_shell (Printf.sprintf "%s %s%s" (if cache.always_build then "Unpack" else "Create") cache.name (if cache.always_build then "" else " cache")) cache.build) @@ -234,7 +234,7 @@ let install_sys_packages packages ~descr ?cond platforms = let not_windows = Predicate(false, Runner Windows) in let cond = if List.mem Windows platforms then - Option.map_default (fun cond -> Some (And (not_windows, cond))) (Some not_windows) cond + Option.map_default (fun cond -> Some (And [not_windows; cond])) (Some not_windows) cond else cond in @@ -467,7 +467,12 @@ let hygiene_job (type a) ~analyse_job (platform : a platform) ~oc ~workflow f = " echo \"AD ${changed_file}.\""; "done"; ] - ++ 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"] + ++ run "Hygiene" ~cond:(Or[Predicate(true, Contains("steps.files.outputs.modified", "configure.ac")); + Predicate(true, Contains("steps.files.outputs.all", "src_ext")); + Predicate(true, Contains("steps.files.outputs.all", ".github/workflows"))]) + ~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 main oc : unit = diff --git a/.github/workflows/lib.ml b/.github/workflows/lib.ml index 720b3fe511e..0eb2f254511 100644 --- a/.github/workflows/lib.ml +++ b/.github/workflows/lib.ml @@ -155,8 +155,8 @@ let end_job ~oc ~workflow ~job f = f job ~oc ~workflow let (++) = (@@) type condition = -| And of condition * condition -| Or of condition * condition +| And of condition list +| Or of condition list | Predicate of bool * variable and variable = | Runner of os_only platform @@ -165,16 +165,25 @@ and variable = | Contains of string * string | Compare of string * string +let all_predicates = + List.for_all (function Predicate(_, _) -> true | _ -> false) + let emit_condition ~oc ~indent = let indent = String.make indent ' ' in let rec to_yaml condition = match condition with - | And ((Predicate(_, _) as l), (Predicate(_, _) as r)) -> recurse l ^ " && " ^ recurse r - | Or ((Predicate(_, _) as l), (Predicate(_, _) as r)) -> recurse l ^ " || " ^ recurse r + | And predicates when all_predicates predicates -> + String.concat " && " (List.map recurse predicates) + | Or predicates when all_predicates predicates -> + String.concat " || " (List.map recurse predicates) | cond -> recurse cond and recurse = function - | And (l, r) -> Printf.sprintf "((%s) && (%s))" (recurse l) (recurse r) - | Or (l, r) -> Printf.sprintf "((%s) || (%s))" (recurse l) (recurse r) + | And tests -> + String.concat " && " (List.map recurse tests) + |> Printf.sprintf "(%s)" + | Or tests -> + String.concat " || " (List.map recurse tests) + |> Printf.sprintf "(%s)" | Predicate (op, EndsWith(variable, constant)) -> let op = if op then "" else " == false" in Printf.sprintf "endsWith(%s, '%s')%s" variable constant op diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a6866af1a2..d06a1b729aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -616,5 +616,5 @@ jobs: env: BASE_REF_SHA: ${{ github.event.pull_request.base.sha }} PR_REF_SHA: ${{ github.event.pull_request.head.sha }} - if: contains(steps.files.outputs.modified, 'configure.ac') || contains(steps.files.outputs.all, 'src_ext') + if: contains(steps.files.outputs.modified, 'configure.ac') || contains(steps.files.outputs.all, 'src_ext') || contains(steps.files.outputs.all, '.github/workflows') run: bash -exu .github/scripts/main/hygiene.sh