scripts: setup ksunextbot

This commit is contained in:
Rifat Azad
2025-01-19 14:23:08 +06:00
parent 2c17a5f4f3
commit f60eed24e8
9 changed files with 57 additions and 23 deletions

View File

@@ -51,7 +51,7 @@ build_from_image() {
echo "[+] Images to upload"
find . -type f -name "*.gz"
# find . -type f -name "*.gz" -exec python3 "$GITHUB_WORKSPACE"/KernelSU-Next/scripts/ksubot.py {} +
# find . -type f -name "*.gz" -exec python3 "$GITHUB_WORKSPACE"/KernelSU-Next/scripts/ksunextbot.py {} +
}
for dir in Image*; do

View File

@@ -30,7 +30,7 @@ build_from_image() {
echo '[+] Images to upload'
find . -type f -name "*.gz"
# find . -type f -name "*.gz" -exec python3 "$GITHUB_WORKSPACE"/KernelSU-Next/scripts/ksubot.py {} +
# find . -type f -name "*.gz" -exec python3 "$GITHUB_WORKSPACE"/KernelSU-Next/scripts/ksunextbot.py {} +
}
for dir in Image*; do

View File

@@ -82,7 +82,7 @@ jobs:
uses: actions/cache@v4
if: false
with:
path: scripts/ksubot.session
path: scripts/ksunextbot.session
key: ${{ runner.os }}-bot-session
- name: Build boot images

View File

@@ -106,7 +106,7 @@ jobs:
uses: actions/cache@v4
if: false
with:
path: scripts/ksubot.session
path: scripts/ksunextbot.session
key: ${{ runner.os }}-bot-session
- name: Build boot images

View File

@@ -118,7 +118,7 @@ jobs:
uses: actions/cache@v4
if: false
with:
path: scripts/ksubot.session
path: scripts/ksunextbot.session
key: ${{ runner.os }}-bot-session
- name: Build boot images

View File

@@ -91,7 +91,7 @@ jobs:
uses: actions/cache@v4
if: false
with:
path: scripts/ksubot.session
path: scripts/ksunextbot.session
key: ${{ runner.os }}-bot-session
- name: Build boot images

View File

@@ -71,6 +71,15 @@ jobs:
with:
fetch-depth: 0
- name: Setup need_upload
id: need_upload
run: |
if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then
echo "UPLOAD=true" >> $GITHUB_OUTPUT
else
echo "UPLOAD=false" >> $GITHUB_OUTPUT
fi
- name: Write key
run: |
if [ ! -z "${{ secrets.KEYSTORE }}" ]; then
@@ -150,3 +159,32 @@ jobs:
with:
name: "mappings"
path: "manager/app/build/outputs/mapping/release/"
- name: Bot session cache
if: steps.need_upload.outputs.UPLOAD == 'true'
id: bot_session_cache
uses: actions/cache@v4
with:
path: scripts/ksunextbot.session
key: ${{ runner.os }}-bot-session
- name: Upload to telegram
if: steps.need_upload.outputs.UPLOAD == 'true'
env:
API_ID: ${{ secrets.API_ID }}
API_HASH: ${{ secrets.API_HASH }}
CHAT_ID: ${{ secrets.CHAT_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
MESSAGE_THREAD_ID: ${{ secrets.MESSAGE_THREAD_ID }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
COMMIT_URL: ${{ github.event.head_commit.url }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
TITLE: Nightly Manager (CI BUILD)
run: |
if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then
export VERSION=$(git rev-list --count HEAD)
APK=$(find ./app/build/outputs/apk/release -name "*.apk")
pip3 install telethon
python3 $GITHUB_WORKSPACE/scripts/ksunextbot.py $APK
fi

View File

@@ -5,7 +5,7 @@ on:
paths:
- '.github/workflows/build-su.yml'
- 'userspace/su/**'
- 'scripts/ksubot.py'
- 'scripts/ksunextbot.py'
pull_request:
branches: [ "next" ]
paths:

View File

@@ -4,13 +4,11 @@ import sys
from telethon import TelegramClient
from telethon.tl.functions.help import GetConfigRequest
API_ID = 611335
API_HASH = "d524b414d21f4d37f08684c1df41ac9c"
# Environment Variables
API_ID = os.environ.get("API_ID")
API_HASH = os.environ.get("API_HASH")
BOT_TOKEN = os.environ.get("BOT_TOKEN")
CHAT_ID = os.environ.get("CHAT_ID")
MESSAGE_THREAD_ID = os.environ.get("MESSAGE_THREAD_ID")
COMMIT_URL = os.environ.get("COMMIT_URL")
COMMIT_MESSAGE = os.environ.get("COMMIT_MESSAGE")
RUN_URL = os.environ.get("RUN_URL")
@@ -41,15 +39,13 @@ def get_caption():
def check_environ():
global CHAT_ID, MESSAGE_THREAD_ID
global CHAT_ID
if BOT_TOKEN is None:
print("[-] Invalid BOT_TOKEN")
exit(1)
if CHAT_ID is None:
print("[-] Invalid CHAT_ID")
exit(1)
else:
CHAT_ID = int(CHAT_ID)
if COMMIT_URL is None:
print("[-] Invalid COMMIT_URL")
exit(1)
@@ -65,15 +61,10 @@ def check_environ():
if VERSION is None:
print("[-] Invalid VERSION")
exit(1)
if MESSAGE_THREAD_ID is None:
print("[-] Invaild MESSAGE_THREAD_ID")
exit(1)
else:
MESSAGE_THREAD_ID = int(MESSAGE_THREAD_ID)
async def main():
print("[+] Uploading to telegram")
print("[+] Uploading to Telegram channel")
check_environ()
files = sys.argv[1:]
print("[+] Files:", files)
@@ -82,7 +73,7 @@ async def main():
exit(1)
print("[+] Logging in Telegram with bot")
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
session_dir = os.path.join(script_dir, "ksubot")
session_dir = os.path.join(script_dir, "ksunextbot")
async with await TelegramClient(session=session_dir, api_id=API_ID, api_hash=API_HASH).start(bot_token=BOT_TOKEN) as bot:
caption = [""] * len(files)
caption[-1] = get_caption()
@@ -91,7 +82,12 @@ async def main():
print(caption)
print("---")
print("[+] Sending")
await bot.send_file(entity=CHAT_ID, file=files, caption=caption, reply_to=MESSAGE_THREAD_ID, parse_mode="markdown")
await bot.send_file(
entity=CHAT_ID,
file=files,
caption=caption,
parse_mode="markdown"
)
print("[+] Done!")
if __name__ == "__main__":