try to send file

This commit is contained in:
pompurin404 2024-10-13 16:28:13 +08:00
parent 36261a6211
commit e0af19583c
No known key found for this signature in database
5 changed files with 155 additions and 6 deletions

View File

@ -220,6 +220,31 @@ jobs:
body_path: changelog.md
token: ${{ secrets.GITHUB_TOKEN }}
artifact:
if: startsWith(github.ref, 'refs/heads/')
needs: [windows, macos, linux, windows7]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
run: npm install -g pnpm
- name: Install Dependencies
run: pnpm install
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Telegram Bot Server
uses: zjns/telegram-bot-server@v1
with:
api_id: ${{ secrets.TELEGRAM_BOT_API_ID }}
api_hash: ${{ secrets.TELEGRAM_BOT_API_HASH }}
- name: Upload Artifacts
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
run: pnpm artifact
updater:
if: startsWith(github.ref, 'refs/tags/v')
needs: [windows, macos, windows7]

View File

@ -15,6 +15,7 @@
"updater": "node scripts/updater.mjs",
"checksum": "node scripts/checksum.mjs",
"telegram": "node scripts/telegram.mjs",
"artifact": "node scripts/artifact.mjs",
"dev": "electron-vite dev",
"postinstall": "electron-builder install-app-deps",
"build:win": "electron-vite build && electron-builder --publish never --win",
@ -59,6 +60,7 @@
"electron-window-state": "^5.0.3",
"eslint": "^8.57.1",
"eslint-plugin-react": "^7.37.1",
"form-data": "^4.0.1",
"framer-motion": "^11.9.0",
"lodash": "^4.17.21",
"meta-json-schema": "^1.18.9",

View File

@ -114,6 +114,9 @@ importers:
eslint-plugin-react:
specifier: ^7.37.1
version: 7.37.1(eslint@8.57.1)
form-data:
specifier: ^4.0.1
version: 4.0.1
framer-motion:
specifier: ^11.9.0
version: 11.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
@ -3193,8 +3196,8 @@ packages:
resolution: {integrity: sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==}
engines: {node: '>=14'}
form-data@4.0.0:
resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
form-data@4.0.1:
resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==}
engines: {node: '>= 6'}
formdata-polyfill@4.0.10:
@ -8260,7 +8263,7 @@ snapshots:
ejs: 3.1.10
electron-builder-squirrel-windows: 25.0.4(dmg-builder@25.0.4)
electron-publish: 25.0.3
form-data: 4.0.0
form-data: 4.0.1
fs-extra: 10.1.0
hosted-git-info: 4.1.0
is-ci: 3.0.1
@ -8416,7 +8419,7 @@ snapshots:
axios@1.7.7:
dependencies:
follow-redirects: 1.15.9
form-data: 4.0.0
form-data: 4.0.1
proxy-from-env: 1.1.0
transitivePeerDependencies:
- debug
@ -9445,7 +9448,7 @@ snapshots:
cross-spawn: 7.0.3
signal-exit: 4.1.0
form-data@4.0.0:
form-data@4.0.1:
dependencies:
asynckit: 0.4.0
combined-stream: 1.0.8

119
scripts/artifact.mjs Normal file
View File

@ -0,0 +1,119 @@
import fs from 'fs'
import axios from 'axios'
import path from 'path'
import FormData from 'form-data'
import { execSync } from 'child_process'
const CHAT_ID = '@MihomoPartyCi'
const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE
const pkg = fs.readFileSync('package.json', 'utf-8')
const { version } = JSON.parse(pkg)
const hash = execSync('git rev-parse --short HEAD').toString().trim()
const linuxFiles = [
path.join(GITHUB_WORKSPACE, `mihomo-party-linux-${version}-aarch64.rpm`),
path.join(GITHUB_WORKSPACE, `mihomo-party-linux-${version}-arm64.deb`),
path.join(GITHUB_WORKSPACE, `mihomo-party-linux-${version}-x86_64.rpm`),
path.join(GITHUB_WORKSPACE, `mihomo-party-linux-${version}-amd64.deb`)
]
const macosFiles = [
path.join(GITHUB_WORKSPACE, `mihomo-party-macos-${version}-arm64.dmg`),
path.join(GITHUB_WORKSPACE, `mihomo-party-macos-${version}-x64.dmg`)
]
const windowsFiles = [
path.join(GITHUB_WORKSPACE, `mihomo-party-windows-${version}-x64-setup.exe`),
path.join(GITHUB_WORKSPACE, `mihomo-party-windows-${version}-x64-portable.7z`),
path.join(GITHUB_WORKSPACE, `mihomo-party-windows-${version}-ia32-setup.exe`),
path.join(GITHUB_WORKSPACE, `mihomo-party-windows-${version}-ia32-portable.7z`),
path.join(GITHUB_WORKSPACE, `mihomo-party-windows-${version}-arm64-setup.exe`),
path.join(GITHUB_WORKSPACE, `mihomo-party-windows-${version}-arm64-portable.7z`)
]
const windows7Files = [
path.join(GITHUB_WORKSPACE, `mihomo-party-win7-${version}-x64-setup.exe`),
path.join(GITHUB_WORKSPACE, `mihomo-party-win7-${version}-x64-portable.7z`),
path.join(GITHUB_WORKSPACE, `mihomo-party-win7-${version}-ia32-setup.exe`),
path.join(GITHUB_WORKSPACE, `mihomo-party-win7-${version}-ia32-portable.7z`)
]
const windowsMedia = windowsFiles.map((file, index) => ({
type: 'document',
media: `attach://file${index}`
}))
windowsMedia[windowsMedia.length - 1].caption = `#${hash} #Windows10 #Windows11`
const windowsForm = new FormData()
windowsForm.append('chat_id', CHAT_ID)
windowsForm.append('media', JSON.stringify(windowsMedia))
windowsFiles.forEach((file, index) => {
windowsForm.append(`file${index}`, fs.createReadStream(file))
})
const windows7Media = windows7Files.map((file, index) => ({
type: 'document',
media: `attach://file${index}`
}))
windows7Media[windows7Media.length - 1].caption = `#${hash} #Windows7 #Windows8`
const windows7Form = new FormData()
windows7Form.append('chat_id', CHAT_ID)
windows7Form.append('media', JSON.stringify(windows7Media))
windows7Files.forEach((file, index) => {
windows7Form.append(`file${index}`, fs.createReadStream(file))
})
const linuxMedia = linuxFiles.map((file, index) => ({
type: 'document',
media: `attach://file${index}`
}))
linuxMedia[linuxMedia.length - 1].caption = `#${hash} #Linux`
const linuxForm = new FormData()
linuxForm.append('chat_id', CHAT_ID)
linuxForm.append('media', JSON.stringify(linuxMedia))
linuxFiles.forEach((file, index) => {
linuxForm.append(`file${index}`, fs.createReadStream(file))
})
const macosMedia = macosFiles.map((file, index) => ({
type: 'document',
media: `attach://file${index}`
}))
macosMedia[macosMedia.length - 1].caption = `#${hash} #macOS`
const macosForm = new FormData()
macosForm.append('chat_id', CHAT_ID)
macosForm.append('media', JSON.stringify(macosMedia))
macosFiles.forEach((file, index) => {
macosForm.append(`file${index}`, fs.createReadStream(file))
})
await axios.post(
`http://127.0.0.1:8088/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
windowsForm,
{
headers: windowsForm.getHeaders()
}
)
await axios.post(
`http://127.0.0.1:8088/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
windows7Form,
{
headers: windows7Form.getHeaders()
}
)
await axios.post(
`http://127.0.0.1:8088/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
macosForm,
{
headers: macosForm.getHeaders()
}
)
await axios.post(
`http://127.0.0.1:8088/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
linuxForm,
{
headers: linuxForm.getHeaders()
}
)

View File

@ -1,7 +1,7 @@
import axios from 'axios'
import { readFileSync } from 'fs'
const chat_id = '@mihomo_party_group'
const chat_id = '@MihomoPartyChannel'
const pkg = readFileSync('package.json', 'utf-8')
const changelog = readFileSync('changelog.md', 'utf-8')
const { version } = JSON.parse(pkg)