Skip to content

Commit

Permalink
New release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Mar 10, 2024
1 parent c0ed5bc commit ed08b19
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflow_data/devbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"title": "New Devbuild!",
"description": "",
"url": "",
"color": 11761899,
"color": 16751147,
"fields": [
{
"name": "Changes since last commit:",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflow_data/release.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## ⬇️ Download
>### [🖥️ Web Updater (chrome)](https://momentum-fw.dev/update) [recommended]
>### [🐬 qFlipper Package (.tgz)](https://github.com/Next-Flip/Momentum-Firmware/releases/download/{VERSION_TAG}/{ARTIFACT_TGZ})
>### [🐬 qFlipper Package (.tgz)](https://github.com/Next-Flip/Momentum-Firmware/releases/download/{VERSION_TAG}/flipper-z-f7-update-{VERSION_TAG}.tgz)
>### [📦 Zipped Archive (.zip)](https://github.com/Next-Flip/Momentum-Firmware/releases/download/{VERSION_TAG}/{ARTIFACT_ZIP})
>### [📦 Zipped Archive (.zip)](https://github.com/Next-Flip/Momentum-Firmware/releases/download/{VERSION_TAG}/flipper-z-f7-update-{VERSION_TAG}.zip)
**Check the [install guide](https://github.com/Next-Flip/Momentum-Firmware#install) if you're not sure, or [join our Discord](https://discord.gg/momentum) if you have questions or encounter issues!**

Expand Down
21 changes: 14 additions & 7 deletions .github/workflow_data/release.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/usr/bin/env python
import requests
import json
import os

if __name__ == "__main__":
with open(os.environ["GITHUB_EVENT_PATH"], "r") as f:
event = json.load(f)
release = requests.get(
event["release"]["url"],
headers={
"Accept": "application/vnd.github.v3+json",
"Authorization": f"token {os.environ['GITHUB_TOKEN']}"
}
).json()
version_tag = release["tag_name"]
changelog = release["body"]

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_ZIP=os.environ['ARTIFACT_ZIP'],
VERSION_TAG=os.environ['VERSION_TAG'],
VERSION_TAG=version_tag,
CHANGELOG=changelog
)
with open(notes_path, "w") as f:
f.write(notes)
with open(os.environ["ARTIFACT_TGZ"].removesuffix(".tgz") + ".md", "w") as f:
f.write(changelog.strip() + "\n\n")
53 changes: 9 additions & 44 deletions .github/workflow_data/webhook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
import datetime as dt
import requests
import json
import sys
Expand Down Expand Up @@ -44,50 +45,13 @@
color = 16723712 if event["forced"] else 3669797

case "release":
match event["action"]:
case "published":
webhook = "RELEASE_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)
webhook = "RELEASE_WEBHOOK"
color = 9471191
version_tag = event['release']['tag_name']
title = f"New Release: `{version_tag}`"
desc += f"> 💻 [**Web Installer**](https://momentum-fw.dev/update)\n\n"
desc += f"> 🐬 [**Changelog & Download**](https://github.com/Next-Flip/Momentum-Firmware/releases/tag/{version_tag})\n\n"
desc += f"> 🛞 [**Project Page**](https://github.com/Next-Flip/Momentum-Firmware)"

case "workflow_run":
run = event["workflow_run"]
Expand Down Expand Up @@ -148,6 +112,7 @@
"url": event["sender"]["html_url"],
"icon_url": event["sender"]["avatar_url"],
},
"timestamp": dt.datetime.utcnow().isoformat()
}
],
"attachments": [],
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/reindex.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Release"

on:
release:
types:
- released

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v4

- name: "Update release notes"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: python .github/workflow_data/release.py

- name: "Download release assets from tag build"
run: |
set -e
wget "${{ secrets.INDEXER_URL }}"/firmware/${{ github.event.release.tag_name }}/flipper-z-f7-update-${{ github.event.release.tag_name }}.tgz
wget "${{ secrets.INDEXER_URL }}"/firmware/${{ github.event.release.tag_name }}/flipper-z-f7-update-${{ github.event.release.tag_name }}.zip
wget "${{ secrets.INDEXER_URL }}"/firmware/${{ github.event.release.tag_name }}/flipper-z-f7-sdk-${{ github.event.release.tag_name }}.zip
- name: "Update release with assets and notes"
uses: "softprops/action-gh-release@v1"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
body_path: .github/workflow_data/release.md
files: |
flipper-z-f7-update-${{ github.event.release.tag_name }}.tgz
flipper-z-f7-update-${{ github.event.release.tag_name }}.zip
flipper-z-f7-sdk-${{ github.event.release.tag_name }}.zip
- name: "Trigger reindex"
run: |
curl --fail -L -H "Token: ${{ secrets.INDEXER_TOKEN }}" \
"${{ secrets.INDEXER_URL }}"/firmware/reindex;
- name: "Send release notification"
env:
RELEASE_WEBHOOK: ${{ secrets.RELEASE_WEBHOOK }}
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: python .github/workflow_data/webhook.py
3 changes: 0 additions & 3 deletions .github/workflows/webhook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: "Webhook"

on:
push:
release:
types:
- "published"
workflow_run:
workflows:
- "Build"
Expand Down

0 comments on commit ed08b19

Please sign in to comment.