Skip to content

Commit

Permalink
Docs workflolw (#998)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stavros-k authored Nov 27, 2024
1 parent 6183721 commit 29b51af
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
97 changes: 97 additions & 0 deletions .github/scripts/message.py
Original file line number Diff line number Diff line change
@@ -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()
19 changes: 17 additions & 2 deletions .github/workflows/app-test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29b51af

Please sign in to comment.