Skip to content

Commit

Permalink
WIP show changelog since last devbuild in embed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Willy-JL committed Jul 28, 2024
1 parent b9fd4e0 commit 3a092b6
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions .github/workflow_data/devbuild.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,76 @@
#!/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"
artifact_sdk = f"{os.environ['INDEXER_URL']}/firmware/dev/{os.environ['ARTIFACT_TAG'].replace('update', 'sdk')}.zip"
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)
Expand All @@ -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"},
Expand All @@ -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,
"```",
])
},
{
Expand Down

0 comments on commit 3a092b6

Please sign in to comment.