支持推送包到telegram

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

Loading…
Cancel
Save