diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index dbef9db..b954017 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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') @@ -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 diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..42b2cc0 Binary files /dev/null and b/scripts/requirements.txt differ diff --git a/scripts/telegrampush.py b/scripts/telegrampush.py new file mode 100644 index 0000000..3f6fb68 --- /dev/null +++ b/scripts/telegrampush.py @@ -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()) \ No newline at end of file