Skip to content

Commit

Permalink
PostBot: Fetch rom version dynamically from repo instead of hardcodin…
Browse files Browse the repository at this point in the history
…g in variable [skip ci]

Change-Id: I2f808bc687561036d5d8f9e1ba4775fe724d54bc
Signed-off-by: PrajjuS <theprajjus@gmail.com>
  • Loading branch information
PrajjuS committed Sep 24, 2024
1 parent 28efbc4 commit 660c25b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 19 additions & 1 deletion .github/scripts/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import re
import telebot
import os
import json
import datetime
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):
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/post-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: |
Expand Down

0 comments on commit 660c25b

Please sign in to comment.