From 29b51afc1b4c78d012298edc60968e3174ce681a Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Wed, 27 Nov 2024 17:58:27 +0200 Subject: [PATCH] Docs workflolw (#998) * test * clen * test more complex * fix * one line? * test * br * list * test more * omre? * cleaner * hmm * back * hmm * no json * fmt * speratate * cleaner * test * fix * aha * remove * ok * okay * test * reduce noise * reduce nosie * separate * fmt * cleaner * new lines * slim down * sort * remove import * fmt * app * tag docs-team * quote * revert app changes * skip if empty * skip better * test * clean * lets not block the rest of the pipeline * use files * dont fail if its empty --- .github/scripts/message.py | 97 +++++++++++++++++++++++++++ .github/workflows/app-test-suite.yaml | 19 +++++- 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100755 .github/scripts/message.py diff --git a/.github/scripts/message.py b/.github/scripts/message.py new file mode 100755 index 0000000000..4ab7de5139 --- /dev/null +++ b/.github/scripts/message.py @@ -0,0 +1,97 @@ +import sys +import json + + +def get_files_from_file(file: str): + with open(file, "r") as f: + json_files = f.read() + + try: + return json.loads(json_files.replace("\\", "")) + except json.JSONDecodeError: + print(f"Failed to decode JSON from {file}", file=sys.stderr) + exit(1) + + +trains_to_check = ["test", "stable", "enterprise"] +account_to_notify = ["@truenas/docs-team"] + + +def process(changed_files=[], added_files=[]): + 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 + + app = file.split("/")[2] + if file.startswith(f"ix-dev/{train}/{app}/templates/library/base_"): + continue + + if train not in changes: + changes[train] = {"apps": {}} + + if app not in changes[train]["apps"]: + changes[train]["apps"][app] = {"areas": set([]), "added": set([]), "modified": set([])} + + trimmed_file_name = file.replace(f"ix-dev/{train}/{app}/", "") + if file in added_files: + changes[train]["apps"][app]["added"].add(trimmed_file_name) + else: + changes[train]["apps"][app]["modified"].add(trimmed_file_name) + + 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 sorted(changes): + message += f"## `{train.title()}`\n\n" + for app in sorted(changes[train]["apps"]): + message += f"### `{app.title()}`\n" + if len(changes[train]["apps"][app]["areas"]) > 0: + fmt_areas = [f"`{a}`" for a in changes[train]["apps"][app]["areas"]] + message += f"Affected areas: {', '.join(fmt_areas)}\n" + if len(changes[train]["apps"][app]["added"]) > 0: + message += "Added files:\n" + for file in sorted(changes[train]["apps"][app]["added"]): + message += f"- `{file}`\n" + message += "\n" + if len(changes[train]["apps"][app]["modified"]) > 0: + message += "Modified files:\n" + for file in sorted(changes[train]["apps"][app]["modified"]): + message += f"- `{file}`\n" + message += "\n" + message += "\n---\n\n" + + if message != "": + message += "Notifying the following about changes to the trains:\n" + message += ", ".join(account_to_notify) + return message + + +ALL_CHANGED_FILE = ".github/outputs/all_changed_files.json" +ADDED_FILE = ".github/outputs/added_files.json" + + +def main(): + changed_files = get_files_from_file(ALL_CHANGED_FILE) + added_files = get_files_from_file(ADDED_FILE) + + 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 c6f63fe561..f1adb6ed2d 100644 --- a/.github/workflows/app-test-suite.yaml +++ b/.github/workflows/app-test-suite.yaml @@ -28,13 +28,28 @@ jobs: - name: Matrix Output id: changed-apps - # env: - # CHANGED_FILES: ${{ steps.changed-files-json.outputs.all_changed_files }} run: | out=$(python3 .github/scripts/changed_apps.py) echo "changed-apps=${out}" >> $GITHUB_OUTPUT echo "change-count=$(echo "${out}" | jq -r '.include | length')" >> $GITHUB_OUTPUT + - name: Message Generation + id: message + run: | + python3 .github/scripts/message.py > pr-comment.txt + if [ "$(cat pr-comment.txt)" != "" ]; then + echo "message=true" >> $GITHUB_OUTPUT + else + echo "message=false" >> $GITHUB_OUTPUT + fi + - name: Comment PR + uses: thollander/actions-comment-pull-request@v3 + if: steps.message.outputs.message == 'true' + continue-on-error: true + with: + comment-tag: notify-teams + file-path: pr-comment.txt + run-apps: name: Run Docker Compose Render/Install needs: changed-files