Skip to content

Commit f694d0b

Browse files
committed
chore: add caching for android builds with turborepo
1 parent 27014b7 commit f694d0b

File tree

8 files changed

+75
-10
lines changed

8 files changed

+75
-10
lines changed

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
with:
1010
node-version: 16.x
1111

12-
- name: Restore yarn cache
12+
- name: Cache dependencies
1313
id: yarn-cache
1414
uses: actions/cache@v3
1515
with:

.github/workflows/build-templates.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ jobs:
7878
--author-url https://test.test \
7979
--repo-url https://test.test \
8080
--type ${{ matrix.type }} \
81-
--languages ${{ matrix.language }}
81+
--languages ${{ matrix.language }} \
82+
--turborepo
8283
8384
echo "work_dir=$WORK_DIR" >> $GITHUB_ENV
8485
@@ -93,6 +94,7 @@ jobs:
9394
with:
9495
path: |
9596
${{ env.work_dir }}/**/node_modules
97+
${{ env.work_dir }}/**/yarn.lock
9698
key: ${{ runner.os }}-library-yarn-${{ hashFiles(format('{0}/**/package.json', env.work_dir)) }}
9799
restore-keys: |
98100
${{ runner.os }}-library-yarn-
@@ -103,6 +105,15 @@ jobs:
103105
run: |
104106
yarn
105107
108+
- name: Cache turborepo
109+
uses: actions/cache@v3
110+
with:
111+
path: |
112+
${{ env.work_dir }}/.turbo
113+
key: ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
114+
restore-keys: |
115+
${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-
116+
106117
- name: Lint library
107118
working-directory: ${{ env.work_dir }}
108119
run: |
@@ -130,6 +141,7 @@ jobs:
130141
uses: nttld/setup-ndk@v1
131142
with:
132143
ndk-version: r21d
144+
local-cache: true
133145

134146
- name: Set ANDROID_NDK
135147
if: env.build_android == 1
@@ -166,5 +178,4 @@ jobs:
166178
if: env.build_android == 1
167179
working-directory: ${{ env.work_dir }}
168180
run: |
169-
cd example/android
170-
./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a
181+
yarn turbo run build:android --cache-dir=".turbo/cache"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"url": "git+https://github.com/react-navigation/react-navigation.git"
1111
},
1212
"engines": {
13-
"node": ">= 10.0.0"
13+
"node": ">= 16.0.0"
1414
},
15+
"packageManager": "^[email protected]",
1516
"scripts": {
1617
"lint": "eslint \"**/*.{js,ts,tsx}\"",
1718
"typescript": "tsc --noEmit",

packages/create-react-native-library/src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const FALLBACK_BOB_VERSION = '0.20.0';
1616
const BINARIES = /(gradlew|\.(jar|keystore|png|jpg|gif))$/;
1717

1818
const COMMON_FILES = path.resolve(__dirname, '../templates/common');
19+
const TURBOREPO_FILES = path.resolve(__dirname, '../templates/turborepo');
1920
const JS_FILES = path.resolve(__dirname, '../templates/js-library');
2021
const EXPO_FILES = path.resolve(__dirname, '../templates/expo-library');
2122
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');
@@ -73,7 +74,8 @@ type ArgName =
7374
| 'repo-url'
7475
| 'languages'
7576
| 'type'
76-
| 'react-native-version';
77+
| 'react-native-version'
78+
| 'turborepo';
7779

7880
type ProjectLanguages =
7981
| 'java-objc'
@@ -102,6 +104,7 @@ type Answers = {
102104
languages: ProjectLanguages;
103105
type?: ProjectType;
104106
reactNativeVersion?: string;
107+
turborepo?: boolean;
105108
};
106109

107110
const LANGUAGE_CHOICES: {
@@ -237,6 +240,10 @@ const args: Record<ArgName, yargs.Options> = {
237240
description: 'Version of React Native to use, uses latest if not specified',
238241
type: 'string',
239242
},
243+
'turborepo': {
244+
description: 'Whether to configure Turborepo for the project',
245+
type: 'boolean',
246+
},
240247
};
241248

242249
async function create(argv: yargs.Arguments<any>) {
@@ -442,6 +449,7 @@ async function create(argv: yargs.Arguments<any>) {
442449
type = 'module-mixed',
443450
languages = type === 'library' ? 'js' : 'java-objc',
444451
reactNativeVersion,
452+
turborepo,
445453
} = {
446454
...argv,
447455
...(await prompts(
@@ -568,6 +576,7 @@ async function create(argv: yargs.Arguments<any>) {
568576
},
569577
repo: repoUrl,
570578
example,
579+
turborepo,
571580
};
572581

573582
const copyDir = async (source: string, dest: string) => {
@@ -629,6 +638,10 @@ async function create(argv: yargs.Arguments<any>) {
629638

630639
await copyDir(COMMON_FILES, folder);
631640

641+
if (turborepo) {
642+
await copyDir(TURBOREPO_FILES, folder);
643+
}
644+
632645
if (languages === 'js') {
633646
await copyDir(JS_FILES, folder);
634647
await copyDir(EXPO_FILES, folder);

packages/create-react-native-library/templates/common/$.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
with:
1010
node-version: 16.x
1111

12-
- name: Restore yarn cache
12+
- name: Cache dependencies
1313
id: yarn-cache
1414
uses: actions/cache@v3
1515
with:

packages/create-react-native-library/templates/common/$.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ android/app/libs
6161
android/keystores/debug.keystore
6262

6363
# Expo
64-
.expo/*
64+
.expo/
65+
66+
# Turborepo
67+
.turbo/
6568

6669
# generated by bob
6770
lib/

packages/create-react-native-library/templates/common/$package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@
3333
"prepare": "bob build",
3434
"release": "release-it",
3535
"example": "yarn --cwd example",
36+
<% if (example === 'native' && turborepo) { -%>
37+
"build:android": "cd example/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
38+
"build:ios": "cd example/ios && xcodebuild -workspace <%- project.name %>Example.xcworkspace -configuration Debug -scheme <%- project.name %>Example -destination 'generic/platform=iOS' CODE_SIGN_IDENTITY='' CODE_SIGNING_REQUIRED=NO",
39+
<% } -%>
3640
<% if (example === 'native') { -%>
37-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build",
38-
"bootstrap": "yarn example && yarn install && yarn example pods"
41+
"bootstrap": "yarn example && yarn install && yarn example pods",
42+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
3943
<% } else { -%>
4044
"bootstrap": "yarn example && yarn install"
4145
<% } -%>
@@ -75,6 +79,9 @@
7579
"react-native": "0.70.0",
7680
"react-native-builder-bob": "^<%- bob.version %>",
7781
"release-it": "^15.0.0",
82+
<% if (turborepo) { -%>
83+
"turbo": "^1.6.3",
84+
<% } -%>
7885
"typescript": "^4.5.2"
7986
},
8087
"resolutions": {
@@ -84,6 +91,10 @@
8491
"react": "*",
8592
"react-native": "*"
8693
},
94+
"engines": {
95+
"node": ">= 16.0.0"
96+
},
97+
"packageManager": "^[email protected]",
8798
"jest": {
8899
"preset": "react-native",
89100
"modulePathIgnorePatterns": [
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"pipeline": {
4+
<% if (example === 'native') { -%>
5+
"build:android": {
6+
"inputs": [
7+
"package.json",
8+
"android/**",
9+
"example/package.json",
10+
"example/android/**"
11+
],
12+
"outputs": []
13+
},
14+
"build:ios": {
15+
"inputs": [
16+
"package.json",
17+
"*.podspec",
18+
"ios/**",
19+
"example/package.json",
20+
"example/ios/**"
21+
],
22+
"outputs": []
23+
}
24+
<% } -%>
25+
}
26+
}

0 commit comments

Comments
 (0)