From 3a092b600df0a93c231a311ad5b67c806685fbfc Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Mon, 29 Jul 2024 00:53:54 +0200 Subject: [PATCH] WIP show changelog since last devbuild in embed codeblock text is too big, looks ugly in discord embed also fields and embed content are limited length needs some other way to highligght added/removed lines --- .github/workflow_data/devbuild.py | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/.github/workflow_data/devbuild.py b/.github/workflow_data/devbuild.py index 79cdb26120..75411182b5 100644 --- a/.github/workflow_data/devbuild.py +++ b/.github/workflow_data/devbuild.py @@ -1,7 +1,9 @@ #!/usr/bin/env python import datetime as dt +import subprocess import requests import json +import re import os artifact_tgz = f"{os.environ['INDEXER_URL']}/firmware/dev/{os.environ['ARTIFACT_TAG']}.tgz" @@ -9,6 +11,66 @@ artifact_lab = f"https://lab.flipper.net/?url={artifact_tgz}&channel=dev-cfw&version={os.environ['VERSION_TAG']}" +def parse_diff(diff: str): + lines = diff.splitlines()[5:] + parsed = {} + previndent = "" + prevtext = "" + categories = [] + + for line in lines: + text = line[1:] + if not text.strip(): + continue + + indent = re.match("^[-# ]+", text) + if not indent: + continue + indent = indent[0].rstrip() + if indent.startswith("#"): + categories = [] + indent = "" + elif indent != previndent: + if len(indent) > len(previndent): + categories.append(prevtext) + else: + categories.pop() + previndent = indent + prevtext = text + + change = line[0] + if change != " ": + section = parsed + for category in categories: + section.setdefault(category, {}) + section = section[category] + section.setdefault(text, {}) + section[text][None] = change + + return parsed + + +def format_changes(section, name=None, lines=None): + if not name: + lines = [] + else: + if name.startswith("#"): + lines.append(f"\n{name}") + else: + change = section.get(None) + name = name.replace("-", change or "*", 1) + if change: + name = change + name[1:] + lines.append(name) + + for key, value in section.items(): + if key is not None: + format_changes(value, name=key, lines=lines) + + if not name: + return "\n".join(lines).lstrip() + + if __name__ == "__main__": with open(os.environ["GITHUB_EVENT_PATH"], "r") as f: event = json.load(f) @@ -27,6 +89,10 @@ if channel["id"] == "development": before = channel["versions"][0]["version"] + last_build_diff = subprocess.check_output(["git", "diff", f"{before}:CHANGELOG.md", f"{after}:CHANGELOG.md", "-U99999"]).decode() + parsed = parse_diff(last_build_diff) + changes = format_changes(parsed) + requests.post( os.environ["BUILD_WEBHOOK"], headers={"Accept": "application/json", "Content-Type": "application/json"}, @@ -50,6 +116,10 @@ "name": "Changelog:", "value": "\n".join([ f"[Since last release ({release})]({event['repository']['html_url']}/blob/{after}/CHANGELOG.md)", + f"Since last build ({before[:8]}):", + "```diff", + changes, + "```", ]) }, {