From df133f0a36cc2b27d7b83080946b070f0bde8655 Mon Sep 17 00:00:00 2001 From: XelXen <78258352+XelXen@users.noreply.github.com> Date: Sun, 18 Sep 2022 10:47:24 +0530 Subject: [PATCH] Enable SHA Checking --- .github/checkrun.py | 3 +-- .github/pkg.py | 39 ++++++++++++++++-------------------- .github/sign.py | 4 ++++ .github/tg.py | 4 ++-- .github/workflows/ci.yml | 5 ++++- .github/workflows/tg-bot.yml | 10 +++++---- 6 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 .github/sign.py diff --git a/.github/checkrun.py b/.github/checkrun.py index e04e0f6fa..17dc114ea 100644 --- a/.github/checkrun.py +++ b/.github/checkrun.py @@ -13,5 +13,4 @@ if "\n\n" in message: else: print("Silence not found") else: - print("Empty Description") - + print("Empty Description") \ No newline at end of file diff --git a/.github/pkg.py b/.github/pkg.py index b52625542..f40440d9d 100644 --- a/.github/pkg.py +++ b/.github/pkg.py @@ -1,29 +1,24 @@ import os +from json import load +data = load(open('commit.json')) while True: - os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-x86-debug.apk --output app-x86-debug.apk") - outputStr = open("app-x86-debug.apk","r").read() - if "Not Found" not in outputStr: - print("Build [x86] Downloaded") + os.system('curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/sign.txt --output sign.txt') + f = open('sign.txt') + if f == data['sha'][0:7]: break -while True: - os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-x86_64-debug.apk --output app-x86_64-debug.apk") - outputStr = open("app-x86_64-debug.apk","r").read() - if "Not Found" not in outputStr: - print("Build [x86_64] Downloaded") - break +os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-x86-debug.apk --output app-x86-debug.apk") +print("Build [x86] Downloaded") -while True: - os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-armeabi-v7a-debug.apk --output app-armeabi-v7a-debug.apk") - outputStr = open("app-armeabi-v7a-debug.apk","r").read() - if "Not Found" not in outputStr: - print("Build [arm7] Downloaded") - break +os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-x86_64-debug.apk --output app-x86_64-debug.apk") +print("Build [x86_64] Downloaded") -while True: - os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-armeabi-v8a-debug.apk --output app-armeabi-v8a-debug.apk") - outputStr = open("app-armeabi-v8a-debug.apk","r").read() - if "Not Found" not in outputStr: - print("Build [arm8] Downloaded") - break \ No newline at end of file +os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-armeabi-v7a-debug.apk --output app-armeabi-v7a-debug.apk") +print("Build [arm7] Downloaded") + +os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-armeabi-v8a-debug.apk --output app-armeabi-v8a-debug.apk") +print("Build [arm8] Downloaded") + +os.system("curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/latestBuild/app-universal-debug.apk --output app-armeabi-v8a-debug.apk") +print("Build [universal] Downloaded") \ No newline at end of file diff --git a/.github/sign.py b/.github/sign.py new file mode 100644 index 000000000..9f5d8d311 --- /dev/null +++ b/.github/sign.py @@ -0,0 +1,4 @@ +from json import load + +f = open('sign.txt', "w") +f.write(data['sha'][0:7]) \ No newline at end of file diff --git a/.github/tg.py b/.github/tg.py index dc68d1166..e6dae39d4 100644 --- a/.github/tg.py +++ b/.github/tg.py @@ -6,7 +6,7 @@ from os import system from time import sleep as wait def deploy(): - system(f'~/bot-api --local --api-id={TG_API_ID} --api-hash={TG_API_HASH}') + system(f'./bot-api --local --api-id={TG_API_ID} --api-hash={TG_API_HASH}') def bot(): wait(10) @@ -21,7 +21,7 @@ def bot(): Signed-off-by: {data['commit']['author']['name']} ''', parse_mode=telegram.ParseMode.MARKDOWN) - bot.send_media_group(TG_POST_ID, [telegram.InputMediaDocument(open('app-x86-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-x86_64-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-armeabi-v7a-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-arm64-v8a-debug.apk', 'rb'))]) + bot.send_media_group(TG_POST_ID, [telegram.InputMediaDocument(open('app-x86-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-universal-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-x86_64-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-armeabi-v7a-debug.apk', 'rb')), telegram.InputMediaDocument(open('app-arm64-v8a-debug.apk', 'rb'))]) system('killall -9 python') if __name__ == '__main__': diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9d2d4f35..ae6cb5374 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,8 +25,10 @@ jobs: - name: Check for Execution Orders run: | cd .github + touch sign.txt curl https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} > commit.json python checkrun.py + python sign.py cd .. - name: Set up JDK 11 @@ -53,8 +55,9 @@ jobs: - name: Upload to Archive run: | git clone https://github.com/LibreTubeAlpha/Archive archive - rm -rf archive/*.apk + rm -rf archive/*.apk archive/sign.txt mv app/build/outputs/apk/debug/*.apk archive/ + mv .github/sign.txt archive/ cd archive git add -f * git commit -m "WORKFLOW: ALPHA BUILDS" diff --git a/.github/workflows/tg-bot.yml b/.github/workflows/tg-bot.yml index 1aefcc42f..ce73ad213 100644 --- a/.github/workflows/tg-bot.yml +++ b/.github/workflows/tg-bot.yml @@ -22,22 +22,24 @@ jobs: - name: Check for Execution Orders run: | cd .github + mv checkrun.py ~ + cd ~ curl https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} > commit.json python checkrun.py cd .. - name: Download packages run: | - cd ~ - mv .github/pkg.py . + cd .github python pkg.py + cd .. - name: Telegram Bot continue-on-error: true run: | - cd ~ + cd .github curl https://libre-tube.github.io/images/LibreAlpha.png --output alpha.png - curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/exec --output ~/bot-api + curl https://raw.githubusercontent.com/LibreTubeAlpha/Archive/main/exec --output bot-api chmod 755 ./bot-api echo "TG_TOKEN = '${{ secrets.TG_TOKEN }}'" > tgconfig.py echo "TG_API_ID = '${{ secrets.TG_API_ID }}'" >> tgconfig.py