Skip to content

Commit

Permalink
Merged
Browse files Browse the repository at this point in the history
  • Loading branch information
pazone committed Mar 13, 2024
2 parents 5e9e865 + fad7d2a commit fefe766
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .buildkite/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"""
Expand Down Expand Up @@ -91,13 +98,26 @@ def create_entity(self):
msg = tm.render(stage=self)
return msg

<<<<<<< HEAD
# Conditions:

def is_pr() -> bool:
pr = os.getenv('BUILDKITE_PULL_REQUEST')
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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand All @@ -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 = []
Expand All @@ -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!
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions filebeat/buildkite.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit fefe766

Please sign in to comment.