From 1b0bff2beb57b0b7ef61cc2324ec845b3352ee0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E9=BA=A6?= Date: Tue, 10 Mar 2026 15:59:37 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20GitHub=20Actions=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=BC=96=E8=AF=91=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 跨平台自动编译 - macOS (Intel/Apple Silicon) - Linux (gnu/musl) - Windows (msvc/gnu) - 自动发布 Release GitHub Actions 将自动编译所有平台版本并上传到 Release。 --- .github/workflows/release.yml | 184 ++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..81d8c72 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,184 @@ +name: Release Build + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + +jobs: + build: + name: Build Release + strategy: + matrix: + include: + - os: macos-latest + target: x86_64-apple-darwin + name: macOS-Intel + archive: readflow-${{ github.ref_name }}-macos-x86_64.zip + + - os: macos-latest + target: aarch64-apple-darwin + name: macOS-Apple-Silicon + archive: readflow-${{ github.ref_name }}-macos-aarch64.zip + + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + name: Linux + archive: readflow-${{ github.ref_name }}-linux-x86_64.tar.gz + + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + name: Linux-MUSL + archive: readflow-${{ github.ref_name }}-linux-x86_64-musl.tar.gz + + - os: windows-latest + target: x86_64-pc-windows-msvc + name: Windows + archive: readflow-${{ github.ref_name }}-windows-x86_64.zip + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: actions-rs/toolchain@v1 + with: + target: ${{ matrix.target }} + profile: minimal + components: rustfmt, clippy + + - name: Cache cargo registry + uses: actions/cache@v4 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo index + uses: actions/cache@v4 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} + + - name: Build release + run: cargo build --release + + - name: Run tests + run: cargo test + + - name: Package macOS + if: matrix.name == 'macOS-Intel' || matrix.name == 'macOS-Apple-Silicon' + run: | + mkdir -p release + cp target/release/readflow release/ + chmod +x release/readflow + # Create Info.plist + cat > release/Info.plist << EOF + + + + + CFBundleExecutable + readflow + CFBundleIdentifier + com.readflow.app + CFBundleName + ReadFlow + CFBundleDisplayName + ReadFlow + CFBundleShortVersionString + ${{ github.ref_name }} + CFBundleVersion + ${{ github.ref_name }} + CFBundlePackageType + APPL + NSHighResolutionCapable + + + + EOF + cd release + mkdir -p ReadFlow.app/Contents/MacOS + mkdir -p ReadFlow.app/Contents/Resources + mv readflow ReadFlow.app/Contents/MacOS/ + mv Info.plist ReadFlow.app/Contents/ + cp -r ../assets ReadFlow.app/Contents/Resources/ || true + cd .. + zip -r -X ${{ matrix.archive }} ReadFlow.app + + - name: Package Linux + if: matrix.name == 'Linux' || matrix.name == 'Linux-MUSL' + run: | + mkdir -p release + cp target/release/readflow release/readflow + chmod +x release/readflow + # Create .desktop file + cat > release/readflow.desktop << EOF + [Desktop Entry] + Name=ReadFlow + Comment=ReadFlow - 面向开发者和知识工作者的阅读工具 + Exec=/usr/local/bin/readflow + Icon=readflow + Terminal=false + Type=Application + Categories=Utility;Reading; + EOF + cd release + if [ "${{ matrix.name }}" == "Linux-MUSL" ]; then + tar -czf ${{ matrix.archive }} readflow + else + tar -czf ${{ matrix.archive }} readflow readflow.desktop + fi + + - name: Package Windows + if: matrix.name == 'Windows' + run: | + mkdir -p release + cp target/release/readflow.exe release/ + # Create NSIS installer (simplified) + # For now, just create a simple wrapper script + cat > release/install.bat << 'EOF' + @echo off + echo Installing ReadFlow... + copy readflow.exe %LOCALAPPDATA%\readflow\ + echo Installation complete! + EOF + cd release + powershell Compress-Archive -Path ${{ matrix.archive }} -DestinationPath . readflow.exe install.bat + + - name: Upload Release Asset + uses: softprops/action-gh-release@v2 + with: + name: ${{ matrix.name }} + files: | + ${{ matrix.archive }} + body: | + ## 🎉 ReadFlow ${{ github.ref_name }} for ${{ matrix.name }} + + ### 下载 + - 下方附件中的安装包 + + ### 快速开始 + - 解压后运行 readflow 即可 + + ### 功能 + - ✅ EPUB/MOBI/Markdown/PDF 阅读 + - ✅ 20+ 编程语言语法高亮 + - ✅ 双语翻译对照 + - ✅ 笔记与书签系统 + - ✅ 插件系统 + - ✅ 主题商店 + + --- + + **下载附件**: ${{ matrix.name }} + generate_release_notes: true + tag_name: ${{ github.ref_name }} + token: ${{ secrets.GITHUB_TOKEN }} + fail_on_unmatched_files: true