Merge branch 'rust_new' of github.com:DataEraserC/FileClassificationS… #86
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 | |
| matrix: | |
| target: | |
| - aarch64-linux-android | |
| - armv7-linux-androideabi | |
| - x86_64-linux-android | |
| - i686-linux-android | |
| 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 NDK | |
| uses: nttld/setup-ndk@v1 | |
| with: | |
| ndk-version: r25b | |
| - name: Install cargo-ndk | |
| run: cargo install cargo-ndk --locked | |
| - name: Install Android targets | |
| run: | | |
| rustup target add aarch64-linux-android | |
| rustup target add armv7-linux-androideabi | |
| rustup target add x86_64-linux-android | |
| rustup target add i686-linux-android | |
| - name: Install SQLite development headers | |
| 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 target | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_cli == 'true' }} | |
| run: | | |
| if [ -n "$FEATURES" ]; then | |
| cargo ndk --target ${{ matrix.target }} --platform 21 -- build --release --bin file_classification_cli --features "$FEATURES" --verbose | |
| else | |
| cargo ndk --target ${{ matrix.target }} --platform 21 -- build --release --bin file_classification_cli --verbose | |
| fi | |
| - name: Build WebAPI for Android target | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }} | |
| run: | | |
| if [ -n "$FEATURES" ]; then | |
| cargo ndk --target ${{ matrix.target }} --platform 21 -- build --release --bin file_classification_webapi --features "$FEATURES" --verbose | |
| else | |
| cargo ndk --target ${{ matrix.target }} --platform 21 -- build --release --bin file_classification_webapi --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-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_cli | |
| - name: Upload Android WebAPI artifacts | |
| if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.build_webapi == 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_webapi-android-${{ matrix.target }} | |
| path: target/${{ matrix.target }}/release/file_classification_webapi | |
| 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-linux-android/file_classification_cli | |
| artifacts/file_classification_cli-android-armv7-linux-androideabi/file_classification_cli | |
| artifacts/file_classification_cli-android-x86_64-linux-android/file_classification_cli | |
| artifacts/file_classification_cli-android-i686-linux-android/file_classification_cli | |
| artifacts/file_classification_webapi-android-aarch64-linux-android/file_classification_webapi | |
| artifacts/file_classification_webapi-android-armv7-linux-androideabi/file_classification_webapi | |
| artifacts/file_classification_webapi-android-x86_64-linux-android/file_classification_webapi | |
| artifacts/file_classification_webapi-android-i686-linux-android/file_classification_webapi |