Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
Merge branch 'ClaraCrazy:main' into FlipperXtreme
Browse files Browse the repository at this point in the history
  • Loading branch information
IamUSER committed Apr 23, 2023
2 parents 3683a02 + b85fcad commit c6abb17
Show file tree
Hide file tree
Showing 299 changed files with 11,770 additions and 2,168 deletions.
150 changes: 150 additions & 0 deletions .github/workflow_data/discord.py
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": [],
},
)
83 changes: 83 additions & 0 deletions .github/workflow_data/hotfix.py
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)
18 changes: 18 additions & 0 deletions .github/workflow_data/package.sh
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
18 changes: 13 additions & 5 deletions .github/workflow_data/release.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
## ⬇️ Download
>### [🖥️ Web Updater (chrome)](https://lab.flipper.net/?url={webupdater_url}&channel=XFW-Updater&version={release_tag}) [recommended]
>### [🖥️ Web Updater (chrome)](https://lab.flipper.net/?url={ARTIFACT_WEB}&channel=XFW-Updater&version={VERSION_TAG}) [recommended]
>### [🐬 qFlipper Package (.tgz)](https://github.com/ClaraCrazy/Flipper-Xtreme/releases/download/{release_tag}/{release_tag}.tgz)
>### [🐬 qFlipper Package (.tgz)](https://github.com/ClaraCrazy/Flipper-Xtreme/releases/download/{VERSION_TAG}/{ARTIFACT_TGZ})
>### [📦 Zipped Archive (.zip)](https://github.com/ClaraCrazy/Flipper-Xtreme/releases/download/{release_tag}/{release_tag}.zip)
>### [📦 Zipped Archive (.zip)](https://github.com/ClaraCrazy/Flipper-Xtreme/releases/download/{VERSION_TAG}/{ARTIFACT_ZIP})
**Remember to delete your `apps` folders before updating!**\
**Check the [install guide](https://github.com/ClaraCrazy/Flipper-Xtreme#install) if you're not sure, or [join our Discord](https://discord.gg/flipper-xtreme) if you have questions or encounter issues!**

## 🚀 Changelog
{changelog}
{CHANGELOG}

<!--- <HOTFIXES>
### Hotfixes:
[//]: <NEXT_HOTFIX>
**If you have any of the above issues, please re-download and re-install!**
<HOTFIXES> -->

## ❤️ Support
If you like what you're seeing, **please consider donating to us**. We won't ever put this behind a paywall, but we'd still appreciate a few bucks!

- **[Direct transfer to my bank](https://bunq.me/ClaraK)**: No account needed, they have a convenient online pay thingy (that hates americans, sowwy)
- **[Direct Wire-transfer](https://bunq.me/ClaraK)**: No account needed, just specify amount and hit send
- **[Patreon](https://patreon.com/CynthiaLabs)**
- **[Paypal](https://paypal.me/RdX2020)**
- **Monero**: `41kyWeeoVdK4quzQ4M9ikVGs6tCQCLfdx8jLExTNsAu2SF1QAyDqRdjfGM6EL8L9NpXwt89HJeAoGf1aoArk7nDr4AMMV4T`
Expand Down
19 changes: 19 additions & 0 deletions .github/workflow_data/release.py
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)
4 changes: 4 additions & 0 deletions .github/workflow_data/version.sh
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
16 changes: 16 additions & 0 deletions .github/workflow_data/webupdater.py
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="")
36 changes: 36 additions & 0 deletions .github/workflows/discord.yml
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

0 comments on commit c6abb17

Please sign in to comment.