diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7482c7e7..8e5ffd7a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -163,34 +163,14 @@ jobs: TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} CHAT_ID: "-1002428644828" run: | - DIST_DIR="$(pwd)/dist" - media="[" - i=1 - for file in "$DIST_DIR"/*; do - basename=$(basename "$file") - if [[ $i -eq 1 ]]; then - media="${media}{\"type\": \"document\", \"media\": \"attach://file$i\"}" - else - media="${media}, {\"type\": \"document\", \"media\": \"attach://file$i\"}" - fi - curl_files="$curl_files -F file$i=@$file" - i=$((i+1)) - done - - release_notes=$(cat $(pwd)/release.md) - - media="${media%,*}, {\"type\": \"document\", \"media\": \"attach://file$((i-1))\", \"caption\": \"$release_notes\", \"parse_mode\": \"MarkdownV2\"}]" - - curl -X POST "http://localhost:8081/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMediaGroup" \ - -F "chat_id=${CHAT_ID}" \ - -F "media=$media" \ - $curl_files + python -m pip install --upgrade pip + pip install requests + python release.py - name: Patch release.md run: | version=$(echo "${{ github.ref_name }}" | sed 's/^v//') sed "s|VERSION|$version|g" ./.github/release_template.md >> release.md - - name: Release if: ${{ !contains(github.ref, '+') }} diff --git a/release.py b/release.py new file mode 100644 index 00000000..98114c34 --- /dev/null +++ b/release.py @@ -0,0 +1,42 @@ +import os +import requests + +TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN") + +CHAT_ID = "-1002428644828" +API_URL = f"http://localhost:8081/bot{TELEGRAM_BOT_TOKEN}/sendMediaGroup" + +DIST_DIR = os.path.join(os.getcwd(), "dist") +release_file = os.path.join(os.getcwd(), "release.md") + +media = [] +curl_files = {} + +i = 1 +for file in os.listdir(DIST_DIR): + file_path = os.path.join(DIST_DIR, file) + if os.path.isfile(file_path): + file_key = f"file{i}" + media.append({ + "type": "document", + "media": f"attach://{file_key}" + }) + curl_files[file_key] = open(file_path, 'rb') + i += 1 + +with open(release_file, 'r') as f: + release_notes = f.read() + +if media: + media[-1]["caption"] = release_notes + media[-1]["parse_mode"] = "MarkdownV2" + +# 发送 POST 请求到 Telegram API +response = requests.post( + API_URL, + data={ + "chat_id": CHAT_ID, + "media": json.dumps(media) + }, + files=curl_files +) \ No newline at end of file