Skip to content

Commit

Permalink
Merge branch 'chore/Update-package-dependencies' of https://github.co…
Browse files Browse the repository at this point in the history
…m/dotintent/react-native-ble-plx into chore/Update-package-dependencies
  • Loading branch information
dimninik committed Sep 25, 2023
2 parents ba38bb8 + 279a91f commit bb37438
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 18 deletions.
40 changes: 40 additions & 0 deletions .github/actions/setup_test_project/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Setup
description: Setup Node.js and install dependencies
inputs:
REACT_NATIVE_VERSION:
description: React Native version to use
required: false

runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc

- name: Initialize project template
run: npx react-native@latest init BlePlxExample --version ${{ inputs.REACT_NATIVE_VERSION }} --directory test_project --skip-install --verbose
shell: bash

- name: Cache dependencies
id: yarn-cache
uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-${{ inputs.REACT_NATIVE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-${{ inputs.REACT_NATIVE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }}
${{ runner.os }}-${{ inputs.REACT_NATIVE_VERSION }}-yarn-
- name: Copy project files
run: node ./scripts/copyExampleProjectFiles.js
shell: bash

- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
yarn install --cwd test_project
yarn install
shell: bash
47 changes: 30 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,32 @@ jobs:

build-android:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
react_native_version: ['0.72.4', ' 0.71.13', '0.70.13']
env:
TURBO_CACHE_DIR: .turbo/android
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup
uses: ./.github/actions/setup_test_project
with:
REACT_NATIVE_VERSION: ${{ matrix.react_native_version }}

- name: Cache turborepo for Android
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-${{ matrix.react_native_version }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-android-
${{ runner.os }}-${{ matrix.react_native_version }}-turborepo-android-
- name: Check turborepo cache for Android
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run test:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'test:android').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
Expand All @@ -93,36 +99,42 @@ jobs:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
key: ${{ runner.os }}-${{ matrix.react_native_version }}-gradle-${{ hashFiles('test_project/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
${{ runner.os }}-${{ matrix.react_native_version }}-gradle-
- name: Build example for Android
run: |
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
yarn turbo run test:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
build-ios:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
react_native_version: ['0.72.4', ' 0.71.13', '0.70.13']
env:
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup
uses: ./.github/actions/setup_test_project
with:
REACT_NATIVE_VERSION: ${{ matrix.react_native_version }}

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

- name: Build example for iOS
- name: Build test_project for iOS
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
yarn turbo run test:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ buck-out/

# Bundle artifact
*.jsbundle
/lib
/test_project
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v16
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"release": "release-it",
"example": "yarn --cwd example",
"build:android": "cd example/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
"test:android": "cd test_project/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
"build:ios": "cd example/ios && xcodebuild -workspace BlePlxExample.xcworkspace -scheme BlePlxExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO",
"test:ios": "cd test_project/ios && xcodebuild -workspace BlePlxExample.xcworkspace -scheme BlePlxExample -configuration Debug -sdk iphonesimulator ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO",
"bootstrap": "yarn example && yarn install && yarn example pods",
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
},
Expand Down
151 changes: 151 additions & 0 deletions scripts/copyExampleProjectFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
const path = require('path')
const fs = require('fs')

const TEST_PROJECT_DIR_NAME = '../test_project'
const EXAMPLE_PROJECT_DIR_NAME = '../example'

const indexJsPath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'index.js')
const indexJsDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'index.js')

const copyExampleProjectIndexJs = () => {
console.info('Deleting index.js from test_project')
fs.unlinkSync(indexJsDestinationPath)
console.info('Copying index.js from example to test_project')
fs.copyFileSync(indexJsPath, indexJsDestinationPath)
}

const jsSourceDirectory = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'src')
const jsSourceDestinationDirectory = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'src')

const copyExampleProjectJsFiles = () => {
console.info('Copying src from example to test_project')
fs.cpSync(jsSourceDirectory, jsSourceDestinationDirectory, { recursive: true })
}

const androidManifestPath = path.join(
__dirname,
EXAMPLE_PROJECT_DIR_NAME,
'android',
'app',
'src',
'main',
'AndroidManifest.xml'
)
const androidManifestDestinationPath = path.join(
__dirname,
TEST_PROJECT_DIR_NAME,
'android',
'app',
'src',
'main',
'AndroidManifest.xml'
)
const manifestPermissions = [
`<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />`,
`<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />`,
`<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />`,
`<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />`,
`<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />`
]

const addAndroidManifestPermissions = () => {
const destinationAndroidManifestLines = fs.readFileSync(androidManifestDestinationPath, 'utf8').split('\n')
const indexOfManifestTagEndLine = destinationAndroidManifestLines.findIndex(line => line.includes('>'))

console.info('Adding permissions to AndroidManifest.xml')
const joinedPermissions = manifestPermissions.join('\n')
destinationAndroidManifestLines.splice(indexOfManifestTagEndLine + 1, 0, joinedPermissions)

console.info('Writing new AndroidManifest.xml to test_project')
fs.writeFileSync(androidManifestDestinationPath, destinationAndroidManifestLines.join('\n'))
}

const packageJsonPath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'package.json')
const packageJsonDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'package.json')

const addMissingDependencies = () => {
const sourcePackageJson = require(packageJsonPath)
const editedPackageJson = require(packageJsonDestinationPath)

console.info('Checking for missing dependencies')
const missingDependencies = Object.keys(sourcePackageJson.dependencies).filter(
dependency => !editedPackageJson.dependencies[dependency]
)
const missingDevDependencies = Object.keys(sourcePackageJson.devDependencies).filter(
dependency => !editedPackageJson.devDependencies[dependency]
)

missingDependencies.forEach(dependency => {
editedPackageJson.dependencies[dependency] = sourcePackageJson.dependencies[dependency]
})
missingDevDependencies.forEach(dependency => {
editedPackageJson.devDependencies[dependency] = sourcePackageJson.devDependencies[dependency]
})

console.info('Writing new package.json to test_project')
fs.writeFileSync(packageJsonDestinationPath, JSON.stringify(editedPackageJson, null, 2) + '\n')
}

const metroDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'metro.config.js')
const metroSourcePath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'metro.config.js')

const copyMetroConfig = () => {
console.info('Deleting metro.config.js from test_project')
fs.unlinkSync(metroDestinationPath)
console.info('Copying metro.config.js from example to test_project')
fs.copyFileSync(metroSourcePath, metroDestinationPath)
}

const reactNativeDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'react-native.config.js')
const reactNativeSourcePath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'react-native.config.js')

const copyReactNativeConfig = () => {
const doesDestinationFileExist = fs.existsSync(reactNativeDestinationPath)

if (doesDestinationFileExist) {
console.info('Deleting react-native.config.js from test_project')
fs.unlinkSync(reactNativeDestinationPath)
}

console.info('Copying react-native.config.js from example to test_project')
fs.copyFileSync(reactNativeSourcePath, reactNativeDestinationPath)
}

const babelConfigDestinationPath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'babel.config.js')
const babelConfigSourcePath = path.join(__dirname, EXAMPLE_PROJECT_DIR_NAME, 'babel.config.js')

const copyBabelConfig = () => {
console.info('Deleting babel.config.js from test_project')
fs.unlinkSync(babelConfigDestinationPath)
console.info('Copying babel.config.js from example to test_project')
fs.copyFileSync(babelConfigSourcePath, babelConfigDestinationPath)
}

const changePackageJsonName = () => {
const packageJson = require(packageJsonDestinationPath)

packageJson.name = 'test_project'
fs.writeFileSync(packageJsonDestinationPath, JSON.stringify(packageJson, null, 2) + '\n')
}

const setMinSdkVersion = () => {
const gradlePath = path.join(__dirname, TEST_PROJECT_DIR_NAME, 'android', 'app', 'build.gradle')
const gradleLines = fs.readFileSync(gradlePath, 'utf8').split('\n')
const indexOfManifestTagEndLine = gradleLines.findIndex(line => line.includes('minSdkVersion'))
gradleLines[indexOfManifestTagEndLine] = 'minSdkVersion 23'
fs.writeFileSync(gradlePath, gradleLines.join('\n'))
}

const copyExampleProjectFiles = () => {
copyExampleProjectIndexJs()
copyExampleProjectJsFiles()
addAndroidManifestPermissions()
addMissingDependencies()
copyMetroConfig()
copyReactNativeConfig()
copyBabelConfig()
changePackageJsonName()
setMinSdkVersion()
}

copyExampleProjectFiles()
29 changes: 29 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
],
"outputs": []
},
"test:android":{
"inputs": [
"package.json",
"android",
"!android/build",
"src/*.ts",
"src/*.tsx",
"test_project/package.json",
"test_project/android",
"!test_project/android/.gradle",
"!test_project/android/build",
"!test_project/android/app/build"
],
"outputs": []
},
"build:ios": {
"inputs": [
"package.json",
Expand All @@ -29,6 +44,20 @@
"!example/ios/Pods"
],
"outputs": []
},
"test:ios": {
"inputs": [
"package.json",
"*.podspec",
"ios",
"src/*.ts",
"src/*.tsx",
"test_project/package.json",
"test_project/ios",
"!test_project/ios/build",
"!test_project/ios/Pods"
],
"outputs": []
}
}
}

0 comments on commit bb37438

Please sign in to comment.