Skip to content

Commit

Permalink
feat: build ios and android example apps on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 4, 2023
1 parent c69d9b3 commit 325b7ca
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 20 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ jobs:
--repo-url https://test.test \
--type ${{ matrix.type }} \
--languages ${{ matrix.language }} \
--turborepo
- name: Cache dependencies of library
id: library-yarn-cache
Expand Down
15 changes: 1 addition & 14 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const FALLBACK_BOB_VERSION = '0.20.0';
const BINARIES = /(gradlew|\.(jar|keystore|png|jpg|gif))$/;

const COMMON_FILES = path.resolve(__dirname, '../templates/common');
const TURBOREPO_FILES = path.resolve(__dirname, '../templates/turborepo');
const JS_FILES = path.resolve(__dirname, '../templates/js-library');
const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');
Expand Down Expand Up @@ -80,8 +79,7 @@ type ArgName =
| 'repo-url'
| 'languages'
| 'type'
| 'react-native-version'
| 'turborepo';
| 'react-native-version';

type ProjectLanguages =
| 'java-objc'
Expand Down Expand Up @@ -110,7 +108,6 @@ type Answers = {
languages: ProjectLanguages;
type?: ProjectType;
reactNativeVersion?: string;
turborepo?: boolean;
};

const LANGUAGE_CHOICES: {
Expand Down Expand Up @@ -246,10 +243,6 @@ const args: Record<ArgName, yargs.Options> = {
description: 'Version of React Native to use, uses latest if not specified',
type: 'string',
},
'turborepo': {
description: 'Whether to configure Turborepo for the project',
type: 'boolean',
},
};

async function create(argv: yargs.Arguments<any>) {
Expand Down Expand Up @@ -455,7 +448,6 @@ async function create(argv: yargs.Arguments<any>) {
type = 'module-mixed',
languages = type === 'library' ? 'js' : 'java-objc',
reactNativeVersion,
turborepo,
} = {
...argv,
...(await prompts(
Expand Down Expand Up @@ -582,7 +574,6 @@ async function create(argv: yargs.Arguments<any>) {
},
repo: repoUrl,
example,
turborepo,
year: new Date().getFullYear(),
};

Expand Down Expand Up @@ -645,10 +636,6 @@ async function create(argv: yargs.Arguments<any>) {

await copyDir(COMMON_FILES, folder);

if (turborepo) {
await copyDir(TURBOREPO_FILES, folder);
}

if (languages === 'js') {
await copyDir(JS_FILES, folder);
await copyDir(EXPO_FILES, folder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage

build:
build-library:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -46,3 +46,101 @@ jobs:

- name: Build package
run: yarn prepack

<% if (project.native) { -%>
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: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Finalize Android SDK
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
- 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 }}-library-turborepo-android-
- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}

- 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 }}-library-turborepo-ios-
- name: Cache cocoapods
id: cocoapods-cache
uses: actions/cache@v3
with:
path: |
**/ios/Pods
**/ios/Podfile.lock
key: ${{ runner.os }}-cocoapods-${{ hashFiles('**/Podfile') }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-cocoapods-${{ hashFiles('**/Podfile') }}-
${{ runner.os }}-cocoapods-
- name: Install cocoapods
if: steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
yarn example pods
env:
NO_FLIPPER: 1

- name: Build example (iOS)
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
<% } else { -%>
build-web:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

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

- name: Build example for Web
run: |
yarn example expo export:web
<% } -%>
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
"prepack": "bob build",
"release": "release-it",
"example": "yarn --cwd example",
<% if (example === 'native' && turborepo) { -%>
<% if (example === 'native') { -%>
"build:android": "cd example/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
"build:ios": "cd example/ios && xcodebuild -workspace <%- project.name %>Example.xcworkspace -scheme <%- project.name %>Example -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",
<% } -%>
<% if (example === 'native') { -%>
"bootstrap": "yarn example && yarn install && yarn example pods",
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
<% } else { -%>
Expand Down Expand Up @@ -79,7 +77,7 @@
"react-native": "0.70.0",
"react-native-builder-bob": "^<%- bob.version %>",
"release-it": "^15.0.0",
<% if (turborepo) { -%>
<% if (example === 'native') { -%>
"turbo": "^1.10.7",
<% } -%>
"typescript": "^5.0.2"
Expand Down

0 comments on commit 325b7ca

Please sign in to comment.