diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 5a013c4d..85087cff 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -459,7 +459,13 @@ jobs: notify-telegram: name: Notify Telegram runs-on: ubuntu-latest - needs: [update_tag, autobuild-x86-windows-macos-linux, autobuild-arm-linux, autobuild-x86-arm-windows_webview2] + needs: + [ + update_tag, + autobuild-x86-windows-macos-linux, + autobuild-arm-linux, + autobuild-x86-arm-windows_webview2, + ] steps: - name: Checkout repository uses: actions/checkout@v4 diff --git a/scripts/release-version.mjs b/scripts/release-version.mjs index a628aaaf..32e12f37 100644 --- a/scripts/release-version.mjs +++ b/scripts/release-version.mjs @@ -53,7 +53,9 @@ function getGitShortCommit() { */ function getLatestTauriCommit() { try { - const fullHash = execSync("bash ./scripts-workflow/get_latest_tauri_commit.bash") + const fullHash = execSync( + "bash ./scripts-workflow/get_latest_tauri_commit.bash", + ) .toString() .trim(); return execSync(`git rev-parse --short ${fullHash}`).toString().trim(); diff --git a/scripts/telegram.mjs b/scripts/telegram.mjs index 2e384e8b..1e84a7e7 100644 --- a/scripts/telegram.mjs +++ b/scripts/telegram.mjs @@ -2,22 +2,27 @@ import axios from "axios"; import { readFileSync } from "fs"; import { log_success, log_error, log_info } from "./utils.mjs"; -const CHAT_ID_RELEASE = "@clash_verge_re"; // 正式发布频道 -const CHAT_ID_TEST = "@vergetest"; // 测试频道 +const CHAT_ID_RELEASE = "@clash_verge_re"; // 正式发布频道 +const CHAT_ID_TEST = "@vergetest"; // 测试频道 async function sendTelegramNotification() { if (!process.env.TELEGRAM_BOT_TOKEN) { throw new Error("TELEGRAM_BOT_TOKEN is required"); } - const version = process.env.VERSION || (() => { - const pkg = readFileSync("package.json", "utf-8"); - return JSON.parse(pkg).version; - })(); + const version = + process.env.VERSION || + (() => { + const pkg = readFileSync("package.json", "utf-8"); + return JSON.parse(pkg).version; + })(); - const downloadUrl = process.env.DOWNLOAD_URL || `https://github.com/clash-verge-rev/clash-verge-rev/releases/download/v${version}`; + const downloadUrl = + process.env.DOWNLOAD_URL || + `https://github.com/clash-verge-rev/clash-verge-rev/releases/download/v${version}`; - const isAutobuild = process.env.BUILD_TYPE === "autobuild" || version.includes("autobuild"); + const isAutobuild = + process.env.BUILD_TYPE === "autobuild" || version.includes("autobuild"); const chatId = isAutobuild ? CHAT_ID_TEST : CHAT_ID_RELEASE; const buildType = isAutobuild ? "滚动更新版" : "正式版"; @@ -39,7 +44,7 @@ async function sendTelegramNotification() { function convertMarkdownToTelegramHTML(content) { return content .split("\n") - .map(line => { + .map((line) => { if (line.trim().length === 0) { return ""; } else if (line.startsWith("## ")) { @@ -49,8 +54,14 @@ async function sendTelegramNotification() { } else if (line.startsWith("#### ")) { return `${line.replace("#### ", "")}`; } else { - let processedLine = line.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); - processedLine = processedLine.replace(/\*\*([^*]+)\*\*/g, '$1'); + let processedLine = line.replace( + /\[([^\]]+)\]\(([^)]+)\)/g, + '$1', + ); + processedLine = processedLine.replace( + /\*\*([^*]+)\*\*/g, + "$1", + ); return processedLine; } }) @@ -64,19 +75,25 @@ async function sendTelegramNotification() { // 发送到 Telegram try { - await axios.post(`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`, { - chat_id: chatId, - text: content, - link_preview_options: { - is_disabled: false, - url: `https://github.com/clash-verge-rev/clash-verge-rev/releases/tag/v${version}`, - prefer_large_media: true, + await axios.post( + `https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`, + { + chat_id: chatId, + text: content, + link_preview_options: { + is_disabled: false, + url: `https://github.com/clash-verge-rev/clash-verge-rev/releases/tag/v${version}`, + prefer_large_media: true, + }, + parse_mode: "HTML", }, - parse_mode: "HTML", - }); + ); log_success(`✅ Telegram 通知发送成功到 ${chatId}`); } catch (error) { - log_error(`❌ Telegram 通知发送失败到 ${chatId}:`, error.response?.data || error.message); + log_error( + `❌ Telegram 通知发送失败到 ${chatId}:`, + error.response?.data || error.message, + ); process.exit(1); } }