diff --git a/.github/scripts/message.py b/.github/scripts/message.py new file mode 100755 index 0000000000..9614252242 --- /dev/null +++ b/.github/scripts/message.py @@ -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() diff --git a/.github/workflows/app-test-suite.yaml b/.github/workflows/app-test-suite.yaml index 73faadba77..b874b45375 100644 --- a/.github/workflows/app-test-suite.yaml +++ b/.github/workflows/app-test-suite.yaml @@ -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