diff --git a/.buildkite/pipeline.py b/.buildkite/pipeline.py index 68016e3a0c65..b0b2beb3dfe6 100755 --- a/.buildkite/pipeline.py +++ b/.buildkite/pipeline.py @@ -2,8 +2,11 @@ import yaml import os from dataclasses import dataclass, field +<<<<<<< HEAD import subprocess import fnmatch +======= +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 from jinja2 import Template from pathlib import Path @@ -26,6 +29,10 @@ def create_entity(self): msg = tm.render(pipeline=self) return msg +<<<<<<< HEAD +======= + +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 @dataclass(unsafe_hash=True) class Group: """Buildkite Group object""" @@ -91,6 +98,7 @@ def create_entity(self): msg = tm.render(stage=self) return msg +<<<<<<< HEAD # Conditions: def is_pr() -> bool: @@ -98,6 +106,18 @@ def is_pr() -> bool: return pr and os.getenv('BUILDKITE_PULL_REQUEST') != "false" def step_comment(step: Step) -> bool: +======= + +def is_step_enabled(step: Step, conditions) -> bool: + # TODO: + # If PR then + # If Changeset + + pull_request = os.getenv('BUILDKITE_PULL_REQUEST') + if pull_request and pull_request == "false": + return True + +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 comment = os.getenv('GITHUB_PR_TRIGGER_COMMENT') if comment: # the comment should be a subset of the values in .buildkite/pull-requests.json @@ -108,10 +128,34 @@ def step_comment(step: Step) -> bool: return True # i.e: /test filebeat unitTest return comment_prefix + " " + step.name in comment +<<<<<<< HEAD else: return True def group_comment(group: Group) -> bool: +======= + + labels_env = os.getenv('GITHUB_PR_LABELS') + if labels_env: + labels = labels_env.split() + # i.e: filebeat-unitTest + if step.project + '-' + step.name in labels: + return True + + return False + + +def is_group_enabled(group: Group, conditions) -> bool: + # TODO: + # If PR then + # If GitHub label matches project name + category (I'm not sure we wanna use this approach since GH comments support it) + # If Changeset + + pull_request = os.getenv('BUILDKITE_PULL_REQUEST') + if pull_request and pull_request == "false": + return True + +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 comment = os.getenv('GITHUB_PR_TRIGGER_COMMENT') if comment: # the comment should be a subset of the values in .buildkite/pull-requests.json @@ -122,6 +166,7 @@ def group_comment(group: Group) -> bool: return comment_prefix + " " + group.project in comment else: # i.e: test filebeat extended +<<<<<<< HEAD return comment_prefix + " " + group.project + " " + group.category in comment changed_files = None @@ -172,6 +217,12 @@ def is_group_enabled(group: Group, changeset_filters: list[str]) -> bool: return True return group_comment(group) +======= + return comment_prefix + " " + group.project + " " + group.category in comment + + return group.category.startswith("mandatory") + +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 def fetch_stage(name: str, stage, project: str, category: str) -> Step: """Create a step given the yaml object.""" @@ -188,7 +239,11 @@ def fetch_stage(name: str, stage, project: str, category: str) -> Step: provider="gcp") +<<<<<<< HEAD def fetch_group(stages, project: str, category: str) -> Group: +======= +def fetch_group(stages, project: str, category: str, conditions) -> Group: +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 """Create a group given the yaml object.""" steps = [] @@ -200,13 +255,22 @@ def fetch_group(stages, project: str, category: str) -> Group: project=project, stage=stages[stage]) +<<<<<<< HEAD if is_step_enabled(step): +======= + if is_step_enabled(step, conditions): +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 steps.append(step) return Group( project=project, category=category, +<<<<<<< HEAD steps=steps) +======= + steps=steps + ) +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 # TODO: validate unique stages! @@ -230,16 +294,30 @@ def main() -> None: group = fetch_group(stages=project_obj["stages"]["mandatory"], project=project, +<<<<<<< HEAD category="mandatory") if is_group_enabled(group, project_obj["when"]["changeset"]): +======= + category="mandatory", + conditions=conditions) + + if is_group_enabled(group, conditions): +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 groups.append(group) group = fetch_group(stages=project_obj["stages"]["extended"], project=project, +<<<<<<< HEAD category="extended") if is_group_enabled(group, project_obj["when"]["changeset"]): +======= + category="extended", + conditions=conditions) + + if is_group_enabled(group, conditions): +>>>>>>> fad7d2a36bf38b7a8d0eba18d4cee60984d32a95 extended_groups.append(group) # TODO: improve this merging lists diff --git a/filebeat/buildkite.yml b/filebeat/buildkite.yml index ae347506b21b..8dceb95688da 100644 --- a/filebeat/buildkite.yml +++ b/filebeat/buildkite.yml @@ -1,6 +1,7 @@ when: changeset: ## when PR contains any of those entries in the changeset - "filebeat/**" + stages: # default stage - it runs always for: # - branches/tags