feat(ci): 构建并发布WebAPI二进制文件- 在Linux、Windows和macOS的CI流程中添加WebAPI二进制构建步骤 #43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Release | |
| on: | |
| push: | |
| branches: [ "main", "master", "rust_new" ] | |
| tags: [ "v*" ] | |
| pull_request: | |
| branches: [ "main", "master", "rust_new" ] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| PROJECT_NAME: file_classification_cli | |
| jobs: | |
| test-linux: | |
| name: Test on Ubuntu | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install dependencies (Linux) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libsqlite3-dev | |
| - name: Run tests | |
| run: cargo test --verbose | |
| test-windows: | |
| name: Test on Windows | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install vcpkg | |
| run: | | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| cd vcpkg | |
| .\bootstrap-vcpkg.bat | |
| - name: Install dependencies (Windows) | |
| run: | | |
| cd vcpkg | |
| .\vcpkg install sqlite3:x64-windows sqlite3:x64-windows-static | |
| - name: Setup vcpkg paths for Windows | |
| run: | | |
| echo "VCPKG_ROOT=$env:GITHUB_WORKSPACE\vcpkg" >> $env:GITHUB_ENV | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows\lib" >> $env:GITHUB_PATH | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static\lib" >> $env:GITHUB_PATH | |
| - name: Run tests | |
| run: cargo test --verbose | |
| test-macos: | |
| name: Test on macOS | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install dependencies (macOS) | |
| run: | | |
| brew install sqlite3 | |
| - name: Run tests | |
| run: cargo test --verbose | |
| build-android: | |
| name: Build Android binary | |
| needs: [test-linux, test-windows, test-macos] | |
| if: always() | |
| runs-on: ubuntu-latest | |
| continue-on-error: true | |
| strategy: | |
| fail-fast: false | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install Android targets | |
| run: | | |
| rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android | |
| - name: Install Android NDK | |
| uses: nttld/setup-ndk@v1 | |
| with: | |
| ndk-version: r25b | |
| - name: Setup Android environment | |
| run: | | |
| echo "ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV | |
| echo "NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV | |
| - name: Configure cargo for Android | |
| run: | | |
| mkdir -p .cargo | |
| echo '[target.aarch64-linux-android]' > .cargo/config.toml | |
| echo "ar = \"$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar\"" >> .cargo/config.toml | |
| echo "linker = \"$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang\"" >> .cargo/config.toml | |
| - name: Install SQLite for Android | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libsqlite3-dev | |
| - name: Build for Android | |
| run: | | |
| cargo build --target aarch64-linux-android --release --bin file_classification_cli --verbose | |
| - name: Set Android binary name | |
| run: echo "ANDROID_BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload Android artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-android | |
| path: target/aarch64-linux-android/release/file_classification_cli | |
| build-linux: | |
| name: Build Linux binaries | |
| needs: test-linux | |
| if: always() | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: | |
| # x86 architectures | |
| - x86_64-unknown-linux-gnu | |
| - i686-unknown-linux-gnu | |
| # ARM architectures - most common ones | |
| - aarch64-unknown-linux-gnu | |
| - armv7-unknown-linux-gnueabihf | |
| # RISC-V architectures - supported ones | |
| - riscv64gc-unknown-linux-gnu | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install dependencies (Linux) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libsqlite3-dev gcc-multilib | |
| - name: Install cross-compilation tools | |
| run: | | |
| sudo apt-get install -y gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-i686-linux-gnu \ | |
| gcc-riscv64-linux-gnu | |
| - name: Configure cargo for cross-compilation | |
| run: | | |
| mkdir -p .cargo | |
| echo '[target.i686-unknown-linux-gnu]' > .cargo/config.toml | |
| echo 'linker = "i686-linux-gnu-gcc"' >> .cargo/config.toml | |
| echo '' >> .cargo/config.toml | |
| echo '[target.aarch64-unknown-linux-gnu]' >> .cargo/config.toml | |
| echo 'linker = "aarch64-linux-gnu-gcc"' >> .cargo/config.toml | |
| echo '' >> .cargo/config.toml | |
| echo '[target.armv7-unknown-linux-gnueabihf]' >> .cargo/config.toml | |
| echo 'linker = "arm-linux-gnueabihf-gcc"' >> .cargo/config.toml | |
| echo '' >> .cargo/config.toml | |
| echo '[target.riscv64gc-unknown-linux-gnu]' >> .cargo/config.toml | |
| echo 'linker = "riscv64-linux-gnu-gcc"' >> .cargo/config.toml | |
| - name: Build CLI release binary | |
| run: | | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose | |
| - name: Build WebAPI release binary | |
| run: | | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose | |
| - name: Set binary name | |
| run: echo "BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload CLI artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_cli | |
| - name: Upload WebAPI artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_webapi-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_webapi | |
| build-windows: | |
| name: Build Windows binaries | |
| needs: test-windows | |
| if: always() | |
| runs-on: windows-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: | |
| - x86_64-pc-windows-msvc | |
| - i686-pc-windows-msvc | |
| - aarch64-pc-windows-msvc | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install vcpkg | |
| run: | | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| cd vcpkg | |
| .\bootstrap-vcpkg.bat | |
| - name: Install dependencies (Windows) | |
| run: | | |
| cd vcpkg | |
| .\vcpkg install sqlite3:x64-windows sqlite3:x64-windows-static | |
| - name: Set up vcpkg for Windows | |
| run: | | |
| echo "VCPKG_ROOT=$env:GITHUB_WORKSPACE\vcpkg" >> $env:GITHUB_ENV | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows\lib" >> $env:GITHUB_PATH | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static\lib" >> $env:GITHUB_PATH | |
| - name: Build CLI release binary | |
| run: | | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose | |
| - name: Build WebAPI release binary | |
| run: | | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose | |
| - name: Set binary name | |
| run: echo "BINARY_NAME=file_classification_cli.exe" >> $env:GITHUB_ENV | |
| - name: Upload CLI artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_cli.exe | |
| - name: Upload WebAPI artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_webapi-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_webapi.exe | |
| build-macos: | |
| name: Build macOS binaries | |
| needs: test-macos | |
| if: always() | |
| runs-on: macos-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: | |
| - x86_64-apple-darwin | |
| - aarch64-apple-darwin | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install dependencies (macOS) | |
| run: | | |
| brew install sqlite3 | |
| - name: Build CLI release binary | |
| run: | | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose | |
| - name: Build WebAPI release binary | |
| run: | | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose | |
| - name: Set binary name | |
| run: echo "BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload CLI artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_cli | |
| - name: Upload WebAPI artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_webapi-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_webapi | |
| release: | |
| name: Create GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: [test-linux, test-windows, test-macos, build-linux, build-windows, build-macos, build-android] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Create release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| artifacts/file_classification_cli-x86_64-unknown-linux-gnu/file_classification_cli | |
| artifacts/file_classification_cli-i686-unknown-linux-gnu/file_classification_cli | |
| artifacts/file_classification_cli-aarch64-unknown-linux-gnu/file_classification_cli | |
| artifacts/file_classification_cli-armv7-unknown-linux-gnueabihf/file_classification_cli | |
| artifacts/file_classification_cli-riscv64gc-unknown-linux-gnu/file_classification_cli | |
| artifacts/file_classification_webapi-x86_64-unknown-linux-gnu/file_classification_webapi | |
| artifacts/file_classification_webapi-i686-unknown-linux-gnu/file_classification_webapi | |
| artifacts/file_classification_webapi-aarch64-unknown-linux-gnu/file_classification_webapi | |
| artifacts/file_classification_webapi-armv7-unknown-linux-gnueabihf/file_classification_webapi | |
| artifacts/file_classification_webapi-riscv64gc-unknown-linux-gnu/file_classification_webapi | |
| artifacts/file_classification_cli-x86_64-pc-windows-msvc/file_classification_cli.exe | |
| artifacts/file_classification_cli-i686-pc-windows-msvc/file_classification_cli.exe | |
| artifacts/file_classification_cli-aarch64-pc-windows-msvc/file_classification_cli.exe | |
| artifacts/file_classification_webapi-x86_64-pc-windows-msvc/file_classification_webapi.exe | |
| artifacts/file_classification_webapi-i686-pc-windows-msvc/file_classification_webapi.exe | |
| artifacts/file_classification_webapi-aarch64-pc-windows-msvc/file_classification_webapi.exe | |
| artifacts/file_classification_cli-x86_64-apple-darwin/file_classification_cli | |
| artifacts/file_classification_cli-aarch64-apple-darwin/file_classification_cli | |
| artifacts/file_classification_webapi-x86_64-apple-darwin/file_classification_webapi | |
| artifacts/file_classification_webapi-aarch64-apple-darwin/file_classification_webapi | |
| artifacts/file_classification_cli-android/file_classification_cli |