forked from flipperdevices/flipperzero-firmware
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notification sending (flipperdevices#3449)
Co-authored-by: あく <alleteam@gmail.com>
- Loading branch information
1 parent
88a3b45
commit fcf3b50
Showing
2 changed files
with
66 additions
and
5 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 |
---|---|---|
@@ -1,15 +1,32 @@ | ||
name: 'Reindex' | ||
name: 'Post-release hooks' | ||
|
||
on: | ||
release: | ||
types: [prereleased,released] | ||
types: [prereleased, released] | ||
|
||
jobs: | ||
reindex: | ||
name: 'Reindex updates' | ||
name: 'Post-release hooks' | ||
runs-on: [self-hosted, FlipperZeroShell] | ||
steps: | ||
- name: Trigger reindex | ||
- name: 'Checkout code' | ||
uses: actions/checkout@v4 | ||
|
||
- name: 'Trigger reindex' | ||
run: | | ||
curl --fail -L -H "Token: ${{ secrets.INDEXER_TOKEN }}" \ | ||
"${{ secrets.INDEXER_URL }}"/firmware/reindex | ||
"${{ secrets.INDEXER_URL }}"/firmware/reindex; | ||
- name: 'Send release notification' | ||
if: ${{ github.event.action == 'released' }} | ||
run: | | ||
echo '${{ secrets.FIREBASE_TOKEN }}' > firebase-token.json; | ||
python3 -m pip install firebase-admin==6.4.0; | ||
python3 scripts/send_firebase_notification.py \ | ||
"--version=${{ github.event.release.name }}" \ | ||
"--token=firebase-token.json"; | ||
- name: 'Remove firebase token' | ||
if: always() | ||
run: | | ||
rm -rf firebase-token.json; |
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,44 @@ | ||
import argparse | ||
import logging | ||
from firebase_admin import messaging, credentials, initialize_app | ||
|
||
|
||
class FirebaseNotifications: | ||
def __init__(self, service_account_file): | ||
try: | ||
cred = credentials.Certificate(service_account_file) | ||
self.firebase_app = initialize_app(cred) | ||
except Exception as e: | ||
logging.exception(e) | ||
raise e | ||
|
||
def send(self, title, body, condition): | ||
try: | ||
message = messaging.Message( | ||
notification=messaging.Notification(title=title, body=body), | ||
condition=condition, | ||
) | ||
messaging.send(message, app=self.firebase_app) | ||
except Exception as e: | ||
logging.exception(e) | ||
raise e | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--token_file", help="Firebase token file", required=True) | ||
parser.add_argument( | ||
"--version", help="Firmware version to notify with", required=True | ||
) | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parse_args() | ||
notification = FirebaseNotifications(args.token_file) | ||
notification.send( | ||
title="Firmware Update Available", | ||
body=f"New firmware version is ready to install: {args.version}", | ||
condition="'flipper_update_firmware_release' in topics", | ||
) |