Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k committed Nov 22, 2024
1 parent b5d44b2 commit a4f2005
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/scripts/message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os
import sys
import json


def get_files_from_env(env_var: str):
json_files = os.getenv(env_var, "")
if not json_files:
print(f"Environment variable {env_var} is empty", file=sys.stderr)
exit(1)

try:
return json.loads(json_files.replace("\\", ""))
except json.JSONDecodeError:
print(f"Failed to decode JSON from {env_var}", file=sys.stderr)
exit(1)


def process(changed_files=[], added_files=[]):
trains_to_check = ["test", "stable", "enterprise"]

changes = {}

for file in changed_files:
if not file.startswith("ix-dev/"):
continue
train = file.split("/")[1]
if train not in trains_to_check:
continue

if train not in changes:
changes[train] = {"apps": {}}
app = file.split("/")[2]

if app not in changes[train]["apps"]:
changes[train]["apps"][app] = {"areas": set([]), "added": set([]), "modified": set([])}

if file in added_files:
changes[train]["apps"][app]["added"].add(file)

if file.endswith("questions.yaml"):
changes[train]["apps"][app]["areas"].add("ui")
elif file.endswith("app.yaml"):
changes[train]["apps"][app]["areas"].add("metadata")
elif file.endswith("docker-compose.yaml"):
changes[train]["apps"][app]["areas"].add("template")
elif file.endswith("ix_values.yaml"):
changes[train]["apps"][app]["areas"].add("static_config")

return generate_message(changes)


def generate_message(changes):
message = ""
for train in changes:
message += f"## `{train}` train\n"
for app in changes[train]["apps"]:
message += f"### `{app}` app\n"
if len(changes[train]["apps"][app]["areas"]) > 0:
message += f"Affected areas: {', '.join(changes[train]["apps"][app]["areas"])}\n"
if len(changes[train]["apps"][app]["added"]) > 0:
message += "Added files:\n"
for file in changes[train]["apps"][app]["added"]:
message += f"- `{file}`\n"
if len(changes[train]["apps"][app]["modified"]) > 0:
message += "Modified files:\n"
for file in changes[train]["apps"][app]["modified"]:
message += f"- Modified `{file}`\n"
message += "\n"
message += "---\n"

return message


def main():
changed_files = get_files_from_env("CHANGED_FILES")
added_files = get_files_from_env("ADDED_FILES")

print(process(changed_files, added_files))


if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions .github/workflows/app-test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ jobs:
echo "changed-apps=${out}" >> $GITHUB_OUTPUT
echo "change-count=$(echo "${out}" | jq -r '.include | length')" >> $GITHUB_OUTPUT
- name: Message Generation
id: message
env:
CHANGED_FILES: ${{ steps.changed-files-json.outputs.all_changed_files }}
ADDED_FILES: ${{ steps.changed-files-json.outputs.added_files }}
run: |
out=$(python3 .github/scripts/message.py)
echo "${out}"
echo "message=${out}" >> $GITHUB_OUTPUT
run-apps:
name: Run Docker Compose Render/Install
needs: changed-files
Expand Down

0 comments on commit a4f2005

Please sign in to comment.