Setup CI for opensvm-dioxus #2
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: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| release: | |
| types: [published] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| # Build and test on multiple platforms | |
| build-and-test: | |
| name: Build & Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: wasm32-unknown-unknown | |
| - name: Cache Rust dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: opensvm-dioxus | |
| - name: Install wasm-pack | |
| uses: jetli/[email protected] | |
| - name: Install Dioxus CLI | |
| run: cargo install dioxus-cli --locked | |
| - name: Build (Debug) | |
| working-directory: opensvm-dioxus | |
| run: cargo build | |
| - name: Run tests | |
| working-directory: opensvm-dioxus | |
| run: cargo test | |
| # Build for web (WASM) with optimizations | |
| build-web: | |
| name: Build Web | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.event_name == 'release' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: wasm32-unknown-unknown | |
| - name: Cache Rust dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: opensvm-dioxus | |
| - name: Install wasm-pack | |
| uses: jetli/[email protected] | |
| - name: Install Dioxus CLI | |
| run: cargo install dioxus-cli --locked | |
| - name: Install wasm-opt | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y binaryen | |
| - name: Install js-minifier | |
| run: npm install -g terser | |
| - name: Build for web (with optimizations) | |
| working-directory: opensvm-dioxus | |
| run: | | |
| # Build using the wasm-release profile optimized for size | |
| RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+simd128" \ | |
| dioxus build --features web --profile wasm-release --platform web --release | |
| # Additional optimization with wasm-opt for smaller binary size | |
| find dist -name "*.wasm" -exec wasm-opt -Oz -o {} {} \; | |
| # Minify JavaScript files | |
| find dist -name "*.js" -exec terser --compress --mangle -o {} {} \; | |
| - name: Package web build | |
| working-directory: opensvm-dioxus | |
| run: | | |
| cd dist | |
| zip -r ../opensvm-dioxus-web.zip . | |
| - name: Upload web artifacts | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: web-build | |
| path: opensvm-dioxus/opensvm-dioxus-web.zip | |
| # Build for desktop platforms | |
| build-desktop: | |
| name: Build Desktop (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| needs: build-and-test | |
| if: github.event_name == 'release' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| artifact_name: opensvm-dioxus-linux-x86_64 | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| artifact_name: opensvm-dioxus-macos-x86_64 | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| artifact_name: opensvm-dioxus-macos-aarch64 | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| artifact_name: opensvm-dioxus-windows-x86_64.exe | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Cache Rust dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: opensvm-dioxus | |
| - name: Install Dioxus CLI | |
| run: cargo install dioxus-cli --locked | |
| - name: Install Linux dependencies | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf | |
| - name: Build desktop app with optimizations | |
| working-directory: opensvm-dioxus | |
| run: | | |
| # Install additional dependency for desktop optimizations | |
| cargo add num_cpus --features | |
| # Build with desktop-specific optimizations | |
| RUSTFLAGS="-C target-cpu=native -C opt-level=3 -C lto=fat" \ | |
| dioxus build --features desktop --profile desktop-release --release --platform desktop --target ${{ matrix.target }} | |
| - name: Rename binary (Linux/macOS) | |
| if: matrix.os != 'windows-latest' | |
| working-directory: opensvm-dioxus | |
| run: | | |
| mv target/${{ matrix.target }}/release/opensvm-dioxus ${{ matrix.artifact_name }} | |
| - name: Rename binary (Windows) | |
| if: matrix.os == 'windows-latest' | |
| working-directory: opensvm-dioxus | |
| shell: pwsh | |
| run: | | |
| Move-Item -Path target\${{ matrix.target }}\release\opensvm-dioxus.exe -Destination ${{ matrix.artifact_name }} | |
| - name: Upload desktop artifacts | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: ${{ matrix.artifact_name }} | |
| path: opensvm-dioxus/${{ matrix.artifact_name }} | |
| # Build for Android | |
| build-android: | |
| name: Build Android | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.event_name == 'release' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: aarch64-linux-android, armv7-linux-androideabi, x86_64-linux-android, i686-linux-android | |
| - name: Cache Rust dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: opensvm-dioxus | |
| - name: Install Dioxus CLI | |
| run: cargo install dioxus-cli --locked | |
| - name: Setup Android SDK | |
| uses: android-actions/setup-android@v2 | |
| - name: Install cargo-ndk | |
| run: cargo install cargo-ndk | |
| - name: Install Android-specific dependencies | |
| run: | | |
| cargo add num_cpus --features | |
| - name: Build for Android with optimizations | |
| working-directory: opensvm-dioxus | |
| run: | | |
| # Build with Android-specific optimizations | |
| RUSTFLAGS="-C opt-level=3 -C lto=thin -C codegen-units=1" \ | |
| dioxus build --features android --release --platform android | |
| # Apply additional APK optimizations using Android build tools | |
| cd target/release/apk | |
| find . -name "*.apk" -exec echo "Optimizing {}" \; -exec zipalign -v -p 4 {} {}.aligned \; -exec mv {}.aligned {} \; | |
| # Sign APK with debug key for testing - in production you would use your release keystore | |
| find . -name "*.apk" -exec echo "Signing {}" \; -exec $ANDROID_SDK_ROOT/build-tools/*/apksigner sign --ks ~/.android/debug.keystore --ks-pass pass:android --key-pass pass:android {} \; | |
| - name: Upload Android APK | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: android-apk | |
| path: opensvm-dioxus/target/release/apk/*.apk | |
| # Create GitHub release with all artifacts | |
| create-release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| needs: [build-web, build-desktop, build-android] | |
| if: github.event_name == 'release' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v3 | |
| with: | |
| path: artifacts | |
| - name: List artifacts | |
| run: find artifacts -type f | |
| - name: Upload release assets | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| artifacts/web-build/opensvm-dioxus-web.zip | |
| artifacts/opensvm-dioxus-linux-x86_64/opensvm-dioxus-linux-x86_64 | |
| artifacts/opensvm-dioxus-macos-x86_64/opensvm-dioxus-macos-x86_64 | |
| artifacts/opensvm-dioxus-macos-aarch64/opensvm-dioxus-macos-aarch64 | |
| artifacts/opensvm-dioxus-windows-x86_64.exe/opensvm-dioxus-windows-x86_64.exe | |
| artifacts/android-apk/*.apk | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Create and publish Homebrew formula | |
| homebrew: | |
| name: Update Homebrew Formula | |
| runs-on: macos-latest | |
| needs: create-release | |
| if: github.event_name == 'release' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download macOS artifacts | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: opensvm-dioxus-macos-x86_64 | |
| path: artifacts/macos-x86_64 | |
| - name: Download macOS ARM artifacts | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: opensvm-dioxus-macos-aarch64 | |
| path: artifacts/macos-aarch64 | |
| - name: Set up Homebrew | |
| uses: Homebrew/actions/setup-homebrew@master | |
| - name: Create Homebrew Formula | |
| run: | | |
| # Get the version from the release tag | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| # Create the formula directory if it doesn't exist | |
| mkdir -p Formula | |
| # Calculate SHA256 checksums for the binaries | |
| SHA256_X86_64=$(shasum -a 256 artifacts/macos-x86_64/opensvm-dioxus-macos-x86_64 | awk '{print $1}') | |
| SHA256_AARCH64=$(shasum -a 256 artifacts/macos-aarch64/opensvm-dioxus-macos-aarch64 | awk '{print $1}') | |
| # Create the formula file | |
| cat > Formula/opensvm-dioxus.rb << EOF | |
| class OpensvmDioxus < Formula | |
| desc "OpenSVM Dioxus application" | |
| homepage "https://github.com/openSVM/opensvm-mobile" | |
| version "${VERSION}" | |
| license "MIT" | |
| on_macos do | |
| on_arm do | |
| url "https://github.com/openSVM/opensvm-mobile/releases/download/v${VERSION}/opensvm-dioxus-macos-aarch64" | |
| sha256 "${SHA256_AARCH64}" | |
| end | |
| on_intel do | |
| url "https://github.com/openSVM/opensvm-mobile/releases/download/v${VERSION}/opensvm-dioxus-macos-x86_64" | |
| sha256 "${SHA256_X86_64}" | |
| end | |
| end | |
| def install | |
| if Hardware::CPU.arm? | |
| bin.install "opensvm-dioxus-macos-aarch64" => "opensvm-dioxus" | |
| else | |
| bin.install "opensvm-dioxus-macos-x86_64" => "opensvm-dioxus" | |
| end | |
| end | |
| test do | |
| system "#{bin}/opensvm-dioxus", "--version" | |
| end | |
| end | |
| EOF | |
| - name: Set up Git | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| - name: Create Homebrew tap repository | |
| run: | | |
| # Create a new tap repository or clone existing one | |
| mkdir -p $(brew --repository)/Library/Taps/opensvm | |
| cd $(brew --repository)/Library/Taps/opensvm | |
| # Check if the tap repository already exists | |
| if [ -d "homebrew-opensvm" ]; then | |
| cd homebrew-opensvm | |
| git pull | |
| else | |
| # Create a new repository | |
| gh repo create opensvm/homebrew-opensvm --public --clone | |
| cd homebrew-opensvm | |
| fi | |
| # Copy the formula file | |
| cp $GITHUB_WORKSPACE/Formula/opensvm-dioxus.rb Formula/ | |
| # Commit and push changes | |
| git add Formula/opensvm-dioxus.rb | |
| git commit -m "Update opensvm-dioxus to ${VERSION}" | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |