ci: push to telegram (#43)
* ci: push to telegram * support topic * check BOT_TOKEN in build-su * update script
This commit is contained in:
31
.github/workflows/build-kernel-5.10.yml
vendored
31
.github/workflows/build-kernel-5.10.yml
vendored
@@ -82,22 +82,45 @@ jobs:
|
|||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: kernel-aarch64-${{ matrix.version }}-Image.gz
|
name: kernel-aarch64-${{ matrix.version }}-Image.gz
|
||||||
path: android-kernel/out/*/dist/Image.gz
|
path: android-kernel/out/android12-5.10/dist/Image.gz
|
||||||
|
|
||||||
- name: Upload boot.img
|
- name: Upload boot.img
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: kernel-aarch64-${{ matrix.version }}-boot.img
|
name: kernel-aarch64-${{ matrix.version }}-boot.img
|
||||||
path: android-kernel/out/*/dist/boot.img
|
path: android-kernel/out/android12-5.10/dist/boot.img
|
||||||
|
|
||||||
- name: Upload boot-lz4.img
|
- name: Upload boot-lz4.img
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: kernel-aarch64-${{ matrix.version }}-boot-lz4.img
|
name: kernel-aarch64-${{ matrix.version }}-boot-lz4.img
|
||||||
path: android-kernel/out/*/dist/boot-lz4.img
|
path: android-kernel/out/android12-5.10/dist/boot-lz4.img
|
||||||
|
|
||||||
- name: Upload boot-gz.img
|
- name: Upload boot-gz.img
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: kernel-aarch64-${{ matrix.version }}-boot-gz.img
|
name: kernel-aarch64-${{ matrix.version }}-boot-gz.img
|
||||||
path: android-kernel/out/*/dist/boot-gz.img
|
path: android-kernel/out/android12-5.10/dist/boot-gz.img
|
||||||
|
|
||||||
|
- name: Upload to telegram
|
||||||
|
env:
|
||||||
|
CHAT_ID: ${{ secrets.CHAT_ID }}
|
||||||
|
CACHE_CHAT_ID: ${{ secrets.CACHE_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: |
|
||||||
|
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
|
||||||
|
mv $OUTDIR/Image.gz $IMAGE_GZ
|
||||||
|
zip $BOOT -j -r $OUTDIR/boot.img
|
||||||
|
zip $BOOT_LZ4 -j -r $OUTDIR/boot-gz.img
|
||||||
|
zip $BOOT_GZ -j -r $OUTDIR/boot-lz4.img
|
||||||
|
pip3 install python-telegram-bot
|
||||||
|
python3 $GITHUB_WORKSPACE/KernelSU/scripts/ksubot.py $IMAGE_GZ $BOOT $BOOT_LZ4 $BOOT_GZ
|
||||||
|
fi
|
||||||
19
.github/workflows/build-kernel-5.15.yml
vendored
19
.github/workflows/build-kernel-5.15.yml
vendored
@@ -54,4 +54,21 @@ jobs:
|
|||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: kernel-aarch64-${{ matrix.version }}-boot.img
|
name: kernel-aarch64-${{ matrix.version }}-boot.img
|
||||||
path: android-kernel/out/*/dist/boot.img
|
path: android-kernel/out/*/dist/boot.img
|
||||||
|
|
||||||
|
- name: Upload to telegram
|
||||||
|
env:
|
||||||
|
CHAT_ID: ${{ secrets.CHAT_ID }}
|
||||||
|
CACHE_CHAT_ID: ${{ secrets.CACHE_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: |
|
||||||
|
if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then
|
||||||
|
OUTDIR=android-kernel/out/android13-5.15/dist
|
||||||
|
BOOT=kernel-aarch64-${{ 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
|
||||||
|
fi
|
||||||
15
.github/workflows/build-su.yml
vendored
15
.github/workflows/build-su.yml
vendored
@@ -27,3 +27,18 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: su
|
name: su
|
||||||
path: ./userspace/su/libs
|
path: ./userspace/su/libs
|
||||||
|
- name: Upload to telegram
|
||||||
|
env:
|
||||||
|
CHAT_ID: ${{ secrets.CHAT_ID }}
|
||||||
|
CACHE_CHAT_ID: ${{ secrets.CACHE_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: |
|
||||||
|
if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then
|
||||||
|
pip3 install python-telegram-bot
|
||||||
|
mv ./userspace/su/libs/arm64-v8a/su su-arm64
|
||||||
|
mv ./userspace/su/libs/x86_64/su su-x86_64
|
||||||
|
python3 scripts/ksubot.py su-arm64 su-x86_64
|
||||||
|
fi
|
||||||
|
|||||||
71
scripts/ksubot.py
Normal file
71
scripts/ksubot.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import asyncio
|
||||||
|
import telegram
|
||||||
|
|
||||||
|
|
||||||
|
BOT_TOKEN = os.environ.get("BOT_TOKEN")
|
||||||
|
CHAT_ID = os.environ.get("CHAT_ID")
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
|
def get_caption():
|
||||||
|
msg = COMMIT_MESSAGE + "\n" + COMMIT_URL
|
||||||
|
if len(msg) > telegram.constants.MessageLimit.CAPTION_LENGTH:
|
||||||
|
return COMMIT_URL
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def check_environ():
|
||||||
|
if BOT_TOKEN is None:
|
||||||
|
print("[-] Invalid BOT_TOKEN")
|
||||||
|
exit(1)
|
||||||
|
if CHAT_ID is None:
|
||||||
|
print("[-] Invalid CHAT_ID")
|
||||||
|
exit(1)
|
||||||
|
if CACHE_CHAT_ID is None:
|
||||||
|
print("[-] Invalid CACHE_CHAT_ID")
|
||||||
|
exit(1)
|
||||||
|
if COMMIT_URL is None:
|
||||||
|
print("[-] Invalid COMMIT_URL")
|
||||||
|
exit(1)
|
||||||
|
if COMMIT_MESSAGE is None:
|
||||||
|
print("[-] Invalid COMMIT_MESSAGE")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
print("[+] Uploading to telegram")
|
||||||
|
check_environ()
|
||||||
|
print("[+] Files:", sys.argv[1:])
|
||||||
|
bot = telegram.Bot(BOT_TOKEN)
|
||||||
|
files = []
|
||||||
|
paths = sys.argv[1:]
|
||||||
|
caption = get_caption()
|
||||||
|
print("[+] Caption: ")
|
||||||
|
print("---")
|
||||||
|
print(caption)
|
||||||
|
print("---")
|
||||||
|
for one in paths:
|
||||||
|
if not os.path.exists(one):
|
||||||
|
print("[-] File not exist: " + one)
|
||||||
|
continue
|
||||||
|
print("[+] Upload: " + one)
|
||||||
|
msg = await bot.send_document(CACHE_CHAT_ID, one)
|
||||||
|
if one == paths[-1]:
|
||||||
|
files.append(telegram.InputMediaDocument(msg.document, caption=caption))
|
||||||
|
else:
|
||||||
|
files.append(telegram.InputMediaDocument(msg.document))
|
||||||
|
await bot.delete_message(CACHE_CHAT_ID, msg.message_id)
|
||||||
|
print("[+] Sending")
|
||||||
|
await bot.send_media_group(CHAT_ID, files, message_thread_id=MESSAGE_THREAD_ID)
|
||||||
|
print("[+] Done!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
loops = asyncio.new_event_loop()
|
||||||
|
loops.run_until_complete(asyncio.wait([main()]))
|
||||||
|
|
||||||
Reference in New Issue
Block a user