This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V44 Release Candidate Changes (#197)
- Loading branch information
Showing
299 changed files
with
11,770 additions
and
2,168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#!/usr/bin/env python | ||
import requests | ||
import json | ||
import sys | ||
import os | ||
|
||
|
||
if __name__ == "__main__": | ||
with open(os.environ["GITHUB_EVENT_PATH"], "r") as f: | ||
event = json.load(f) | ||
|
||
webhook = "DEV_DISCORD_WEBHOOK" | ||
title = desc = url = "" | ||
color = 0 | ||
fields = [] | ||
|
||
match os.environ["GITHUB_EVENT_NAME"]: | ||
case "push": | ||
count = len(event["commits"]) | ||
branch = event["ref"].removeprefix("refs/heads/") | ||
change = ( | ||
"Force Push" | ||
if event["forced"] and not count | ||
else f"{count} New Commit{'' if count == 1 else 's'}" | ||
) | ||
desc = f"[**{change}**]({event['compare']}) | [{branch}]({event['repository']['html_url']}/tree/{branch})\n" | ||
for commit in event["commits"][:10]: | ||
msg = commit['message'].splitlines()[0] | ||
msg = msg[:50] + ("..." if len(msg) > 50 else "") | ||
desc += f"\n[`{commit['id'][:7]}`]({commit['url']}): {msg} - [__{commit['author']['username']}__](https://github.com/{commit['author']['username']})" | ||
if count > 10: | ||
desc += f"\n+ {count - 10} more commits" | ||
url = event["compare"] | ||
color = 16723712 if event["forced"] else 3669797 | ||
|
||
case "pull_request": | ||
pr = event["pull_request"] | ||
url = pr["html_url"] | ||
branch = pr["base"]["ref"] + ( | ||
"" | ||
if pr["base"]["full_name"] != pr["head"]["full_name"] | ||
else f" <- {pr['head']['ref']}" | ||
) | ||
name = pr["title"][:50] + ("..." if len(pr["title"]) > 50 else "") | ||
title = f"Pull Request {event['action'].title()} ({branch}): {name}" | ||
match event["action"]: | ||
case "opened": | ||
desc = (event["body"][:2045] + "...") if len(event["body"]) > 2048 else event["body"] | ||
color = 3669797 | ||
|
||
fields.append( | ||
{ | ||
"name": "Changed Files:", | ||
"value": str(pr["changed_files"]), | ||
"inline": True, | ||
} | ||
) | ||
fields.append( | ||
{ | ||
"name": "Added:", | ||
"value": "+" + str(pr["additions"]), | ||
"inline": True, | ||
} | ||
) | ||
fields.append( | ||
{ | ||
"name": "Removed:", | ||
"value": "-" + str(pr["deletions"]), | ||
"inline": True, | ||
} | ||
) | ||
|
||
case "closed": | ||
color = 16723712 | ||
case "reopened": | ||
color = 16751872 | ||
case _: | ||
sys.exit(1) | ||
|
||
case "release": | ||
match event["action"]: | ||
case "published": | ||
webhook = "DEV_DISCORD_WEBHOOK" | ||
color = 13845998 | ||
title = f"New Release published: {event['name']}" | ||
desc += f"Changelog:" | ||
|
||
changelog = "".join( | ||
event["body"] | ||
.split("Changelog")[1] | ||
.split("<!---")[0] | ||
.split("###") | ||
) | ||
downloads = [ | ||
option | ||
for option in [ | ||
Type.replace("\n\n>", "") | ||
for Type in event["body"] | ||
.split("Download\n>")[1] | ||
.split("### ")[:3] | ||
] | ||
if option | ||
] | ||
|
||
for category in changelog: | ||
group = category.split(":")[0].replace(" ", "") | ||
data = category.split(":")[1:].join(":") | ||
fields.append( | ||
{ | ||
"name": {group}, | ||
"value": { | ||
(data[:2045] + "...") if len(data) > 2048 else data | ||
}, | ||
} | ||
) | ||
fields.append( | ||
{ | ||
"name": "Downloads:", | ||
"value": "\n".join(downloads), | ||
"inline": True, | ||
} | ||
) | ||
case _: | ||
sys.exit(1) | ||
|
||
case _: | ||
sys.exit(1) | ||
|
||
requests.post( | ||
os.environ[webhook], | ||
headers={"Accept": "application/json", "Content-Type": "application/json"}, | ||
json={ | ||
"content": None, | ||
"embeds": [ | ||
{ | ||
"title": title[:256], | ||
"description": desc[:2048], | ||
"url": url, | ||
"color": color, | ||
"fields": fields[:25], | ||
"author": { | ||
"name": event["sender"]["login"][:256], | ||
"url": event["sender"]["html_url"], | ||
"icon_url": event["sender"]["avatar_url"], | ||
}, | ||
} | ||
], | ||
"attachments": [], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python | ||
import datetime as dt | ||
import requests | ||
import pathlib | ||
import json | ||
import sys | ||
import os | ||
import re | ||
|
||
if __name__ == "__main__": | ||
with open(os.environ["GITHUB_EVENT_PATH"], "r") as f: | ||
event = json.load(f) | ||
|
||
release = requests.get( | ||
event["repository"]["releases_url"].rsplit("{/")[0] + "latest", | ||
headers={ | ||
"Accept": "application/vnd.github.v3+json", | ||
"Authorization": f"token {os.environ['GITHUB_TOKEN']}" | ||
} | ||
).json() | ||
|
||
artifacts = ( | ||
os.environ['ARTIFACT_TGZ'], | ||
os.environ['ARTIFACT_ZIP'] | ||
) | ||
|
||
for asset in release["assets"]: | ||
if asset["name"] in artifacts: | ||
req = requests.delete( | ||
asset["url"], | ||
headers={ | ||
"Accept": "application/vnd.github.v3+json", | ||
"Authorization": f"token {os.environ['GITHUB_TOKEN']}" | ||
} | ||
) | ||
if not req.ok: | ||
print(f"{req.url = }\n{req.status_code = }\n{req.content = }") | ||
sys.exit(1) | ||
|
||
for artifact in artifacts: | ||
req = requests.post( | ||
release["upload_url"].rsplit("{?", 1)[0], | ||
headers={ | ||
"Accept": "application/vnd.github.v3+json", | ||
"Authorization": f"token {os.environ['GITHUB_TOKEN']}" | ||
}, | ||
params={ | ||
"name": artifact | ||
}, | ||
data=pathlib.Path(artifact).read_bytes() | ||
) | ||
if not req.ok: | ||
print(f"{req.url = }\n{req.status_code = }\n{req.content = }") | ||
sys.exit(1) | ||
|
||
hotfix_time = dt.datetime.now().strftime(r"%d-%m-%Y %H:%M") | ||
hotfix_desc = event['pull_request']['body'] | ||
hotfix = f"- `{hotfix_time}`: {hotfix_desc}\n" | ||
|
||
body = release["body"] | ||
body = re.sub( | ||
r"(https://lab\.flipper\.net/\?url=).*?(&channel=XFW-Updater&version=" + os.environ['VERSION_TAG'] + r")", | ||
r"\1" + os.environ['ARTIFACT_WEB'] + r"\2", | ||
body | ||
) | ||
body = body.replace("<!--- <HOTFIXES>\n", "") | ||
body = body.replace("\n<HOTFIXES> -->", "") | ||
insert = body.find("\n [//]: <NEXT_HOTFIX>\n") | ||
body = body[:insert] + hotfix + body[:insert] | ||
|
||
req = requests.patch( | ||
release["url"], | ||
headers={ | ||
"Accept": "application/vnd.github.v3+json", | ||
"Authorization": f"token {os.environ['GITHUB_TOKEN']}" | ||
}, | ||
json={ | ||
"body": body | ||
} | ||
) | ||
if not req.ok: | ||
print(f"{req.url = }\n{req.status_code = }\n{req.content = }") | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
export ARTIFACT_DIR="${VERSION_TAG}" | ||
|
||
export ARTIFACT_TGZ="${VERSION_TAG}.tgz" | ||
export ARTIFACT_ZIP="${VERSION_TAG}.zip" | ||
cd dist/${DEFAULT_TARGET}-* | ||
mv ${DEFAULT_TARGET}-update-* ${ARTIFACT_DIR} | ||
tar --format=ustar -czvf ../../${ARTIFACT_TGZ} ${ARTIFACT_DIR} | ||
cd ${ARTIFACT_DIR} | ||
7z a ../../../${ARTIFACT_ZIP} . | ||
cd ../../.. | ||
|
||
python -m pip install pyncclient | ||
export ARTIFACT_WEB="$(NC_FILE=${ARTIFACT_TGZ} NC_PATH=XFW-Updater python .github/workflow_data/webupdater.py)" | ||
|
||
echo "ARTIFACT_TGZ=${ARTIFACT_TGZ}" >> $GITHUB_ENV | ||
echo "ARTIFACT_WEB=${ARTIFACT_WEB}" >> $GITHUB_ENV | ||
echo "ARTIFACT_ZIP=${ARTIFACT_ZIP}" >> $GITHUB_ENV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python | ||
import json | ||
import os | ||
|
||
if __name__ == "__main__": | ||
notes_path = '.github/workflow_data/release.md' | ||
with open(os.environ['GITHUB_EVENT_PATH'], "r") as f: | ||
changelog = json.load(f)['pull_request']['body'] | ||
with open(notes_path, "r") as f: | ||
template = f.read() | ||
notes = template.format( | ||
ARTIFACT_TGZ=os.environ['ARTIFACT_TGZ'], | ||
ARTIFACT_WEB=os.environ['ARTIFACT_WEB'], | ||
ARTIFACT_ZIP=os.environ['ARTIFACT_ZIP'], | ||
VERSION_TAG=os.environ['VERSION_TAG'], | ||
CHANGELOG=changelog | ||
) | ||
with open(notes_path, "w") as f: | ||
f.write(notes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
export VERSION_TAG="$(grep -o "DIST_SUFFIX = .*" fbt_options.py | cut -d'"' -f2)" | ||
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import nextcloud_client | ||
import os | ||
|
||
if __name__ == "__main__": | ||
client = nextcloud_client.Client(os.environ["NC_HOST"]) | ||
client.login(os.environ["NC_USER"], os.environ["NC_PASS"]) | ||
file = os.environ["NC_FILE"] | ||
path = os.environ["NC_PATH"] + file | ||
try: | ||
client.delete(path) | ||
except Exception: | ||
pass | ||
client.put_file(path, file) | ||
share_link = client.share_file_with_link(path).get_link() | ||
download_link = share_link.rstrip("/") + "/download/" + file | ||
print(download_link, end="") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Discord webhook | ||
|
||
on: | ||
push: | ||
pull_request: | ||
types: | ||
- "opened" | ||
- "closed" | ||
- "reopened" | ||
release: | ||
types: | ||
- "published" | ||
check_suite: | ||
types: | ||
- "completed" | ||
issues: | ||
types: | ||
- "opened" | ||
- "closed" | ||
- "reopened" | ||
issue_comment: | ||
types: | ||
- "created" | ||
|
||
jobs: | ||
webhook: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: 'Checkout code' | ||
uses: actions/checkout@v3 | ||
|
||
- name: Send webhook | ||
env: | ||
DEV_DISCORD_WEBHOOK: "https://discord.com/api/webhooks/${{ secrets.DEV_WEBHOOK_ID }}/${{ secrets.DEV_WEBHOOK_TOKEN }}" | ||
run: python .github/workflow_data/discord.py |
Oops, something went wrong.