From 206613f09210d49d0fe215e41cbb2249b615255b Mon Sep 17 00:00:00 2001 From: Rust Date: Mon, 27 Oct 2025 22:53:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9C=A8=E7=BA=BF=E6=89=93?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-android-apk.yml | 324 +++++++++++++++ .github/workflows/build-clash-core.yml | 142 +++++++ .github/workflows/build-multiplatform.yml | 479 ++++++++++++++++++++++ 3 files changed, 945 insertions(+) create mode 100644 .github/workflows/build-android-apk.yml create mode 100644 .github/workflows/build-clash-core.yml create mode 100644 .github/workflows/build-multiplatform.yml diff --git a/.github/workflows/build-android-apk.yml b/.github/workflows/build-android-apk.yml new file mode 100644 index 0000000..554bc34 --- /dev/null +++ b/.github/workflows/build-android-apk.yml @@ -0,0 +1,324 @@ +name: Build Android APK + +on: + push: + branches: + - main + - develop + tags: + - 'v*' + pull_request: + branches: + - main + workflow_dispatch: # 允许手动触发 + inputs: + build_type: + description: '构建类型' + required: true + default: 'release' + type: choice + options: + - debug + - release + api_domain: + description: 'API 域名' + required: true + default: 'api.maodag.top' + type: string + oss_url_1: + description: 'OSS 配置地址 1' + required: true + default: 'https://ppp2.oss-cn-hongkong.aliyuncs.com/bear1.txt' + type: string + oss_url_2: + description: 'OSS 配置地址 2' + required: true + default: 'https://xgp3.oss-ap-northeast-1.aliyuncs.com/bear1.txt' + type: string + oss_url_3: + description: 'OSS 配置地址 3' + required: true + default: 'https://xpp4.oss-ap-northeast-2.aliyuncs.com/bear1.txt' + type: string + oss_url_4: + description: 'OSS 配置地址 4' + required: true + default: 'https://xpp5.oss-ap-southeast-1.aliyuncs.com/bear1.txt' + type: string + +jobs: + build-libcore: + name: 编译 libcore.aar + runs-on: ubuntu-latest + + steps: + - name: 📥 Checkout 代码 + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: 🔧 设置 Go 环境 + uses: actions/setup-go@v5 + with: + go-version: '1.23' + cache: true + cache-dependency-path: libcore/go.sum + + - name: 🔧 设置 Node.js 环境 + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: 🔧 设置 Java 环境 + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + + - name: 🔧 安装 gomobile + run: | + go install golang.org/x/mobile/cmd/gomobile@latest + gomobile init + + - name: 📦 编译 libcore.aar + working-directory: libcore + run: | + echo "🚀 开始编译 libcore..." + bash docker-compile.sh || make android + + echo "✅ 编译完成,检查产物..." + ls -lh bin/ + + if [ -f "bin/libcore.aar" ]; then + echo "✅ libcore.aar 生成成功" + cp bin/libcore.aar ../android/app/libs/ + else + echo "❌ libcore.aar 未找到" + exit 1 + fi + + - name: 📤 上传 libcore.aar + uses: actions/upload-artifact@v4 + with: + name: libcore-aar + path: android/app/libs/libcore.aar + retention-days: 7 + + build-apk: + name: 编译 Android APK + needs: build-libcore + runs-on: ubuntu-latest + + strategy: + matrix: + build_type: [release] # 默认 release 构建 + + steps: + - name: 📥 Checkout 代码 + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: 🔧 设置 Java 环境 + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + + - name: 🔧 设置 Flutter 环境 + uses: subosito/flutter-action@v2 + with: + flutter-version: '3.24.5' + channel: 'stable' + cache: true + + - name: 📥 下载 libcore.aar + uses: actions/download-artifact@v4 + with: + name: libcore-aar + path: android/app/libs/ + + - name: ⚙️ 配置 API 域名和 OSS 地址 + run: | + CONFIG_FILE="lib/app/common/app_config.dart" + + # 获取参数(手动触发时使用输入值,自动触发时使用默认值) + API_DOMAIN="${{ inputs.api_domain || 'api.maodag.top' }}" + OSS_URL_1="${{ inputs.oss_url_1 || 'https://ppp2.oss-cn-hongkong.aliyuncs.com/bear1.txt' }}" + OSS_URL_2="${{ inputs.oss_url_2 || 'https://xgp3.oss-ap-northeast-1.aliyuncs.com/bear1.txt' }}" + OSS_URL_3="${{ inputs.oss_url_3 || 'https://xpp4.oss-ap-northeast-2.aliyuncs.com/bear1.txt' }}" + OSS_URL_4="${{ inputs.oss_url_4 || 'https://xpp5.oss-ap-southeast-1.aliyuncs.com/bear1.txt' }}" + + echo "🔧 配置构建参数:" + echo " API 域名: $API_DOMAIN" + echo " OSS 地址 1: $OSS_URL_1" + echo " OSS 地址 2: $OSS_URL_2" + echo " OSS 地址 3: $OSS_URL_3" + echo " OSS 地址 4: $OSS_URL_4" + + # 替换 API 域名 + sed -i "s|api\.maodag\.top|$API_DOMAIN|g" "$CONFIG_FILE" + + # 替换 OSS 地址 + sed -i "s|https://ppp2\.oss-cn-hongkong\.aliyuncs\.com/bear1\.txt|$OSS_URL_1|g" "$CONFIG_FILE" + sed -i "s|https://xgp3\.oss-ap-northeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_2|g" "$CONFIG_FILE" + sed -i "s|https://xpp4\.oss-ap-northeast-2\.aliyuncs\.com/bear1\.txt|$OSS_URL_3|g" "$CONFIG_FILE" + sed -i "s|https://xpp5\.oss-ap-southeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_4|g" "$CONFIG_FILE" + + echo "✅ 配置替换完成" + echo "" + echo "📄 查看修改后的配置:" + grep -A 15 "kr_baseDomains" "$CONFIG_FILE" || true + + - name: 📦 安装 Flutter 依赖 + run: | + flutter pub get + flutter pub run build_runner build --delete-conflicting-outputs + + - name: 🔨 构建 APK + run: | + if [ "${{ matrix.build_type }}" = "release" ]; then + flutter build apk --release --split-per-abi + else + flutter build apk --debug --split-per-abi + fi + + - name: 📋 生成构建信息 + id: build_info + run: | + BUILD_DATE=$(date '+%Y-%m-%d %H:%M:%S') + COMMIT_SHA=${GITHUB_SHA::7} + + echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT + echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT + + echo "📊 构建信息:" + echo " - 日期: $BUILD_DATE" + echo " - 提交: $COMMIT_SHA" + echo " - 分支: ${GITHUB_REF#refs/heads/}" + + - name: 📦 重命名 APK 文件 + run: | + BUILD_TYPE="${{ matrix.build_type }}" + COMMIT_SHA=${{ steps.build_info.outputs.commit_sha }} + DATE=$(date '+%Y%m%d') + + cd build/app/outputs/flutter-apk/ + + for file in app-*-${BUILD_TYPE}.apk; do + if [ -f "$file" ]; then + # 提取架构名称 (arm64-v8a, armeabi-v7a, x86_64) + ARCH=$(echo "$file" | sed "s/app-\(.*\)-${BUILD_TYPE}.apk/\1/") + NEW_NAME="BearVPN-${ARCH}-${BUILD_TYPE}-${DATE}-${COMMIT_SHA}.apk" + + mv "$file" "$NEW_NAME" + + # 计算文件大小和 MD5 + SIZE=$(ls -lh "$NEW_NAME" | awk '{print $5}') + MD5=$(md5sum "$NEW_NAME" | awk '{print $1}') + + echo "✅ $NEW_NAME" + echo " 大小: $SIZE" + echo " MD5: $MD5" + fi + done + + ls -lh + + - name: 📤 上传 APK (arm64-v8a) + uses: actions/upload-artifact@v4 + with: + name: apk-arm64-v8a-${{ matrix.build_type }} + path: build/app/outputs/flutter-apk/*arm64-v8a*.apk + retention-days: 30 + + - name: 📤 上传 APK (armeabi-v7a) + uses: actions/upload-artifact@v4 + with: + name: apk-armeabi-v7a-${{ matrix.build_type }} + path: build/app/outputs/flutter-apk/*armeabi-v7a*.apk + retention-days: 30 + + - name: 📤 上传 APK (x86_64) + uses: actions/upload-artifact@v4 + with: + name: apk-x86_64-${{ matrix.build_type }} + path: build/app/outputs/flutter-apk/*x86_64*.apk + retention-days: 30 + + create-release: + name: 创建 GitHub Release + needs: build-apk + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + + steps: + - name: 📥 下载所有 APK + uses: actions/download-artifact@v4 + with: + path: artifacts + pattern: apk-* + + - name: 📋 生成 Release 说明 + id: release_notes + run: | + cat > release_notes.md << 'EOF' + ## 🎉 BearVPN Android 版本发布 + + ### 📦 安装包说明 + + | 架构 | 适用设备 | 文件大小 | + |------|----------|----------| + | arm64-v8a | 64位 ARM 设备(推荐,现代手机) | ~40MB | + | armeabi-v7a | 32位 ARM 设备(老旧手机) | ~35MB | + | x86_64 | x86_64 模拟器 | ~45MB | + + ### ✨ 主要特性 + + - ✅ 支持 Shadowsocks/VLESS/Trojan/Hysteria2 等协议 + - ✅ 内置 sing-box 核心 + - ✅ 支持自定义路由规则 + - ✅ 支持 URL Test 节点延迟测试 + + ### 📥 下载建议 + + **不确定选哪个?** 下载 `arm64-v8a` 版本即可,适用于绝大多数现代 Android 手机。 + + ### 🔒 文件校验 + + 下载后请验证 MD5 以确保文件完整性(见下方 Assets 描述)。 + + --- + + **构建信息:** + - 提交: ${GITHUB_SHA::7} + - 构建时间: $(date '+%Y-%m-%d %H:%M:%S UTC') + - Flutter: 3.24.5 + - sing-box: latest + EOF + + echo "release_notes<> $GITHUB_OUTPUT + cat release_notes.md >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: 🚀 创建 GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: | + artifacts/apk-arm64-v8a-*/*.apk + artifacts/apk-armeabi-v7a-*/*.apk + artifacts/apk-x86_64-*/*.apk + body: ${{ steps.release_notes.outputs.release_notes }} + draft: false + prerelease: false + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: 📢 构建成功通知 + run: | + echo "✅ 构建完成!" + echo "📦 Release 已创建: ${{ github.ref }}" + echo "🔗 查看: https://github.com/${{ github.repository }}/releases" diff --git a/.github/workflows/build-clash-core.yml b/.github/workflows/build-clash-core.yml new file mode 100644 index 0000000..5c82290 --- /dev/null +++ b/.github/workflows/build-clash-core.yml @@ -0,0 +1,142 @@ +name: Build Clash Core + +on: + push: + paths: + - 'core/**' + - '.github/workflows/build-clash-core.yml' + pull_request: + paths: + - 'core/**' + workflow_dispatch: # 允许手动触发 + +jobs: + build-android: + name: Build Android (${{ matrix.arch }}) + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + include: + - arch: arm64 + abi: arm64-v8a + cc: aarch64-linux-android29-clang + - arch: armv7 + abi: armeabi-v7a + cc: armv7a-linux-androideabi29-clang + - arch: x86_64 + abi: x86_64 + cc: x86_64-linux-android29-clang + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.20' + cache: true + cache-dependency-path: core/go.sum + + - name: Setup Android NDK + uses: nttld/setup-ndk@v1 + with: + ndk-version: r25c + add-to-path: true + + - name: Build Core + working-directory: core + run: make android-${{ matrix.arch }} + env: + ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} + + - name: Verify Build + run: | + echo "📦 检查编译产物..." + ls -lh android/app/src/main/jniLibs/${{ matrix.abi }}/libclash.so + file android/app/src/main/jniLibs/${{ matrix.abi }}/libclash.so + + echo "🔍 验证导出函数..." + nm -D android/app/src/main/jniLibs/${{ matrix.abi }}/libclash.so | grep -E "(quickStart|getAndroidVpnOptions|startTUN)" + + - name: Calculate MD5 + id: md5 + run: | + MD5=$(md5sum android/app/src/main/jniLibs/${{ matrix.abi }}/libclash.so | awk '{print $1}') + echo "md5=$MD5" >> $GITHUB_OUTPUT + echo "📋 MD5: $MD5" + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: libclash-${{ matrix.abi }} + path: android/app/src/main/jniLibs/${{ matrix.abi }}/libclash.so + retention-days: 30 + if-no-files-found: error + + - name: Comment Build Info + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const stats = fs.statSync('android/app/src/main/jniLibs/${{ matrix.abi }}/libclash.so'); + const sizeMB = (stats.size / 1024 / 1024).toFixed(2); + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `### 🔨 Clash Core 构建完成 (${{ matrix.abi }}) + + - **架构:** ${{ matrix.abi }} + - **大小:** ${sizeMB} MB + - **MD5:** ${{ steps.md5.outputs.md5 }} + - **提交:** ${context.sha.substring(0, 7)} + + [下载构建产物](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})` + }); + + create-release: + name: Create Release + needs: build-android + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + + steps: + - name: Download All Artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Create Release Archive + run: | + cd artifacts + tar -czf clash-core-android-all.tar.gz libclash-*/*.so + ls -lh clash-core-android-all.tar.gz + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: artifacts/clash-core-android-all.tar.gz + body: | + ## Clash Meta 核心 Android 构建 + + 此版本包含所有 Android 架构的预编译二进制文件: + - arm64-v8a (ARM64) + - armeabi-v7a (ARMv7) + - x86_64 (模拟器) + + **使用方法:** + ```bash + tar -xzf clash-core-android-all.tar.gz + cp libclash-*/libclash.so android/app/src/main/jniLibs/ + ``` + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/build-multiplatform.yml b/.github/workflows/build-multiplatform.yml new file mode 100644 index 0000000..ab7422d --- /dev/null +++ b/.github/workflows/build-multiplatform.yml @@ -0,0 +1,479 @@ +name: Build Multi-Platform + +on: + push: + branches: + - main + - develop + tags: + - 'v*' + pull_request: + branches: + - main + workflow_dispatch: + inputs: + build_type: + description: '构建类型' + required: true + default: 'release' + type: choice + options: + - debug + - release + api_domain: + description: 'API 域名' + required: true + default: 'api.maodag.top' + type: string + oss_url_1: + description: 'OSS 配置地址 1' + required: true + default: 'https://ppp2.oss-cn-hongkong.aliyuncs.com/bear1.txt' + type: string + oss_url_2: + description: 'OSS 配置地址 2' + required: true + default: 'https://xgp3.oss-ap-northeast-1.aliyuncs.com/bear1.txt' + type: string + oss_url_3: + description: 'OSS 配置地址 3' + required: true + default: 'https://xpp4.oss-ap-northeast-2.aliyuncs.com/bear1.txt' + type: string + oss_url_4: + description: 'OSS 配置地址 4' + required: true + default: 'https://xpp5.oss-ap-southeast-1.aliyuncs.com/bear1.txt' + type: string + platforms: + description: '构建平台 (多选: android,windows,macos,linux)' + required: true + default: 'android,windows,macos,linux' + type: string + +jobs: + # ==================== 编译 libcore ==================== + build-libcore: + name: 编译 libcore + runs-on: ubuntu-latest + + steps: + - name: 📥 Checkout 代码 + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: 🔧 设置 Go 环境 + uses: actions/setup-go@v5 + with: + go-version: '1.23' + cache: true + cache-dependency-path: libcore/go.sum + + - name: 🔧 设置 Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: 🔧 设置 Java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + + - name: 🔧 安装 gomobile + run: | + go install golang.org/x/mobile/cmd/gomobile@latest + gomobile init + + - name: 📦 编译 libcore.aar (Android) + working-directory: libcore + run: | + echo "🚀 开始编译 Android libcore..." + bash docker-compile.sh || make android + + if [ -f "bin/libcore.aar" ]; then + echo "✅ libcore.aar 生成成功" + mkdir -p ../android/app/libs/ + cp bin/libcore.aar ../android/app/libs/ + else + echo "❌ libcore.aar 未找到" + exit 1 + fi + + - name: 📤 上传 libcore.aar + uses: actions/upload-artifact@v4 + with: + name: libcore-aar + path: android/app/libs/libcore.aar + retention-days: 7 + + # ==================== Android 构建 ==================== + build-android: + name: 构建 Android APK + needs: build-libcore + runs-on: ubuntu-latest + if: contains(inputs.platforms || 'android', 'android') + + steps: + - name: 📥 Checkout 代码 + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: 🔧 设置 Java + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + + - name: 🔧 设置 Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: '3.24.5' + channel: 'stable' + cache: true + + - name: 📥 下载 libcore.aar + uses: actions/download-artifact@v4 + with: + name: libcore-aar + path: android/app/libs/ + + - name: ⚙️ 配置 API 和 OSS + run: | + CONFIG_FILE="lib/app/common/app_config.dart" + API_DOMAIN="${{ inputs.api_domain || 'api.maodag.top' }}" + OSS_URL_1="${{ inputs.oss_url_1 || 'https://ppp2.oss-cn-hongkong.aliyuncs.com/bear1.txt' }}" + OSS_URL_2="${{ inputs.oss_url_2 || 'https://xgp3.oss-ap-northeast-1.aliyuncs.com/bear1.txt' }}" + OSS_URL_3="${{ inputs.oss_url_3 || 'https://xpp4.oss-ap-northeast-2.aliyuncs.com/bear1.txt' }}" + OSS_URL_4="${{ inputs.oss_url_4 || 'https://xpp5.oss-ap-southeast-1.aliyuncs.com/bear1.txt' }}" + + echo "🔧 配置参数:" + echo " API: $API_DOMAIN" + echo " OSS: $OSS_URL_1" + + sed -i "s|api\.maodag\.top|$API_DOMAIN|g" "$CONFIG_FILE" + sed -i "s|https://ppp2\.oss-cn-hongkong\.aliyuncs\.com/bear1\.txt|$OSS_URL_1|g" "$CONFIG_FILE" + sed -i "s|https://xgp3\.oss-ap-northeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_2|g" "$CONFIG_FILE" + sed -i "s|https://xpp4\.oss-ap-northeast-2\.aliyuncs\.com/bear1\.txt|$OSS_URL_3|g" "$CONFIG_FILE" + sed -i "s|https://xpp5\.oss-ap-southeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_4|g" "$CONFIG_FILE" + + echo "✅ 配置完成" + + - name: 📦 安装依赖 + run: | + flutter pub get + flutter pub run build_runner build --delete-conflicting-outputs + + - name: 🔨 构建 APK + run: | + BUILD_TYPE="${{ inputs.build_type || 'release' }}" + if [ "$BUILD_TYPE" = "release" ]; then + flutter build apk --release --split-per-abi + else + flutter build apk --debug --split-per-abi + fi + + - name: 📦 重命名 APK + run: | + BUILD_TYPE="${{ inputs.build_type || 'release' }}" + COMMIT_SHA=${GITHUB_SHA::7} + DATE=$(date '+%Y%m%d') + cd build/app/outputs/flutter-apk/ + + for file in app-*-${BUILD_TYPE}.apk; do + if [ -f "$file" ]; then + ARCH=$(echo "$file" | sed "s/app-\(.*\)-${BUILD_TYPE}.apk/\1/") + NEW_NAME="BearVPN-android-${ARCH}-${BUILD_TYPE}-${DATE}-${COMMIT_SHA}.apk" + mv "$file" "$NEW_NAME" + echo "✅ $NEW_NAME" + fi + done + + - name: 📤 上传 APK + uses: actions/upload-artifact@v4 + with: + name: android-apk + path: build/app/outputs/flutter-apk/*.apk + retention-days: 30 + + # ==================== Windows 构建 ==================== + build-windows: + name: 构建 Windows + runs-on: windows-latest + if: contains(inputs.platforms || 'windows', 'windows') + + steps: + - name: 📥 Checkout 代码 + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: 🔧 设置 Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: '3.24.5' + channel: 'stable' + cache: true + + - name: ⚙️ 配置 API 和 OSS + shell: bash + run: | + CONFIG_FILE="lib/app/common/app_config.dart" + API_DOMAIN="${{ inputs.api_domain || 'api.maodag.top' }}" + OSS_URL_1="${{ inputs.oss_url_1 || 'https://ppp2.oss-cn-hongkong.aliyuncs.com/bear1.txt' }}" + OSS_URL_2="${{ inputs.oss_url_2 || 'https://xgp3.oss-ap-northeast-1.aliyuncs.com/bear1.txt' }}" + OSS_URL_3="${{ inputs.oss_url_3 || 'https://xpp4.oss-ap-northeast-2.aliyuncs.com/bear1.txt' }}" + OSS_URL_4="${{ inputs.oss_url_4 || 'https://xpp5.oss-ap-southeast-1.aliyuncs.com/bear1.txt' }}" + + sed -i "s|api\.maodag\.top|$API_DOMAIN|g" "$CONFIG_FILE" + sed -i "s|https://ppp2\.oss-cn-hongkong\.aliyuncs\.com/bear1\.txt|$OSS_URL_1|g" "$CONFIG_FILE" + sed -i "s|https://xgp3\.oss-ap-northeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_2|g" "$CONFIG_FILE" + sed -i "s|https://xpp4\.oss-ap-northeast-2\.aliyuncs\.com/bear1\.txt|$OSS_URL_3|g" "$CONFIG_FILE" + sed -i "s|https://xpp5\.oss-ap-southeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_4|g" "$CONFIG_FILE" + + - name: 📦 安装依赖 + run: | + flutter pub get + flutter pub run build_runner build --delete-conflicting-outputs + + - name: 🔨 构建 Windows + run: | + $BUILD_TYPE = "${{ inputs.build_type || 'release' }}" + if ($BUILD_TYPE -eq "release") { + flutter build windows --release + } else { + flutter build windows --debug + } + + - name: 📦 打包 Windows + shell: bash + run: | + BUILD_TYPE="${{ inputs.build_type || 'release' }}" + COMMIT_SHA=${GITHUB_SHA::7} + DATE=$(date '+%Y%m%d') + + cd build/windows/x64/runner/Release + 7z a -tzip "../../../../../BearVPN-windows-x64-${BUILD_TYPE}-${DATE}-${COMMIT_SHA}.zip" ./* + + - name: 📤 上传 Windows + uses: actions/upload-artifact@v4 + with: + name: windows-x64 + path: BearVPN-windows-*.zip + retention-days: 30 + + # ==================== macOS 构建 ==================== + build-macos: + name: 构建 macOS + runs-on: macos-latest + if: contains(inputs.platforms || 'macos', 'macos') + + steps: + - name: 📥 Checkout 代码 + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: 🔧 设置 Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: '3.24.5' + channel: 'stable' + cache: true + + - name: ⚙️ 配置 API 和 OSS + run: | + CONFIG_FILE="lib/app/common/app_config.dart" + API_DOMAIN="${{ inputs.api_domain || 'api.maodag.top' }}" + OSS_URL_1="${{ inputs.oss_url_1 || 'https://ppp2.oss-cn-hongkong.aliyuncs.com/bear1.txt' }}" + OSS_URL_2="${{ inputs.oss_url_2 || 'https://xgp3.oss-ap-northeast-1.aliyuncs.com/bear1.txt' }}" + OSS_URL_3="${{ inputs.oss_url_3 || 'https://xpp4.oss-ap-northeast-2.aliyuncs.com/bear1.txt' }}" + OSS_URL_4="${{ inputs.oss_url_4 || 'https://xpp5.oss-ap-southeast-1.aliyuncs.com/bear1.txt' }}" + + sed -i '' "s|api\.maodag\.top|$API_DOMAIN|g" "$CONFIG_FILE" + sed -i '' "s|https://ppp2\.oss-cn-hongkong\.aliyuncs\.com/bear1\.txt|$OSS_URL_1|g" "$CONFIG_FILE" + sed -i '' "s|https://xgp3\.oss-ap-northeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_2|g" "$CONFIG_FILE" + sed -i '' "s|https://xpp4\.oss-ap-northeast-2\.aliyuncs\.com/bear1\.txt|$OSS_URL_3|g" "$CONFIG_FILE" + sed -i '' "s|https://xpp5\.oss-ap-southeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_4|g" "$CONFIG_FILE" + + - name: 📦 安装依赖 + run: | + flutter pub get + flutter pub run build_runner build --delete-conflicting-outputs + + - name: 🔨 构建 macOS + run: | + BUILD_TYPE="${{ inputs.build_type || 'release' }}" + if [ "$BUILD_TYPE" = "release" ]; then + flutter build macos --release + else + flutter build macos --debug + fi + + - name: 📦 打包 macOS + run: | + BUILD_TYPE="${{ inputs.build_type || 'release' }}" + COMMIT_SHA=${GITHUB_SHA::7} + DATE=$(date '+%Y%m%d') + + cd build/macos/Build/Products/Release + zip -r -y "../../../../../BearVPN-macos-${BUILD_TYPE}-${DATE}-${COMMIT_SHA}.zip" BearVPN.app + + - name: 📤 上传 macOS + uses: actions/upload-artifact@v4 + with: + name: macos-app + path: BearVPN-macos-*.zip + retention-days: 30 + + # ==================== Linux 构建 ==================== + build-linux: + name: 构建 Linux + runs-on: ubuntu-latest + if: contains(inputs.platforms || 'linux', 'linux') + + steps: + - name: 📥 Checkout 代码 + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: 🔧 安装 Linux 依赖 + run: | + sudo apt-get update + sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev + + - name: 🔧 设置 Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: '3.24.5' + channel: 'stable' + cache: true + + - name: ⚙️ 配置 API 和 OSS + run: | + CONFIG_FILE="lib/app/common/app_config.dart" + API_DOMAIN="${{ inputs.api_domain || 'api.maodag.top' }}" + OSS_URL_1="${{ inputs.oss_url_1 || 'https://ppp2.oss-cn-hongkong.aliyuncs.com/bear1.txt' }}" + OSS_URL_2="${{ inputs.oss_url_2 || 'https://xgp3.oss-ap-northeast-1.aliyuncs.com/bear1.txt' }}" + OSS_URL_3="${{ inputs.oss_url_3 || 'https://xpp4.oss-ap-northeast-2.aliyuncs.com/bear1.txt' }}" + OSS_URL_4="${{ inputs.oss_url_4 || 'https://xpp5.oss-ap-southeast-1.aliyuncs.com/bear1.txt' }}" + + sed -i "s|api\.maodag\.top|$API_DOMAIN|g" "$CONFIG_FILE" + sed -i "s|https://ppp2\.oss-cn-hongkong\.aliyuncs\.com/bear1\.txt|$OSS_URL_1|g" "$CONFIG_FILE" + sed -i "s|https://xgp3\.oss-ap-northeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_2|g" "$CONFIG_FILE" + sed -i "s|https://xpp4\.oss-ap-northeast-2\.aliyuncs\.com/bear1\.txt|$OSS_URL_3|g" "$CONFIG_FILE" + sed -i "s|https://xpp5\.oss-ap-southeast-1\.aliyuncs\.com/bear1\.txt|$OSS_URL_4|g" "$CONFIG_FILE" + + - name: 📦 安装依赖 + run: | + flutter pub get + flutter pub run build_runner build --delete-conflicting-outputs + + - name: 🔨 构建 Linux + run: | + BUILD_TYPE="${{ inputs.build_type || 'release' }}" + if [ "$BUILD_TYPE" = "release" ]; then + flutter build linux --release + else + flutter build linux --debug + fi + + - name: 📦 打包 Linux + run: | + BUILD_TYPE="${{ inputs.build_type || 'release' }}" + COMMIT_SHA=${GITHUB_SHA::7} + DATE=$(date '+%Y%m%d') + + cd build/linux/x64/release/bundle + tar -czf "../../../../../BearVPN-linux-x64-${BUILD_TYPE}-${DATE}-${COMMIT_SHA}.tar.gz" ./* + + - name: 📤 上传 Linux + uses: actions/upload-artifact@v4 + with: + name: linux-x64 + path: BearVPN-linux-*.tar.gz + retention-days: 30 + + # ==================== 创建 Release ==================== + create-release: + name: 创建 Release + needs: [build-android, build-windows, build-macos, build-linux] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + + steps: + - name: 📥 下载所有构建产物 + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: 📋 生成 Release 说明 + id: release_notes + run: | + cat > release_notes.md << 'EOF' + ## 🎉 BearVPN 多平台版本发布 + + ### 📦 平台支持 + + | 平台 | 架构 | 文件 | + |-----|------|-----| + | **Android** | arm64-v8a | BearVPN-android-arm64-v8a-*.apk | + | **Android** | armeabi-v7a | BearVPN-android-armeabi-v7a-*.apk | + | **Android** | x86_64 | BearVPN-android-x86_64-*.apk | + | **Windows** | x64 | BearVPN-windows-x64-*.zip | + | **macOS** | Universal | BearVPN-macos-*.zip | + | **Linux** | x64 | BearVPN-linux-x64-*.tar.gz | + + ### ✨ 主要特性 + + - ✅ 支持 Shadowsocks/VLESS/Trojan/Hysteria2 + - ✅ 内置 sing-box 核心 + - ✅ 跨平台支持 + - ✅ 自定义路由规则 + + ### 📥 安装指南 + + **Android:** 下载 APK 直接安装 + **Windows:** 解压 ZIP 运行 BearVPN.exe + **macOS:** 解压 ZIP 拖拽到应用程序 + **Linux:** 解压 tar.gz 运行可执行文件 + + --- + + **构建信息:** + - 提交: ${GITHUB_SHA::7} + - 时间: $(date '+%Y-%m-%d %H:%M:%S UTC') + - Flutter: 3.24.5 + EOF + + echo "release_notes<> $GITHUB_OUTPUT + cat release_notes.md >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: 🚀 创建 Release + uses: softprops/action-gh-release@v2 + with: + files: | + artifacts/android-apk/*.apk + artifacts/windows-x64/*.zip + artifacts/macos-app/*.zip + artifacts/linux-x64/*.tar.gz + body: ${{ steps.release_notes.outputs.release_notes }} + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: 📢 构建完成 + run: | + echo "✅ 所有平台构建完成!" + echo "📦 Release: ${{ github.ref }}" + echo "🔗 https://github.com/${{ github.repository }}/releases"