diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 6829c2d7..c7d42f9c 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -53,6 +53,9 @@ jobs: - name: Set Env run: | echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV + VERSION=$(jq -r .version package.json) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "DOWNLOAD_URL=https://github.com/clash-verge-rev/clash-verge-rev/releases/download/autobuild" >> $GITHUB_ENV shell: bash - run: | @@ -66,25 +69,31 @@ jobs: cat > release.txt << EOF $UPDATE_LOGS - ## 我应该下载哪个版本? - - ### MacOS - - MacOS intel芯片: x64.dmg - - MacOS apple M芯片: aarch64.dmg - - ### Linux - - Linux 64位: amd64.deb/amd64.rpm - - Linux arm64 architecture: arm64.deb/aarch64.rpm - - Linux armv7架构: armhf.deb/armhfp.rpm + ## 下载地址 ### Windows (不再支持Win7) #### 正常版本(推荐) - - 64位: x64-setup.exe - - arm64架构: arm64-setup.exe - #### 便携版问题很多不再提供 + - 64位(常用): [clash-verge_${{ env.VERSION }}_x64-setup.exe](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_x64-setup.exe) + - ARM64(不常用): [clash-verge_${{ env.VERSION }}_arm64-setup.exe](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_arm64-setup.exe) + #### 内置Webview2版(体积较大,仅在企业版系统或无法安装webview2时使用) - - 64位: x64_fixed_webview2-setup.exe - - arm64架构: arm64_fixed_webview2-setup.exe + - 64位: [clash-verge_${{ env.VERSION }}_x64_fixed_webview2-setup.exe](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_x64_fixed_webview2-setup.exe) + - ARM64: [clash-verge_${{ env.VERSION }}_arm64_fixed_webview2-setup.exe](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_arm64_fixed_webview2-setup.exe) + + ### macOS + - Apple M芯片: [clash-verge_${{ env.VERSION }}_aarch64.dmg](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_aarch64.dmg) + - Intel芯片: [clash-verge_${{ env.VERSION }}_x64.dmg](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_x64.dmg) + + ### Linux + #### DEB包(Debian系) 使用 apt ./路径 安装 + - 64位: [clash-verge_${{ env.VERSION }}_amd64.deb](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_amd64.deb) + - ARM64: [clash-verge_${{ env.VERSION }}_arm64.deb](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_arm64.deb) + - ARMv7: [clash-verge_${{ env.VERSION }}_armhf.deb](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_armhf.deb) + + #### RPM包(Redhat系) 使用 dnf ./路径 安装 + - 64位: [clash-verge_${{ env.VERSION }}_amd64.rpm](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_amd64.rpm) + - ARM64: [clash-verge_${{ env.VERSION }}_aarch64.rpm](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_aarch64.rpm) + - ARMv7: [clash-verge_${{ env.VERSION }}_armhfp.rpm](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_armhfp.rpm) ### FAQ - [常见问题](https://clash-verge-rev.github.io/faq/windows.html) @@ -437,3 +446,39 @@ jobs: run: pnpm portable-fixed-webview2 ${{ matrix.target }} --${{ env.TAG_NAME }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + notify-telegram: + name: Notify Telegram + runs-on: ubuntu-latest + needs: [autobuild-x86-windows-macos-linux, autobuild-arm-linux, autobuild-x86-arm-windows_webview2] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: "22" + + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + run_install: false + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Get Version and Release Info + run: | + sudo apt-get update + sudo apt-get install jq + echo "VERSION=$(cat package.json | jq '.version' | tr -d '"')" >> $GITHUB_ENV + echo "DOWNLOAD_URL=https://github.com/clash-verge-rev/clash-verge-rev/releases/download/autobuild" >> $GITHUB_ENV + + - name: Send Telegram Notification + run: node scripts/telegram.mjs + env: + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + BUILD_TYPE: autobuild + VERSION: ${{ env.VERSION }} + DOWNLOAD_URL: ${{ env.DOWNLOAD_URL }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e101675c..de658ea4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,9 +40,100 @@ jobs: fi echo "Tag and package.json version are consistent." + update_tag: + name: Update tag + runs-on: ubuntu-latest + needs: check_tag_version + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Fetch UPDATE logs + id: fetch_update_logs + run: | + if [ -f "UPDATELOG.md" ]; then + UPDATE_LOGS=$(awk '/^## v/{if(flag) exit; flag=1} flag' UPDATELOG.md) + if [ -n "$UPDATE_LOGS" ]; then + echo "Found update logs" + echo "UPDATE_LOGS<> $GITHUB_ENV + echo "$UPDATE_LOGS" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + else + echo "No update sections found in UPDATELOG.md" + fi + else + echo "UPDATELOG.md file not found" + fi + shell: bash + + - name: Set Env + run: | + echo "BUILDTIME=$(TZ=Asia/Shanghai date)" >> $GITHUB_ENV + TAG_REF="${GITHUB_REF##*/}" + echo "TAG_NAME=$TAG_REF" >> $GITHUB_ENV + VERSION=$(echo "$TAG_REF" | sed 's/^v//') + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "DOWNLOAD_URL=https://github.com/clash-verge-rev/clash-verge-rev/releases/download/$TAG_REF" >> $GITHUB_ENV + shell: bash + + - run: | + if [ -z "$UPDATE_LOGS" ]; then + echo "No update logs found, using default message" + UPDATE_LOGS="More new features are now supported. Check for detailed changelog soon." + else + echo "Using found update logs" + fi + + cat > release.txt << EOF + $UPDATE_LOGS + + ## 下载地址 + + ### Windows (不再支持Win7) + #### 正常版本(推荐) + - 64位(常用): [clash-verge_${{ env.VERSION }}_x64-setup.exe](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_x64-setup.exe) + - ARM64(不常用): [clash-verge_${{ env.VERSION }}_arm64-setup.exe](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_arm64-setup.exe) + + #### 内置Webview2版(体积较大,仅在企业版系统或无法安装webview2时使用) + - 64位: [clash-verge_${{ env.VERSION }}_x64_fixed_webview2-setup.exe](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_x64_fixed_webview2-setup.exe) + - ARM64: [clash-verge_${{ env.VERSION }}_arm64_fixed_webview2-setup.exe](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_arm64_fixed_webview2-setup.exe) + + ### macOS + - Apple M芯片: [clash-verge_${{ env.VERSION }}_aarch64.dmg](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_aarch64.dmg) + - Intel芯片: [clash-verge_${{ env.VERSION }}_x64.dmg](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_x64.dmg) + + ### Linux + #### DEB包(Debian系) 使用 apt ./路径 安装 + - 64位: [clash-verge_${{ env.VERSION }}_amd64.deb](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_amd64.deb) + - ARM64: [clash-verge_${{ env.VERSION }}_arm64.deb](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_arm64.deb) + - ARMv7: [clash-verge_${{ env.VERSION }}_armhf.deb](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_armhf.deb) + + #### RPM包(Redhat系) 使用 dnf ./路径 安装 + - 64位: [clash-verge_${{ env.VERSION }}_amd64.rpm](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_amd64.rpm) + - ARM64: [clash-verge_${{ env.VERSION }}_aarch64.rpm](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_aarch64.rpm) + - ARMv7: [clash-verge_${{ env.VERSION }}_armhfp.rpm](${{ env.DOWNLOAD_URL }}/clash-verge_${{ env.VERSION }}_armhfp.rpm) + + ### FAQ + - [常见问题](https://clash-verge-rev.github.io/faq/windows.html) + + ### 稳定机场VPN推荐 + - [狗狗加速](https://verge.dginv.click/#/register?code=oaxsAGo6) + Created at ${{ env.BUILDTIME }}. + EOF + + - name: Upload Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.TAG_NAME }} + name: "Clash Verge Rev ${{ env.TAG_NAME }}" + body_path: release.txt + prerelease: false + token: ${{ secrets.GITHUB_TOKEN }} + generate_release_notes: true + release: name: Release Build - needs: check_tag_version + needs: [check_tag_version, update_tag] strategy: fail-fast: false matrix: @@ -112,12 +203,13 @@ jobs: with: tagName: v__VERSION__ releaseName: "Clash Verge Rev v__VERSION__" - releaseBody: "More new features are now supported." + releaseBody: "See release notes for detailed changelog." tauriScript: pnpm args: --target ${{ matrix.target }} release-for-linux-arm: name: Release Build for Linux ARM + needs: [check_tag_version, update_tag] strategy: fail-fast: false matrix: @@ -232,7 +324,7 @@ jobs: with: tag_name: v${{env.VERSION}} name: "Clash Verge Rev v${{env.VERSION}}" - body: "More new features are now supported." + body: "See release notes for detailed changelog." token: ${{ secrets.GITHUB_TOKEN }} files: | src-tauri/target/${{ matrix.target }}/release/bundle/deb/*.deb @@ -240,6 +332,7 @@ jobs: release-for-fixed-webview2: name: Release Build for Fixed WebView2 + needs: [check_tag_version, update_tag] strategy: fail-fast: false matrix: @@ -323,7 +416,7 @@ jobs: with: tag_name: v${{steps.build.outputs.appVersion}} name: "Clash Verge Rev v${{steps.build.outputs.appVersion}}" - body: "More new features are now supported." + body: "See release notes for detailed changelog." token: ${{ secrets.GITHUB_TOKEN }} files: src-tauri/target/${{ matrix.target }}/release/bundle/nsis/*setup* @@ -405,3 +498,39 @@ jobs: release-tag: v${{env.VERSION}} installers-regex: '_(arm64|x64|x86)-setup\.exe$' token: ${{ secrets.WINGET_TOKEN }} + + notify-telegram: + name: Notify Telegram + runs-on: ubuntu-latest + needs: [release-update] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: "22" + + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + run_install: false + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Get Version and Release Info + run: | + sudo apt-get update + sudo apt-get install jq + echo "VERSION=$(cat package.json | jq '.version' | tr -d '"')" >> $GITHUB_ENV + echo "DOWNLOAD_URL=https://github.com/clash-verge-rev/clash-verge-rev/releases/download/v$(cat package.json | jq '.version' | tr -d '"')" >> $GITHUB_ENV + + - name: Send Telegram Notification + run: node scripts/telegram.mjs + env: + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + BUILD_TYPE: release + VERSION: ${{ env.VERSION }} + DOWNLOAD_URL: ${{ env.DOWNLOAD_URL }} diff --git a/scripts/telegram.mjs b/scripts/telegram.mjs new file mode 100644 index 00000000..2e384e8b --- /dev/null +++ b/scripts/telegram.mjs @@ -0,0 +1,88 @@ +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"; // 测试频道 + +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 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 chatId = isAutobuild ? CHAT_ID_TEST : CHAT_ID_RELEASE; + const buildType = isAutobuild ? "滚动更新版" : "正式版"; + + log_info(`Preparing Telegram notification for ${buildType} ${version}`); + log_info(`Target channel: ${chatId}`); + log_info(`Download URL: ${downloadUrl}`); + + // 读取发布说明和下载地址 + let releaseContent = ""; + try { + releaseContent = readFileSync("release.txt", "utf-8"); + log_info("成功读取 release.txt 文件"); + } catch (error) { + log_error("无法读取 release.txt,使用默认发布说明"); + releaseContent = "更多新功能现已支持,详细更新日志请查看发布页面。"; + } + + // Markdown 转换为 HTML + function convertMarkdownToTelegramHTML(content) { + return content + .split("\n") + .map(line => { + if (line.trim().length === 0) { + return ""; + } else if (line.startsWith("## ")) { + return `${line.replace("## ", "")}`; + } else if (line.startsWith("### ")) { + return `${line.replace("### ", "")}`; + } else if (line.startsWith("#### ")) { + return `${line.replace("#### ", "")}`; + } else { + let processedLine = line.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); + processedLine = processedLine.replace(/\*\*([^*]+)\*\*/g, '$1'); + return processedLine; + } + }) + .join("\n"); + } + + const formattedContent = convertMarkdownToTelegramHTML(releaseContent); + + const releaseTitle = isAutobuild ? "滚动更新版发布" : "正式发布"; + const content = `🎉 Clash Verge Rev v${version} ${releaseTitle}\n\n${formattedContent}`; + + // 发送到 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, + }, + parse_mode: "HTML", + }); + log_success(`✅ Telegram 通知发送成功到 ${chatId}`); + } catch (error) { + log_error(`❌ Telegram 通知发送失败到 ${chatId}:`, error.response?.data || error.message); + process.exit(1); + } +} + +// 执行函数 +sendTelegramNotification().catch((error) => { + log_error("脚本执行失败:", error.message); + process.exit(1); +});