name: Build & publish @tursodatabase/sync-react-native on: workflow_dispatch: push: branches: - main tags: - v* pull_request: env: CARGO_INCREMENTAL: "0" CARGO_NET_RETRY: 10 working-directory: bindings/react-native concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: build-ios: name: Build iOS libraries runs-on: blacksmith-6vcpu-macos-latest timeout-minutes: 30 steps: - uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: targets: aarch64-apple-ios,aarch64-apple-ios-sim - name: Rust cache uses: Swatinem/rust-cache@v2 with: prefix-key: "v1-rust-ios" cache-on-failure: true save-if: ${{ github.ref == 'refs/heads/main' }} # The release profile uses thin LTO, meant for the packages published # from tags. Pull requests only need to know the libraries build. - name: Use a faster build profile on pull requests if: github.event_name == 'pull_request' run: echo "CARGO_PROFILE_RELEASE_LTO=false" >> "$GITHUB_ENV" - name: Build iOS libraries run: make ios-build working-directory: ${{ env.working-directory }} - name: Package iOS xcframework run: make package-dylibs working-directory: ${{ env.working-directory }} - name: Upload iOS artifacts uses: actions/upload-artifact@v4 with: name: ios-libs path: | bindings/react-native/libs/ios/ if-no-files-found: error # One job per Android architecture, run in parallel; the publish job # merges their outputs into libs/android. build-android: name: Build Android libraries (${{ matrix.abi }}) runs-on: blacksmith-4vcpu-ubuntu-2404 timeout-minutes: 30 strategy: fail-fast: false matrix: include: - target: aarch64-linux-android abi: arm64-v8a - target: armv7-linux-androideabi abi: armeabi-v7a - target: x86_64-linux-android abi: x86_64 - target: i686-linux-android abi: x86 steps: - uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - name: Rust cache uses: Swatinem/rust-cache@v2 with: prefix-key: "v1-rust-android" key: ${{ matrix.target }} cache-on-failure: true save-if: ${{ github.ref == 'refs/heads/main' }} - name: Set up Android NDK uses: android-actions/setup-android@v3 with: packages: '' - name: Install cargo-ndk run: cargo install cargo-ndk # The release profile uses thin LTO, meant for the packages published # from tags. Pull requests only need to know the libraries build. - name: Use a faster build profile on pull requests if: github.event_name == 'pull_request' run: echo "CARGO_PROFILE_RELEASE_LTO=false" >> "$GITHUB_ENV" - name: Build Android library run: make android-arch TARGET=${{ matrix.target }} ABI=${{ matrix.abi }} working-directory: ${{ env.working-directory }} - name: Upload Android artifacts uses: actions/upload-artifact@v4 with: name: android-libs-${{ matrix.abi }} path: | bindings/react-native/libs/android/ if-no-files-found: error build-typescript: name: Build TypeScript runs-on: ubuntu-latest timeout-minutes: 10 steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v5 with: node-version: 24 - name: Install dependencies run: npm install working-directory: ${{ env.working-directory }} - name: Build TypeScript run: npm run build working-directory: ${{ env.working-directory }} - name: Type check run: npm run typescript working-directory: ${{ env.working-directory }} - name: Upload TypeScript build uses: actions/upload-artifact@v4 with: name: typescript-build path: | bindings/react-native/lib/ if-no-files-found: error build-example-ios: name: Build example app (iOS) runs-on: blacksmith-6vcpu-macos-latest timeout-minutes: 45 needs: - build-ios - build-typescript steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v5 with: node-version: 24 - name: Setup Ruby uses: ruby/setup-ruby@v1 with: ruby-version: '3.2' bundler-cache: true working-directory: examples/react-native - name: Download iOS artifacts uses: actions/download-artifact@v4 with: name: ios-libs path: bindings/react-native/libs/ios/ - name: Fix xcframework after artifact download run: | find bindings/react-native/libs/ios/turso-sync-sdk-kit.xcframework \ -name "turso-sync-sdk-kit" -type f | while read f; do chmod +x "$f" codesign -f -s - "$f" done - name: Download TypeScript build uses: actions/download-artifact@v4 with: name: typescript-build path: bindings/react-native/lib/ - name: Install binding dependencies run: npm install working-directory: ${{ env.working-directory }} - name: Install example app dependencies run: npm install working-directory: examples/react-native - name: Install CocoaPods dependencies run: bundle exec pod install working-directory: examples/react-native/ios - name: Verify xcframework run: | ls -la bindings/react-native/libs/ios/turso-sync-sdk-kit.xcframework/ios-arm64-simulator/turso-sync-sdk-kit.framework/ file bindings/react-native/libs/ios/turso-sync-sdk-kit.xcframework/ios-arm64-simulator/turso-sync-sdk-kit.framework/turso-sync-sdk-kit - name: Build iOS example app run: | xcodebuild build \ -workspace TursoExample.xcworkspace \ -scheme TursoExample \ -sdk iphonesimulator \ -destination 'generic/platform=iOS Simulator' \ -configuration Debug \ CODE_SIGNING_ALLOWED=NO \ ARCHS=arm64 \ ONLY_ACTIVE_ARCH=YES working-directory: examples/react-native/ios publish: name: Publish to npm runs-on: ubuntu-latest timeout-minutes: 15 needs: - build-ios - build-android - build-typescript - build-example-ios permissions: contents: read id-token: write steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v5 with: node-version: 24 - name: Update npm run: npm install -g npm@11 - name: Download iOS artifacts uses: actions/download-artifact@v4 with: name: ios-libs path: bindings/react-native/libs/ios/ # One artifact per architecture; each holds libs/android// plus the # same two headers, so merging them rebuilds the full libs/android. - name: Download Android artifacts uses: actions/download-artifact@v4 with: pattern: android-libs-* merge-multiple: true path: bindings/react-native/libs/android/ - name: Download TypeScript build uses: actions/download-artifact@v4 with: name: typescript-build path: bindings/react-native/lib/ - name: Install dependencies run: npm install working-directory: ${{ env.working-directory }} - name: List package contents run: | echo "=== Package contents ===" ls -la echo "=== libs/ios ===" ls -laR libs/ios/ || echo "No iOS libs" echo "=== libs/android ===" ls -laR libs/android/ || echo "No Android libs" echo "=== lib (TypeScript) ===" ls -laR lib/ || echo "No lib" working-directory: ${{ env.working-directory }} - name: Publish if: startsWith(github.ref, 'refs/tags/v') run: | if git log -1 --pretty=%B | grep "^Turso [0-9]\+\.[0-9]\+\.[0-9]\+$"; then npm publish --access public --provenance elif git log -1 --pretty=%B | grep "^Turso [0-9]\+\.[0-9]\+\.[0-9]\+"; then npm publish --access public --provenance --tag next else echo "git log structure is unexpected, skip publishing" npm publish --dry-run fi working-directory: ${{ env.working-directory }} - name: Publish (dry-run) if: ${{ !startsWith(github.ref, 'refs/tags/v') }} run: npm pack working-directory: ${{ env.working-directory }} - name: Upload package tarball if: ${{ !startsWith(github.ref, 'refs/tags/v') }} uses: actions/upload-artifact@v4 with: name: npm-package path: bindings/react-native/*.tgz