Skip to content

Commit

Permalink
Setup CI and engine update workflow
Browse files Browse the repository at this point in the history
Multiple different things are happening here:

1. Checked-in pre-compiled engines replaced by the download logic.

Engine hash is stored in checked-in `.versions/engine` file and is
downloaded in `prepare` script. Pre-compiled engines are still part of
published npm package but they are no longer checked into the
repository. That also removes the need for LFS setup.

2. CI workflow for automated testing is setup

It is pretty much e2e test from prisma/prisma moved into this repository
instead. Build example app and runs simple integration test on both iOS
and Android emulator. It also fixes a bunch of linting failures present
in the repo.

3. CI workflow for automated updates of client, engines, and automated
   publishing of the package.

Polls npm on cron, if the update found on either `prisma@dev` or
`prisma@latest`, pulls in the new version, does update on the separate
temporary branch and runs aforementioned test on it. If the test is
succsful, branch is merged back into main and new `@prisma/react-native`
package is published with an identical version and npm tag.

Close prisma/team-orm#1106
  • Loading branch information
Sergey Tatarintsev committed Apr 30, 2024
1 parent 51c19a4 commit c28ee18
Show file tree
Hide file tree
Showing 46 changed files with 1,171 additions and 3,741 deletions.
4 changes: 1 addition & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
*.pbxproj -text
# specific for windows script files
*.bat text eol=crlf
QueryEngine.xcframework/ios-arm64/libquery_engine.a filter=lfs diff=lfs merge=lfs -text
QueryEngine.xcframework/ios-arm64_x86_64-simulator/libquery_engine.a filter=lfs diff=lfs merge=lfs -text
*.bat text eol=crlf
6 changes: 5 additions & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'yarn'

- name: Install dependencies
run: yarn install --immutable
shell: bash

- name: Prepare project checkout
run: yarn prepare
shell: bash
45 changes: 45 additions & 0 deletions .github/workflows/check-updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Check for a new client version
on:
schedule:
- cron: '*/5 * * * *'
workflow_dispatch:

jobs:
check-update:
runs-on: ubuntu-latest
outputs:
latest: ${{ steps.check-update.outputs.latest }}
dev: ${{ steps.check-update.outputs.dev }}
integration: ${{ steps.check-update.outputs.dev }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Check for updates
id: check-update
run: yarn check-updates

update-latest:
name: Update latest tag
needs:
- check-update
if: ${{ needs.check-update.outputs.latest != ''}}
uses: ./.github/workflows/update-and-publish.yml
secrets: inherit
with:
npmTag: latest
version: ${{ needs.check-update.outputs.latest }}

update-dev:
name: Update dev tag
needs:
- check-update
if: ${{ needs.check-update.outputs.dev != ''}}
uses: ./.github/workflows/update-and-publish.yml
secrets: inherit
with:
npmTag: dev
version: ${{ needs.check-update.outputs.dev }}
143 changes: 3 additions & 140 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,144 +8,7 @@ on:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Lint files
run: yarn lint

- name: Typecheck files
run: yarn typecheck

test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage

build-library:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: yarn prepare

build-android:
runs-on: ubuntu-latest
env:
TURBO_CACHE_DIR: .turbo/android
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for Android
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-android-
- name: Check turborepo cache for Android
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- name: Install JDK
if: env.turbo_cache_hit != 1
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Finalize Android SDK
if: env.turbo_cache_hit != 1
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
- name: Cache Gradle
if: env.turbo_cache_hit != 1
uses: actions/cache@v3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build example for Android
run: |
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
build-ios:
runs-on: macos-latest
env:
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for iOS
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-ios-
- name: Check turborepo cache for iOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- name: Cache cocoapods
if: env.turbo_cache_hit != 1
id: cocoapods-cache
uses: actions/cache@v3
with:
path: |
**/ios/Pods
key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-cocoapods-
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
yarn pod-install example/ios
env:
NO_FLIPPER: 1

- name: Build example for iOS
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
name: Run test
uses: ./.github/workflows/test.yml
secrets: inherit
108 changes: 108 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Test
on:
workflow_call:
inputs:
ref:
description: Ref to run the tests on
type: string
required: false

jobs:
lint-test:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Setup
uses: ./.github/actions/setup

- name: Lint files
run: yarn lint

- name: Typecheck files
run: yarn typecheck

test-ios:
name: E2E test for iOS
runs-on: macos-14
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Setup
uses: ./.github/actions/setup

- name: Install macOS dependencies
run: |
brew tap wix/brew
brew install applesimutils
env:
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1
- name: Install CocoaPods dependecies
working-directory: example
run: yarn pod-install

- name: Detox build
working-directory: example
run: yarn detox build --configuration ios.sim.release

- name: Detox test
working-directory: example
run: yarn detox test --configuration ios.sim.release --cleanup --headless

test-android:
name: E2E test for Android
runs-on: ubuntu-latest
steps:
# default runner has not enough space for creating emulators
- name: Free disk space
uses: jlumbroso/[email protected]
with:
android: false
tool-cache: true
dotnet: true
haskell: true
swap-storage: true
docker-images: true
large-packages: false

- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- name: Setup Java
uses: actions/setup-java@v3
with:
cache: gradle
distribution: temurin
java-version: 17

- name: Setup
uses: ./.github/actions/setup

- name: Detox build
working-directory: example
run: yarn detox build --configuration android.emu.release

- name: Enable KVM group perms # make android simulator use KVM and run much faster
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Detox test
uses: reactivecircus/android-emulator-runner@v2
with:
working-directory: example
api-level: 28
arch: x86_64
avd-name: Pixel_API_28
script: yarn detox test --configuration android.emu.release --headless
Loading

0 comments on commit c28ee18

Please sign in to comment.