Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github action for check conflicts in resources.yaml #299

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/check_conflicts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check Conflicts

Check warning on line 1 in .github/workflows/check_conflicts.yml

View workflow job for this annotation

GitHub Actions / yamllint

1:1 [document-start] missing document start "---"

on:

Check warning on line 3 in .github/workflows/check_conflicts.yml

View workflow job for this annotation

GitHub Actions / yamllint

3:1 [truthy] truthy value should be one of [false, true]
pull_request:
types: [opened, synchronize, reopened, edited]

jobs:
check_conflicts:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pandas==2.2.2 PyYAML==6.0.1

- name: Run check_conflicts.py
run: python check_conflicts.py
60 changes: 60 additions & 0 deletions check_conflicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import yaml
import pandas as pd


def check_conflicts(file_path):
with open(file_path, "r") as file:
data = yaml.safe_load(file)
df = pd.DataFrame(data["deployment"])
df = df.T
df["max_count"] = df["flavor"].apply(lambda x: data["nodes_inventory"][x])
df["node"] = df.index

training_df = df[df["node"].str.startswith("training-")]
if not training_df.empty:
training_df = training_df.reset_index()
training_df["date"] = training_df.apply(
lambda x: pd.date_range(start=x["start"], end=x["end"]), axis=1
)
training_df = training_df.explode("date")
training_df = training_df.groupby(["flavor", "date"]).agg(
{"count": "sum", "max_count": "first", "node": "unique"}
)
training_df = training_df.reset_index()
training_df["conflict"] = (
training_df["count"] > training_df["max_count"]
)

not_training_df = df[~df["node"].str.startswith("training-")]
not_training_df = not_training_df.groupby("flavor").agg(
{"count": "sum", "max_count": "first", "node": "unique"}
)
not_training_df = not_training_df.reset_index()
not_training_df["conflict"] = (
not_training_df["count"] > not_training_df["max_count"]
)

df = pd.concat([training_df, not_training_df]) if not training_df.empty and not not_training_df.empty else training_df if not training_df.empty else not_training_df

df["node"] = df["node"].apply(lambda x: ", ".join(x))

conflicts = []
for _, row in df[df["conflict"]].iterrows():
date = (
f"on {row['date'].strftime('%Y-%m-%d')} "
if not pd.isnull(row["date"])
else ""
)
conflicts.append(
f"Conflict for {row['flavor']} {date}with {row['count']} nodes requested but only {row['max_count']} available. Conflicted nodes: {row['node']}."
)

conflicts = "\n".join(conflicts)
if conflicts:
raise ValueError(f"Conflicts found:\n{conflicts}")
else:
return True


if __name__ == "__main__":
check_conflicts("resources.yaml")
Loading