diff --git a/.github/runOnRelease.py b/.github/runOnRelease.py new file mode 100644 index 000000000..5b74903dd --- /dev/null +++ b/.github/runOnRelease.py @@ -0,0 +1,64 @@ +from pyrogram import Client +from pyrogram.types import ( + InlineKeyboardButton, + InlineKeyboardMarkup, + InputMediaDocument, +) +from requests import get +from tgconfig import TG_API_HASH, TG_API_ID, TG_CID, TG_TOKEN + +url = "https://api.github.com/repos/Libre-Tube/LibreTube/releases/latest" + +req = get(url).json() + +if TG_CID.isdecimal(): + TG_CID = int(TG_CID) + + +def get_changelog(): + url = "https://api.github.com/repos/libre-tube/LibreTube/contents/fastlane/metadata/android/en-US/changelogs" + data = get(url).json() + last_log = max([int(file["name"].replace(".txt", "")) for file in data]) + log = get( + f"https://github.com/libre-tube/LibreTube/raw/master/fastlane/metadata/android/en-US/changelogs/{last_log}.txt" + ).text + return log + + +def download(url, name): + with open(name, "wb") as f: + f.write(get(url, stream=True).content) + return name + + +buttons = InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton("Release", url=req.get("html_url")), + InlineKeyboardButton( + "F-droid", url="https://www.f-droid.org/packages/com.github.libretube/" + ), + InlineKeyboardButton( + "IzzyOnDroid", + url="https://apt.izzysoft.de/fdroid/index/apk/com.github.libretube", + ), + ] + ] +) + + +_files, files, result, tag = req.get("assets"), [], req.get("body"), req.get("tag_name") +for file in _files: + files.append( + InputMediaDocument(download(file.get("browser_download_url"), file.get("name"))) + ) + +caption = f"**LibreTube {tag} // Privacy Simplified**\n\nWhat's Changed?\n```{get_changelog()}```" +with Client("bot", TG_API_ID, TG_API_HASH, bot_token=TG_TOKEN) as app: + app.send_photo( + TG_CID, + "https://i.ibb.co/LJ9r4hP/LT.jpg", + caption, + reply_markup=buttons, + ) + app.send_media_group(TG_CID, files) diff --git a/.github/workflows/run-on-release.yml b/.github/workflows/run-on-release.yml new file mode 100644 index 000000000..0426ca5e0 --- /dev/null +++ b/.github/workflows/run-on-release.yml @@ -0,0 +1,26 @@ +name: Telegram Release + +on: + release: + types: [published] + +jobs: + debug-builds: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v4 + with: + python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax + architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified + + - name: Upload to Telegram + run: | + git clone https://github.com/${{ github.repository }} && cd LibreTube + echo "TG_API_ID = '${{ secrets.TG_API_ID }}'" >> tgconfig.py + echo "TG_API_HASH = '${{ secrets.TG_API_HASH }}'" >> tgconfig.py + echo "TG_CID = '${{ secrets.TG_CID }}'" >> tgconfig.py + echo "TG_TOKEN = '${{ secrets.TG_TOKEN }}'" >> tgconfig.py + pip install pyrogram TgCrypto requests + mv .github/runOnRelease.py . + python runOnRelease.py +