支持推送包到telegram

pull/1336/head
HalfLife 3 years ago
parent 60006e170a
commit 53c55963df
  1. 47
      .github/scripts/tg_bot.py
  2. 51
      .github/workflows/test.yml

@ -0,0 +1,47 @@
import os, sys, telebot
# 上传文件
def upload_file(tb, chat_id, file_dir):
doc = open(file_dir, 'rb')
tb.send_document(chat_id, doc)
# 上传文件夹内的文件
def upload_folder(tb, chat_id, folder_dir):
file_list = os.listdir(folder_dir)
for file in file_list:
path = os.path.join(folder_dir, file)
if os.path.isfile(path):
upload_file(tb, chat_id, path)
else:
upload_folder(tb, chat_id, path)
# 上传
def upload(tb, chat_id, dir):
if tb is None:
log('ERROR: 输入正确的token')
return
if chat_id is None:
log('ERROR: 输入正确的chat_id')
return
if dir is None:
log('ERROR: 请指定上传的文件路径')
return
if os.path.isfile(dir):
upload_file(tb, chat_id, dir)
else:
upload_folder(tb, chat_id, dir)
if __name__ == '__main__':
argv = sys.argv[1:]
if len(argv) != 3:
log('ERROR: 参数错误,请以这种格式重新尝试\npython tg_bot.py $token $chat_id 待上传的路径')
# Token
TOKEN = argv[0]
# chat_id
chat_id = argv[1]
# 待上传文件的路径
upload_path = argv[2]
#创建连接
tb = telebot.TeleBot(TOKEN)
#开始上传
upload(tb, chat_id, upload_path)

@ -4,18 +4,29 @@ on:
push:
branches:
- master
workflow_dispatch:
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-ver.outputs.version }}
versionL: ${{ steps.set-ver.outputs.versionL }}
lanzou: ${{ steps.check.outputs.lanzou }}
telegram: ${{ steps.check.outputs.telegram }}
steps:
- id: set-ver
run: |
echo "::set-output name=version::$(date -d "8 hour" -u +3.%y.%m%d%H)"
echo "::set-output name=versionL::$(date -d "8 hour" -u +3.%y.%m%d%H%M)"
- id: check
run: |
if [ ${{ secrets.LANZOU_ID }} ]; then
echo "::set-output name=lanzou::yes"
fi
if [ ${{ secrets.BOT_TOKEN }} ]; then
echo "::set-output name=telegram::yes"
fi
build:
needs: prepare
@ -24,7 +35,6 @@ jobs:
product: [app, google]
type: [release, releaseA]
fail-fast: false
runs-on: ubuntu-latest
env:
product: ${{ matrix.product }}
@ -56,6 +66,7 @@ jobs:
sed '$a\RELEASE_STORE_PASSWORD=gedoor_legado' $GITHUB_WORKSPACE/gradle.properties -i
sed '$a\RELEASE_KEY_PASSWORD=gedoor_legado' $GITHUB_WORKSPACE/gradle.properties -i
- name: Build With Gradle
continue-on-error: true
run: |
if [ ${{ env.type }} == 'release' ]; then
typeName="原包名"
@ -81,7 +92,8 @@ jobs:
path: ${{ github.workspace }}/apk/*.apk
lanzou:
needs: build
needs: [prepare, build]
if: ${{ needs.prepare.outputs.lanzou }}
runs-on: ubuntu-latest
env:
# 登录蓝奏云后在控制台运行document.cookie
@ -97,14 +109,13 @@ jobs:
- working-directory: apk/
run: mv */*.apk . ;rm -rf */
- name: Upload To Lanzou
if: ${{ env.ylogin }}
run: |
path="$GITHUB_WORKSPACE/apk/"
python3 $GITHUB_WORKSPACE/.github/scripts/lzy_web.py "$path" "$LANZOU_FOLDER_ID"
echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: https://kunfei.lanzoux.com/b0f810h4b"
jsdelivr:
needs: [prepare,build]
test_Branch:
needs: [prepare, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@ -115,7 +126,7 @@ jobs:
run: mv */*.apk . ;rm -rf */
- name: Push To "test" Branch
run: |
cd $GITHUB_WORKSPACE/apk || exit 1
cd $GITHUB_WORKSPACE/apk
git init
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
@ -124,11 +135,23 @@ jobs:
git commit -m "${{ needs.prepare.outputs.versionL }}"
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f -u origin test
- name: Purge jsdelivr cache
telegram:
needs: [prepare, build]
if: ${{ needs.prepare.outputs.telegram }}
runs-on: ubuntu-latest
env:
CHANNEL_ID: ${{ secrets.CHANNEL_ID }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
path: apk/
- working-directory: apk/
run: mv */*.apk . ;rm -rf */
- name: Post to channel
run: |
result=$(curl -s https://purge.jsdelivr.net/gh/${{ github.repository }}@test/)
if echo $result |grep -q 'success.*true'; then
echo "jsdelivr缓存更新成功"
else
echo $result
fi
pip install pyTelegramBotAPI
path="$GITHUB_WORKSPACE/apk/"
python3 $GITHUB_WORKSPACE/.github/scripts/tg_bot.py "$BOT_TOKEN" "$CHANNEL_ID" "$path"

Loading…
Cancel
Save