Skip to content

Commit

Permalink
update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
twnesss committed Nov 9, 2023
1 parent 2f27c5b commit a921d01
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# These are supported funding model platforms

github: ['taamarin']
custom: ['https://sociabuzz.com/taamarin/tribe', 'https://saweria.co/taamarin']
custom: ['https://sociabuzz.com/taamarin', 'https://saweria.co/taamarin']
76 changes: 76 additions & 0 deletions .github/taamarinbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import asyncio
import os
import sys
from telethon import TelegramClient
from telethon.tl.functions.help import GetConfigRequest

API_ID = os.environ.get("API_ID")
API_HASH = os.environ.get("API_HASH")

BOT_TOKEN = os.environ.get("BOT_TOKEN")
CHAT_ID = int(os.environ.get("CHAT_ID"))
MESSAGE_THREAD_ID = int(os.environ.get("MESSAGE_THREAD_ID"))
VERSION = os.environ.get("VERSION")
COMMIT = os.environ.get("COMMIT")
MSG_TEMPLATE = """
{version}
{commit}
[Github](https://github.com/taamarin/box_for_root)
[Releases](https://github.com/taamarin/box_for_magisk/releases)
#module #ksu #magisk #bfr #debug
""".strip()

def get_caption():
msg = MSG_TEMPLATE.format(
version=VERSION,
commit=COMMIT
)
if len(msg) > 1024:
return COMMIT
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 VERSION is None:
print("[-] Invalid VERSION")
exit(1)
if COMMIT is None:
print("[-] Invalid COMMIT")
exit(1)

async def main():
print("[+] Uploading to telegram")
check_environ()
files = sys.argv[1:]
print("[+] Files:", files)
if len(files) <= 0:
print("[-] No files to upload")
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, "bot.session")
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()
print("[+] Caption: ")
print("---")
print(caption)
print("---")
print("[+] Sending")
await bot.send_file(entity=CHAT_ID, file=files, caption=caption, reply_to=MESSAGE_THREAD_ID, parse_mode="markdown")
print("[+] Done!")

if __name__ == "__main__":
try:
asyncio.run(main())
except Exception as e:
print(f"[-] An error occurred: {e}")

30 changes: 15 additions & 15 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.0
with:
fetch-depth: 0

Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.0
with:
fetch-depth: 0

Expand All @@ -69,19 +69,19 @@ jobs:
sed -i "s/versionCode=.*/versionCode=${{ steps.get_tags.outputs.versionCode }}/g" module.prop
sh build.sh
- name: Upload to telegram
- name: upload to telegram
if: ${{ success() }}
env:
CHAT_ID: ${{ secrets.CHAT_ID }}
CACHE_CHAT_ID: ${{ secrets.CACHE_CHAT_ID }}
CHAT_ID: "-1001597117128"
MESSAGE_THREAD_ID: "218356"
API_ID: ${{ secrets.API_ID }}
API_HASH: ${{ secrets.API_HASH }}
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: box for root ${{ steps.get_tags.outputs.tag }}_${{ steps.get_tags.outputs.version }}_debug
run: |
export VERSION=${{ steps.get_tags.outputs.tag }}_${{ steps.get_tags.outputs.version }}
export CG=$(git log --oneline -n 5)
FILE=$(find ./*.zip -type f)
pip3 install python-telegram-bot
python3 docs/tubot.py $FILE
if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then
export VERSION=${{ steps.get_tags.outputs.tag }}_${{ steps.get_tags.outputs.version }}
export COMMIT=$(git log --oneline -n 10 --no-decorate | sed 's/^[0-9a-f]* //' | sed 's/^/— /')
FILE=$(find -name "*.zip")
pip3 install telethon==1.31.1
python3 $GITHUB_WORKSPACE/.github/taamarinbot.py $FILE
fi
27 changes: 14 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4.1.0
- name: Get Version
id: get_version
run: |
Expand Down Expand Up @@ -51,18 +51,19 @@ jobs:
files: box_for_root-v*.zip
generate_release_notes: true

- name: Upload to telegram
- name: upload to telegram
if: ${{ success() }}
env:
CHAT_ID: ${{ secrets.CHAT_ID }}
CACHE_CHAT_ID: ${{ secrets.CACHE_CHAT_ID }}
CHAT_ID: "-1001597117128"
MESSAGE_THREAD_ID: "218356"
API_ID: ${{ secrets.API_ID }}
API_HASH: ${{ secrets.API_HASH }}
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: ${{ github.event.inputs.tag }}
run: |
export VERSION=$(git rev-parse --short HEAD)
FILE=$(find ./box_for_root-v* -type f)
pip3 install python-telegram-bot
python3 docs/tubot.py $FILE
if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then
export VERSION=$(git rev-parse --short HEAD)
export COMMIT=$(git log --oneline -n 10 --no-decorate | sed 's/^[0-9a-f]* //' | sed 's/^/— /')
FILE=$(find -name "*.zip")
pip3 install telethon==1.31.1
python3 $GITHUB_WORKSPACE/.github/taamarinbot.py $FILE
fi
108 changes: 0 additions & 108 deletions docs/tubot.py

This file was deleted.

0 comments on commit a921d01

Please sign in to comment.