Set up GitHub Actions for CI/CD and multi-platform releases #3
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/CD Pipeline | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ['v*'] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| build-and-test: | |
| name: Build & Test | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| include: | |
| - os: ubuntu-latest | |
| target: wasm32-unknown-unknown | |
| platform: web | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| platform: desktop | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| platform: desktop | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Install Rust toolchain | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| profile: minimal | |
| toolchain: stable | |
| override: true | |
| target: ${{ matrix.target }} | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| opensvm-dioxus/target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: ${{ runner.os }}-cargo- | |
| - name: Install Dioxus CLI | |
| uses: actions-rs/cargo@v1 | |
| with: | |
| command: install | |
| args: dioxus-cli --force | |
| - 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: Install wasm-bindgen-cli | |
| if: matrix.platform == 'web' | |
| uses: actions-rs/cargo@v1 | |
| with: | |
| command: install | |
| args: wasm-bindgen-cli | |
| - name: Install wasm-opt | |
| if: matrix.platform == 'web' | |
| run: | | |
| if [ "$RUNNER_OS" == "Linux" ]; then | |
| curl -L https://github.com/WebAssembly/binaryen/releases/download/version_111/binaryen-version_111-x86_64-linux.tar.gz | tar xz | |
| sudo cp binaryen-version_111/bin/wasm-opt /usr/local/bin/ | |
| elif [ "$RUNNER_OS" == "macOS" ]; then | |
| brew install binaryen | |
| else | |
| choco install binaryen | |
| fi | |
| shell: bash | |
| - name: Build for Web | |
| if: matrix.platform == 'web' | |
| run: | | |
| cd opensvm-dioxus | |
| dioxus build --features web --profile wasm-release --platform web --release | |
| - name: Build for Desktop (macOS/Linux) | |
| if: matrix.platform == 'desktop' && matrix.os != 'windows-latest' | |
| run: | | |
| cd opensvm-dioxus | |
| RUSTFLAGS="-C target-cpu=native" dioxus build --features desktop --profile desktop-release --platform desktop --release | |
| shell: bash | |
| - name: Build for Desktop (Windows) | |
| if: matrix.platform == 'desktop' && matrix.os == 'windows-latest' | |
| run: | | |
| cd opensvm-dioxus | |
| $env:RUSTFLAGS="-C target-cpu=native" | |
| dioxus build --features desktop --profile desktop-release --platform desktop --release | |
| shell: pwsh | |
| - name: Run tests | |
| run: | | |
| cd opensvm-dioxus | |
| cargo test --all-features | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: opensvm-dioxus-${{ matrix.os }}-${{ matrix.platform }} | |
| path: | | |
| opensvm-dioxus/dist/ | |
| release: | |
| name: Create Release | |
| needs: build-and-test | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v3 | |
| with: | |
| path: artifacts | |
| - name: Prepare release assets | |
| run: | | |
| mkdir -p release-assets | |
| # Web (WASM) | |
| if [ -d "artifacts/opensvm-dioxus-ubuntu-latest-web/web" ]; then | |
| cd artifacts/opensvm-dioxus-ubuntu-latest-web/web | |
| zip -r ../../../release-assets/opensvm-dioxus-web.zip . | |
| cd ../../.. | |
| fi | |
| # macOS | |
| if [ -d "artifacts/opensvm-dioxus-macos-latest-desktop/desktop" ]; then | |
| cd artifacts/opensvm-dioxus-macos-latest-desktop/desktop | |
| zip -r ../../../release-assets/opensvm-dioxus-macos.zip . | |
| cd ../../.. | |
| fi | |
| # Windows | |
| if [ -d "artifacts/opensvm-dioxus-windows-latest-desktop/desktop" ]; then | |
| cd artifacts/opensvm-dioxus-windows-latest-desktop/desktop | |
| zip -r ../../../release-assets/opensvm-dioxus-windows.zip . | |
| cd ../../.. | |
| fi | |
| shell: bash | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: release-assets/* | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| homebrew: | |
| name: Update Homebrew Formula | |
| needs: release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Git | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| - name: Download macOS artifact | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: opensvm-dioxus-macos-latest-desktop | |
| path: macos-artifact | |
| - name: Create Homebrew Formula | |
| run: | | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/v${VERSION}/opensvm-dioxus-macos.zip" | |
| # Calculate SHA256 | |
| curl -L -o opensvm-dioxus-macos.zip "$DOWNLOAD_URL" | |
| SHA256=$(shasum -a 256 opensvm-dioxus-macos.zip | awk '{print $1}') | |
| # Create formula directory if it doesn't exist | |
| mkdir -p Formula | |
| # Create or update formula file | |
| cat > Formula/opensvm-dioxus.rb << EOF | |
| class OpensvmDioxus < Formula | |
| desc "OpenSVM Dioxus application for Solana blockchain ecosystem" | |
| homepage "https://github.com/${{ github.repository }}" | |
| url "$DOWNLOAD_URL" | |
| sha256 "$SHA256" | |
| version "$VERSION" | |
| def install | |
| libexec.install Dir["*"] | |
| bin.install_symlink libexec/"opensvm-dioxus" | |
| end | |
| end | |
| EOF | |
| # Create a new branch | |
| git checkout -b update-homebrew-formula-v$VERSION | |
| # Commit and push changes | |
| git add Formula/opensvm-dioxus.rb | |
| git commit -m "Update Homebrew formula to v$VERSION" | |
| git push origin update-homebrew-formula-v$VERSION | |
| # Create pull request | |
| gh pr create --title "Update Homebrew formula to v$VERSION" --body "Updates the Homebrew formula for opensvm-dioxus to version $VERSION" --base main --head update-homebrew-formula-v$VERSION | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| android-build: | |
| name: Build Android | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Install Rust toolchain | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| profile: minimal | |
| toolchain: stable | |
| override: true | |
| target: aarch64-linux-android | |
| - name: Install Android SDK | |
| uses: android-actions/setup-android@v2 | |
| - name: Install Dioxus CLI | |
| uses: actions-rs/cargo@v1 | |
| with: | |
| command: install | |
| args: dioxus-cli --force | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| opensvm-dioxus/target | |
| key: android-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: android-cargo- | |
| - name: Build for Android | |
| run: | | |
| cd opensvm-dioxus | |
| RUSTFLAGS="-C opt-level=3 -C lto=thin" dioxus build --features android --platform android --release | |
| - name: Optimize APK | |
| run: | | |
| cd opensvm-dioxus/dist/android | |
| $ANDROID_HOME/build-tools/33.0.0/zipalign -v -p 4 app-release-unsigned.apk app-release-aligned.apk | |
| $ANDROID_HOME/build-tools/33.0.0/apksigner sign --ks debug.keystore --ks-pass pass:android --key-pass pass:android --out opensvm-dioxus.apk app-release-aligned.apk | |
| - name: Upload Android artifact | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: opensvm-dioxus-android | |
| path: opensvm-dioxus/dist/android/opensvm-dioxus.apk | |
| - name: Add Android APK to release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: opensvm-dioxus/dist/android/opensvm-dioxus.apk | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |