Skip to content

Commit

Permalink
Test action 10
Browse files Browse the repository at this point in the history
  • Loading branch information
chen08209 committed Oct 14, 2024
1 parent 56fe039 commit e9e8d9b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
26 changes: 3 additions & 23 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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, '+') }}
Expand Down
42 changes: 42 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit e9e8d9b

Please sign in to comment.