From 660c25b78a5d22fe4be7b91e3f9fbc17d3284dd3 Mon Sep 17 00:00:00 2001 From: PrajjuS Date: Tue, 24 Sep 2024 08:57:32 +0530 Subject: [PATCH] PostBot: Fetch rom version dynamically from repo instead of hardcoding in variable [skip ci] Change-Id: I2f808bc687561036d5d8f9e1ba4775fe724d54bc Signed-off-by: PrajjuS --- .github/scripts/post.py | 20 +++++++++++++++++++- .github/workflows/post-bot.yml | 3 +-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/scripts/post.py b/.github/scripts/post.py index c977b38..16a0135 100755 --- a/.github/scripts/post.py +++ b/.github/scripts/post.py @@ -21,6 +21,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, see . +import re import telebot import os import json @@ -28,6 +29,7 @@ from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton from time import sleep from NoobStuffs.libtelegraph import TelegraphHelper +from github import Github # Get configs from workflow secrets def getConfig(config_name: str): @@ -36,11 +38,27 @@ def getConfig(config_name: str): BOT_TOKEN = getConfig("BOT_TOKEN") CHAT_ID = getConfig("CHAT_ID") PRIV_CHAT_ID = getConfig("PRIV_CHAT_ID") - DROID_VERSION_CHECK = getConfig("DROID_VERSION_CHECK") except KeyError: print("Fill all the configs plox..\nExiting...") exit(0) +# Get the version of DroidX UI to check for updates +def getDroidXUIVersion(): + VENDOR_REPO = "DroidX-UI/vendor_droidx" + VERSION_PATH = "config/version.mk" + VERSION_MAJOR_REGEX = r"PRODUCT_VERSION_MAJOR = (.+)" + VERSION_MINOR_REGEX = r"PRODUCT_VERSION_MINOR = (.+)" + g = Github(getConfig("GH_TOKEN")) + repo = g.get_repo(VENDOR_REPO) + content = repo.get_contents(VERSION_PATH).decoded_content.decode() + major_version = re.search(VERSION_MAJOR_REGEX, content) + minor_version = re.search(VERSION_MINOR_REGEX, content) + major = major_version.group(1) if major_version else None + minor = minor_version.group(1) if minor_version else None + return f"{major}.{minor}" if major and minor else None + +DROID_VERSION_CHECK = getDroidXUIVersion() + BANNER_PATH = "./banners/latest.png" # Init bot diff --git a/.github/workflows/post-bot.yml b/.github/workflows/post-bot.yml index b39f3e3..d1c76b2 100755 --- a/.github/workflows/post-bot.yml +++ b/.github/workflows/post-bot.yml @@ -14,7 +14,6 @@ env: BOT_TOKEN: ${{ secrets.BOT_TOKEN }} CHAT_ID: ${{ secrets.CHAT_ID }} PRIV_CHAT_ID: ${{ secrets.PRIV_CHAT_ID }} - DROID_VERSION_CHECK: ${{ secrets.DROID_VERSION_CHECK }} jobs: post: @@ -24,7 +23,7 @@ jobs: - uses: actions/checkout@v3 - name: Install Dependencies - run: sudo pip install pyTelegramBotAPI noobstuffs + run: sudo pip install pyTelegramBotAPI noobstuffs PyGithub - name: Set Git Configs & Secrets run: |