mihomo-party/scripts/artifact.mjs

159 lines
5.1 KiB
JavaScript
Raw Normal View History

2024-10-15 14:41:07 +08:00
/* eslint-disable @typescript-eslint/explicit-function-return-type */
2024-10-13 16:28:13 +08:00
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()
2024-10-13 19:23:14 +08:00
const message = execSync('git log -1 --pretty=%B').toString().trim()
2024-10-13 16:28:13 +08:00
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 = [
2024-10-16 14:56:30 +08:00
path.join(GITHUB_WORKSPACE, `mihomo-party-macos-${version}-arm64.pkg`),
path.join(GITHUB_WORKSPACE, `mihomo-party-macos-${version}-x64.pkg`)
2024-10-13 16:28:13 +08:00
]
const macos10Files = [
path.join(GITHUB_WORKSPACE, `mihomo-party-catalina-${version}-arm64.pkg`),
path.join(GITHUB_WORKSPACE, `mihomo-party-catalina-${version}-x64.pkg`)
]
2024-10-13 16:28:13 +08:00
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}`
}))
2024-10-13 19:23:14 +08:00
windowsMedia[windowsMedia.length - 1].caption = `#${hash} #Windows10 #Windows11\n${message}`
2024-10-13 16:28:13 +08:00
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}`
}))
2024-10-13 19:23:14 +08:00
windows7Media[windows7Media.length - 1].caption = `#${hash} #Windows7 #Windows8\n${message}`
2024-10-13 16:28:13 +08:00
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}`
}))
2024-10-13 19:23:14 +08:00
linuxMedia[linuxMedia.length - 1].caption = `#${hash} #Linux\n${message}`
2024-10-13 16:28:13 +08:00
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 11+\n${message}`
2024-10-13 16:28:13 +08:00
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))
})
const macos10Media = macos10Files.map((file, index) => ({
type: 'document',
media: `attach://file${index}`
}))
macos10Media[macos10Media.length - 1].caption = `#${hash} #macOS 10.15+\n${message}`
const macos10Form = new FormData()
macos10Form.append('chat_id', CHAT_ID)
macos10Form.append('media', JSON.stringify(macos10Media))
macos10Files.forEach((file, index) => {
macos10Form.append(`file${index}`, fs.createReadStream(file))
})
2024-10-15 14:41:07 +08:00
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
2024-10-13 16:28:13 +08:00
await axios.post(
2024-10-15 14:41:07 +08:00
`http://127.0.0.1:8081/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
2024-10-13 16:28:13 +08:00
windowsForm,
{
headers: windowsForm.getHeaders()
}
)
2024-10-15 14:41:07 +08:00
await sleep(10000)
2024-10-13 16:28:13 +08:00
await axios.post(
2024-10-15 14:41:07 +08:00
`http://127.0.0.1:8081/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
2024-10-13 16:28:13 +08:00
windows7Form,
{
headers: windows7Form.getHeaders()
}
)
2024-10-15 14:41:07 +08:00
await sleep(10000)
2024-10-13 16:28:13 +08:00
await axios.post(
2024-10-15 14:41:07 +08:00
`http://127.0.0.1:8081/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
2024-10-13 16:28:13 +08:00
macosForm,
{
headers: macosForm.getHeaders()
}
)
2024-10-15 14:41:07 +08:00
await sleep(10000)
await axios.post(
`http://127.0.0.1:8081/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
macos10Form,
{
headers: macos10Form.getHeaders()
}
)
await sleep(10000)
2024-10-13 16:28:13 +08:00
await axios.post(
2024-10-15 14:41:07 +08:00
`http://127.0.0.1:8081/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMediaGroup`,
2024-10-13 16:28:13 +08:00
linuxForm,
{
headers: linuxForm.getHeaders()
}
)