Skip to content

Commit

Permalink
Allow specifying a list of branches to benchmark
Browse files Browse the repository at this point in the history
This would be useful for benchmarking more than one long running branches of a
repository, for instance, the `5.0` and `trunk` branches of ocaml/ocaml.
  • Loading branch information
punchagan committed Apr 3, 2023
1 parent 6df7b2f commit 3859ebc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
21 changes: 18 additions & 3 deletions pipeline/lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type repo = {
build_args : string list; [@default []]
notify_github : bool; [@default false]
if_label : string option; [@default None]
branches : string list; [@default []]
}
[@@deriving yojson]

Expand Down Expand Up @@ -98,18 +99,32 @@ let default name =
build_args = [];
notify_github = false;
if_label = None;
branches = [];
}

let must_benchmark repo conf =
match (conf.if_label, Repository.pull_number repo) with
let must_benchmark_branch repo conf =
match Repository.pull_number repo with
| Some _ -> true
| _ -> (
match (conf.branches, Repository.branch repo) with
| (_ :: _ as branches), Some name -> List.mem name branches
| [], _ ->
Option.value ~default:false @@ Repository.is_default_branch repo
| _, _ -> false)

let must_benchmark_pull repo conf =
match (conf.if_label, Repository.branch repo) with
| Some tag, Some _ -> List.mem tag (Repository.labels repo)
| _ -> true

let find t repo =
let name = Repository.info repo in
match List.filter (fun r -> r.name = name) t.repos with
| [] -> [ default name ]
| configs -> List.filter (must_benchmark repo) configs
| configs ->
configs
|> List.filter (must_benchmark_pull repo)
|> List.filter (must_benchmark_branch repo)

let find_image t image_name = Images.find image_name t.images

Expand Down
12 changes: 7 additions & 5 deletions pipeline/lib/pipeline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ let github_repositories repo =
repository ~commit ~github_head:head ~commit_message:message
in
match key with
(* Skip all branches other than the default branch, and check PRs *)
| `Ref branch when branch = default_branch ->
repository ~branch:default_branch_name ~labels:[] () :: lst
| `Ref branch ->
let branch = Util.get_branch_name branch in
repository ~branch
~is_default_branch:(branch = default_branch_name)
~labels:[] ()
:: lst
| `PR pr ->
repository ~title:pr.title ~pull_number:pr.id ~labels:pr.labels ()
:: lst
| _ -> lst)
:: lst)
ref_map []

let filter_stale_repositories repos =
Expand Down
5 changes: 4 additions & 1 deletion pipeline/lib/repository.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type t = {
github_api : Current_github.Api.t option;
title : string option;
labels : string list;
is_default_branch : bool option;
}

let default_src ?src commit =
Expand All @@ -18,7 +19,7 @@ let default_src ?src commit =
| Some src -> src

let v ~owner ~name ?src ~commit ?commit_message ?pull_number ?branch
?github_head ?github_api ?title ~labels () =
?github_head ?github_api ?title ~labels ?is_default_branch () =
{
owner;
name;
Expand All @@ -31,6 +32,7 @@ let v ~owner ~name ?src ~commit ?commit_message ?pull_number ?branch
src = default_src ?src commit;
title;
labels;
is_default_branch;
}

let owner t = t.owner
Expand All @@ -43,6 +45,7 @@ let pull_number t = t.pull_number
let title t = t.title
let labels t = t.labels
let branch t = t.branch
let is_default_branch t = t.is_default_branch
let github_head t = t.github_head
let github_api t = t.github_api
let id t = (t.owner, t.name)
Expand Down

0 comments on commit 3859ebc

Please sign in to comment.