Skip to content

Commit

Permalink
Telegram Push
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiinaSekiu committed Sep 1, 2024
1 parent b7a08be commit 6cb7095
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 3 deletions.
74 changes: 71 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,76 @@ jobs:
name: MiniLPA-${{ env.SHORT_COMMIT_ID }}-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.type }}${{ matrix.wayland && '-Wayland' || '' }}
path: |
build/dist/
release:
name: Release
canary-telegram:
name: Canary(Telegram)
runs-on: macos-latest
needs: [ build-with-zulu, build-with-jbr ]
if: "!startsWith(github.ref, 'refs/tags/v')"
env:
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
steps:
- name: Checkout Scripts
uses: actions/checkout@v4
if: env.TELEGRAM_TOKEN != ''
with:
sparse-checkout: scripts

- name: Setup Python
uses: actions/setup-python@v5
if: env.TELEGRAM_TOKEN != ''
with:
python-version: 'pypy3.10'
cache: 'pip'

- name: Download Artifact
uses: actions/download-artifact@v4
if: env.TELEGRAM_TOKEN != ''
with:
merge-multiple: true
path: artifact

- name: Telegram Push
shell: pwsh
if: env.TELEGRAM_TOKEN != ''
run: |
pip install -r scripts/requirements.txt
python scripts/telegrampush.py -token '${{ secrets.TELEGRAM_TOKEN }}' -target '@MiniLPACanary' -path "$(Get-Location)/artifact/" -message "\[[$($Env:GITHUB_SHA.Substring(0, 7))](${{ github.event.head_commit.url }})\] ${{ github.event.head_commit.message }}”
release-telegram:
name: Release(Telegram)
runs-on: macos-latest
needs: [ build-with-zulu, build-with-jbr ]
if: startsWith(github.ref, 'refs/tags/v')
env:
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
steps:
- name: Checkout Scripts
uses: actions/checkout@v4
if: env.TELEGRAM_TOKEN != ''
with:
sparse-checkout: scripts

- name: Setup Python
uses: actions/setup-python@v5
if: env.TELEGRAM_TOKEN != ''
with:
python-version: 'pypy3.10'
cache: 'pip'

- name: Download Artifact
uses: actions/download-artifact@v4
if: env.TELEGRAM_TOKEN != ''
with:
merge-multiple: true
path: artifact

- name: Telegram Push
shell: pwsh
if: env.TELEGRAM_TOKEN != ''
run: |
pip install -r scripts/requirements.txt
python scripts/telegrampush.py -token '${{ secrets.TELEGRAM_TOKEN }}' -target '@MiniLPA' -path "$(Get-Location)/artifact/" -message "🎉 $("${{ github.ref_name }}".Replace(".", "\.")) Released\! 🎉`n[GitHub Release](https://github.com/EsimMoe/MiniLPA/releases/tag/$("${{ github.ref_name }}".Replace(".", "\.")))”
release-github:
name: Release(GitHub)
runs-on: macos-latest
needs: [ build-with-zulu, build-with-jbr ]
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -116,7 +184,7 @@ jobs:
Get-ChildItem | ForEach-Object { (Get-FileHash $_.FullName -Algorithm SHA256).Hash + ' ' + $_.Name | Out-File -Path $Env:GITHUB_OUTPUT -Append }
'EOF' | Out-File -Path $Env:GITHUB_OUTPUT -Append
- name: Release
- name: GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
Expand Down
Binary file added scripts/requirements.txt
Binary file not shown.
35 changes: 35 additions & 0 deletions scripts/telegrampush.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import asyncio
import os
import argparse
import telegram

async def main():
parser = argparse.ArgumentParser()
parser.add_argument('-token', required=True)
parser.add_argument('-target', required=True)
parser.add_argument('-path', required=True)
parser.add_argument('-message', required=True)
args = parser.parse_args()
bot = telegram.Bot(args.token, base_url='https://tg.git.llc/bot')
async with bot:
file_paths = []
for root, dirs, files in os.walk(args.path):
for file_name in files:
file_path = os.path.join(root, file_name)
file_paths.append(file_path)
async def filter_and_send(check, message = None):
medias = list(map(lambda path: telegram.InputMediaDocument(media=open(path, 'rb')), filter(check, file_paths)))
if medias:
if message: medias[-1] = telegram.InputMediaDocument(media=medias[-1].media, caption=message)
await bot.send_media_group(chat_id=args.target, media=medias, read_timeout=300, write_timeout=300)

line = telegram.helpers.escape_markdown(text='==========================', version=2)
await bot.send_message(chat_id=args.target, text=f'{line}\n{args.message}', parse_mode=telegram.constants.ParseMode.MARKDOWN_V2, read_timeout=300, write_timeout=300)
await filter_and_send(lambda path: 'Windows' in path, 'Windows')
await filter_and_send(lambda path: 'Linux' in path, 'Linux')
await filter_and_send(lambda path: 'macOS' in path, 'macOS')
await filter_and_send(lambda path: path.endswith('.jar'))
await bot.send_message(chat_id=args.target, text=line, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2, read_timeout=300, write_timeout=300)

if __name__ == '__main__':
asyncio.run(main())

0 comments on commit 6cb7095

Please sign in to comment.