diff --git a/.github/scripts/build_a12.sh b/.github/scripts/build_a12.sh index 04e09b9f..4f0c0a65 100644 --- a/.github/scripts/build_a12.sh +++ b/.github/scripts/build_a12.sh @@ -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 diff --git a/.github/scripts/build_a13.sh b/.github/scripts/build_a13.sh index 6ef5f18a..32ce875a 100644 --- a/.github/scripts/build_a13.sh +++ b/.github/scripts/build_a13.sh @@ -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 diff --git a/.github/workflows/build-kernel-a12.yml b/.github/workflows/build-kernel-a12.yml index eb9c04f6..4b5483cc 100644 --- a/.github/workflows/build-kernel-a12.yml +++ b/.github/workflows/build-kernel-a12.yml @@ -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 diff --git a/.github/workflows/build-kernel-a13.yml b/.github/workflows/build-kernel-a13.yml index a9c125ca..91e8077e 100644 --- a/.github/workflows/build-kernel-a13.yml +++ b/.github/workflows/build-kernel-a13.yml @@ -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 diff --git a/.github/workflows/build-kernel-a14.yml b/.github/workflows/build-kernel-a14.yml index 7d90c67a..69ac97ba 100644 --- a/.github/workflows/build-kernel-a14.yml +++ b/.github/workflows/build-kernel-a14.yml @@ -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 diff --git a/.github/workflows/build-kernel-a15.yml b/.github/workflows/build-kernel-a15.yml index 891a8840..f4b9f91c 100644 --- a/.github/workflows/build-kernel-a15.yml +++ b/.github/workflows/build-kernel-a15.yml @@ -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 diff --git a/.github/workflows/build-manager.yml b/.github/workflows/build-manager.yml index ee51bed6..d22fc3da 100644 --- a/.github/workflows/build-manager.yml +++ b/.github/workflows/build-manager.yml @@ -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 + diff --git a/.github/workflows/build-su.yml b/.github/workflows/build-su.yml index 25fc2898..ee2b66c5 100644 --- a/.github/workflows/build-su.yml +++ b/.github/workflows/build-su.yml @@ -5,7 +5,7 @@ on: paths: - '.github/workflows/build-su.yml' - 'userspace/su/**' - - 'scripts/ksubot.py' + - 'scripts/ksunextbot.py' pull_request: branches: [ "next" ] paths: diff --git a/scripts/ksubot.py b/scripts/ksunextbot.py similarity index 76% rename from scripts/ksubot.py rename to scripts/ksunextbot.py index c3b36727..0cf3499b 100644 --- a/scripts/ksubot.py +++ b/scripts/ksunextbot.py @@ -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__":