feat(database): 切换默认数据库为PostgreSQL并优化连接配置 #76
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" ] | |
| workflow_dispatch: | |
| inputs: | |
| features: | |
| description: 'Features to enable (comma-separated, e.g. sqlite-bundled,mysql-bundled,postgres-bundled,sqlite,mysql,postgres)' | |
| required: false | |
| default: 'sqlite-bundled' | |
| target_platforms: | |
| description: 'Target platforms to build (comma-separated, e.g. linux,windows,macos)' | |
| required: false | |
| default: 'linux,windows,macos' | |
| build_cli: | |
| description: 'Build CLI binary' | |
| type: boolean | |
| default: true | |
| build_webapi: | |
| description: 'Build WebAPI binary' | |
| type: boolean | |
| default: true | |
| 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: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - 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: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - 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: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - 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: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - 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 | |
| echo '' >> .cargo/config.toml | |
| echo '[target.armv7-linux-androideabi]' >> .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/armv7a-linux-androideabi21-clang\"" >> .cargo/config.toml | |
| echo '' >> .cargo/config.toml | |
| echo '[target.x86_64-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/x86_64-linux-android21-clang\"" >> .cargo/config.toml | |
| echo '' >> .cargo/config.toml | |
| echo '[target.i686-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/i686-linux-android21-clang\"" >> .cargo/config.toml | |
| - name: Install SQLite for Android | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libsqlite3-dev | |
| - name: Prepare features | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| FEATURES="${{ github.event.inputs.features }}" | |
| else | |
| FEATURES="sqlite-bundled" | |
| fi | |
| echo "FEATURES=$FEATURES" >> $GITHUB_ENV | |
| - name: Build for Android | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| run: | | |
| if [ -n "$FEATURES" ]; then | |
| cargo build --target aarch64-linux-android --release --bin file_classification_cli --features "$FEATURES" --verbose | |
| else | |
| cargo build --target aarch64-linux-android --release --bin file_classification_cli --verbose | |
| fi | |
| - name: Build for other Android targets | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| run: | | |
| if [ -n "$FEATURES" ]; then | |
| cargo build --target armv7-linux-androideabi --release --bin file_classification_cli --features "$FEATURES" --verbose | |
| cargo build --target x86_64-linux-android --release --bin file_classification_cli --features "$FEATURES" --verbose | |
| cargo build --target i686-linux-android --release --bin file_classification_cli --features "$FEATURES" --verbose | |
| else | |
| cargo build --target armv7-linux-androideabi --release --bin file_classification_cli --verbose | |
| cargo build --target x86_64-linux-android --release --bin file_classification_cli --verbose | |
| cargo build --target i686-linux-android --release --bin file_classification_cli --verbose | |
| fi | |
| - name: Set Android binary name | |
| run: echo "ANDROID_BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload Android artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-android-aarch64 | |
| path: target/aarch64-linux-android/release/file_classification_cli | |
| - name: Upload other Android artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-android-armv7 | |
| path: target/armv7-linux-androideabi/release/file_classification_cli | |
| - name: Upload other Android artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-android-x86_64 | |
| path: target/x86_64-linux-android/release/file_classification_cli | |
| - name: Upload other Android artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-android-i686 | |
| path: target/i686-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: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - 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: Prepare features | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| FEATURES="${{ github.event.inputs.features }}" | |
| else | |
| FEATURES="sqlite-bundled" | |
| fi | |
| echo "FEATURES=$FEATURES" >> $GITHUB_ENV | |
| - name: Build CLI release binary | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| run: | | |
| if [ -n "$FEATURES" ]; then | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --features "$FEATURES" --verbose | |
| else | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose | |
| fi | |
| - name: Build WebAPI release binary | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }} | |
| run: | | |
| if [ -n "$FEATURES" ]; then | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --features "$FEATURES" --verbose | |
| else | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose | |
| fi | |
| - name: Set binary name | |
| run: echo "BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload CLI artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_cli | |
| - name: Upload WebAPI artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }} | |
| 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: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - 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: Prepare features | |
| run: | | |
| if ("${{ github.event_name }}" -eq "workflow_dispatch") { | |
| $env:FEATURES="${{ github.event.inputs.features }}" | |
| } else { | |
| $env:FEATURES="sqlite-bundled" | |
| } | |
| echo "FEATURES=$env:FEATURES" >> $env:GITHUB_ENV | |
| - name: Build CLI release binary | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| run: | | |
| if ( "${env:FEATURES}" -ne "" ) { | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --features "${env:FEATURES}" --verbose | |
| } else { | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose | |
| } | |
| - name: Build WebAPI release binary | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }} | |
| run: | | |
| if ( "${env:FEATURES}" -ne "" ) { | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --features "${env:FEATURES}" --verbose | |
| } else { | |
| 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 | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| 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 | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }} | |
| 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: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Install dependencies (macOS) | |
| run: | | |
| brew install sqlite3 | |
| - name: Prepare features | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| FEATURES="${{ github.event.inputs.features }}" | |
| else | |
| FEATURES="sqlite-bundled" | |
| fi | |
| echo "FEATURES=$FEATURES" >> $GITHUB_ENV | |
| - name: Build CLI release binary | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| run: | | |
| if [ -n "$FEATURES" ]; then | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --features "$FEATURES" --verbose | |
| else | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_cli --verbose | |
| fi | |
| - name: Build WebAPI release binary | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }} | |
| run: | | |
| if [ -n "$FEATURES" ]; then | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --features "$FEATURES" --verbose | |
| else | |
| cargo build --target ${{ matrix.target }} --release --bin file_classification_webapi --verbose | |
| fi | |
| - name: Set binary name | |
| run: echo "BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload CLI artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_cli | |
| - name: Upload WebAPI artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }} | |
| 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-aarch64/file_classification_cli | |
| artifacts/file_classification_cli-android-armv7/file_classification_cli | |
| artifacts/file_classification_cli-android-x86_64/file_classification_cli | |
| artifacts/file_classification_cli-android-i686/file_classification_cli |