From acd6f44c7efff3aec28024fc271d2d3b925f3c88 Mon Sep 17 00:00:00 2001 From: Ylarod Date: Thu, 12 Jan 2023 09:21:01 +0800 Subject: [PATCH] ci: update message hint (#44) --- .github/workflows/build-kernel-5.10.yml | 10 +++++---- .github/workflows/build-kernel-5.15.yml | 4 +++- .github/workflows/build-su.yml | 3 +++ scripts/ksubot.py | 28 +++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-kernel-5.10.yml b/.github/workflows/build-kernel-5.10.yml index d188e5d3..3d8be200 100644 --- a/.github/workflows/build-kernel-5.10.yml +++ b/.github/workflows/build-kernel-5.10.yml @@ -110,13 +110,15 @@ jobs: 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: kernel-aarch64-${{ matrix.version }} run: | if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then OUTDIR=android-kernel/out/android12-5.10/dist - IMAGE_GZ=kernel-aarch64-${{ matrix.version }}-Image.gz - BOOT=kernel-aarch64-${{ matrix.version }}-boot.img.zip - BOOT_LZ4=kernel-aarch64-${{ matrix.version }}-boot-lz4.img.zip - BOOT_GZ=kernel-aarch64-${{ matrix.version }}-boot-gz.img.zip + IMAGE_GZ=${{ matrix.version }}-Image.gz + BOOT=${{ matrix.version }}-boot.img.zip + BOOT_LZ4=${{ matrix.version }}-boot-lz4.img.zip + BOOT_GZ=${{ matrix.version }}-boot-gz.img.zip mv $OUTDIR/Image.gz $IMAGE_GZ zip $BOOT -j -r $OUTDIR/boot.img zip $BOOT_LZ4 -j -r $OUTDIR/boot-gz.img diff --git a/.github/workflows/build-kernel-5.15.yml b/.github/workflows/build-kernel-5.15.yml index 2eefc6b9..7cb53c49 100644 --- a/.github/workflows/build-kernel-5.15.yml +++ b/.github/workflows/build-kernel-5.15.yml @@ -64,10 +64,12 @@ jobs: 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: kernel-aarch64-${{ matrix.version }} run: | if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then OUTDIR=android-kernel/out/android13-5.15/dist - BOOT=kernel-aarch64-${{ matrix.version }}-boot.img.zip + BOOT=${{ matrix.version }}-boot.img.zip zip $BOOT -j -r $OUTDIR/boot.img pip3 install python-telegram-bot python3 $GITHUB_WORKSPACE/KernelSU/scripts/ksubot.py $BOOT diff --git a/.github/workflows/build-su.yml b/.github/workflows/build-su.yml index c063989e..39757f9a 100644 --- a/.github/workflows/build-su.yml +++ b/.github/workflows/build-su.yml @@ -5,6 +5,7 @@ on: paths: - '.github/workflows/build-su.yml' - 'userspace/**' + - 'scripts/ksubot.py' pull_request: branches: [ "main" ] paths: @@ -35,6 +36,8 @@ jobs: 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: SU run: | if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then pip3 install python-telegram-bot diff --git a/scripts/ksubot.py b/scripts/ksubot.py index 69116691..099ff73a 100644 --- a/scripts/ksubot.py +++ b/scripts/ksubot.py @@ -2,6 +2,7 @@ import os import sys import asyncio import telegram +from telegram import helpers BOT_TOKEN = os.environ.get("BOT_TOKEN") @@ -10,10 +11,25 @@ CACHE_CHAT_ID = os.environ.get("CACHE_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") +TITLE = os.environ.get("TITLE") +MSG_TEMPLATE = """ +*{title}* +``` +{commit_message} +``` +[Commit]({commit_url}) +[Workflow run]({run_url}) +""".strip() def get_caption(): - msg = COMMIT_MESSAGE + "\n" + COMMIT_URL + msg = MSG_TEMPLATE.format( + title=helpers.escape_markdown(TITLE, 2), + commit_message=helpers.escape_markdown(COMMIT_MESSAGE, 2, telegram.MessageEntity.PRE), + commit_url=helpers.escape_markdown(COMMIT_URL, 2, telegram.MessageEntity.TEXT_LINK), + run_url=helpers.escape_markdown(RUN_URL, 2, telegram.MessageEntity.TEXT_LINK) + ) if len(msg) > telegram.constants.MessageLimit.CAPTION_LENGTH: return COMMIT_URL return msg @@ -35,6 +51,12 @@ def check_environ(): if COMMIT_MESSAGE is None: print("[-] Invalid COMMIT_MESSAGE") exit(1) + if RUN_URL is None: + print("[-] Invalid RUN_URL") + exit(1) + if TITLE is None: + print("[-] Invalid TITLE") + exit(1) async def main(): @@ -56,7 +78,9 @@ async def main(): print("[+] Upload: " + one) msg = await bot.send_document(CACHE_CHAT_ID, one) if one == paths[-1]: - files.append(telegram.InputMediaDocument(msg.document, caption=caption)) + files.append(telegram.InputMediaDocument(msg.document, + caption=caption, + parse_mode=telegram.constants.ParseMode.MARKDOWN_V2)) else: files.append(telegram.InputMediaDocument(msg.document)) await bot.delete_message(CACHE_CHAT_ID, msg.message_id)