Skip to content

Commit

Permalink
Fix the checking of the workflow generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dra27 committed Jan 18, 2024
1 parent f2def32 commit ce4c5d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ce4c5d2

Please sign in to comment.