Skip to content

Commit 833e601

Browse files
Add RNRepo to ci builds (#2944)
# Summary Adds RNRepo build-tools integration to `fabric-example` so that CI builds can consume pre-built native dependencies instead of compiling them from scratch, speeding up CI. The integration is guarded by `CI=true` / `ENV['CI']` environment variables, so local development is unaffected. `react-native-svg` itself is excluded from prebuilds via `rnrepo.config.json` so that CI always builds and tests the library from source. ## Test Plan Builds in CI using RNRepo should speed up the CI process. Android sees ~38% improvement across the board. iOS builds are ~15% faster. - https://github.com/software-mansion/react-native-svg/actions/runs/25438112937: 5min - without: 6-12min ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | MacOS | ❌ | | Android | ✅ | | Web | ❌ | ## Checklist - [ ] I have tested this on a device and a simulator - [ ] I added documentation in `README.md` - [ ] I updated the typed files (typescript) - [ ] I added a test for the API in the `__tests__` folder
1 parent 3414292 commit 833e601

8 files changed

Lines changed: 62 additions & 2 deletions

File tree

.github/workflows/android-build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ jobs:
6868
6969
- name: Build app
7070
working-directory: apps/${{ matrix.working-directory }}/android
71-
run: ./gradlew assembleDebug --build-cache --console=plain -PreactNativeArchitectures=arm64-v8a
71+
run: ./gradlew :app:assembleDebug --build-cache --console=plain -PreactNativeArchitectures=arm64-v8a

.github/workflows/e2e-android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
E2E=true yarn --cwd apps/${{ env.WORKING_DIRECTORY }} start &> output.log &
9696
9797
# Build the Android app
98-
cd apps/${{ env.WORKING_DIRECTORY }}/android && ./gradlew assembleDebug
98+
cd apps/${{ env.WORKING_DIRECTORY }}/android && ./gradlew :app:assembleDebug
9999
100100
# Install the app APK
101101
$ANDROID_HOME/platform-tools/adb install -r apps/${{ env.WORKING_DIRECTORY }}/android/app/build/outputs/apk/debug/app-debug.apk

apps/fabric-example/android/app/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ apply plugin: "com.android.application"
22
apply plugin: "org.jetbrains.kotlin.android"
33
apply plugin: "com.facebook.react"
44

5+
def isCIEnabled() {
6+
return ["1", "true"].contains(System.getenv("CI")?.toLowerCase())
7+
}
8+
9+
def isRNRepoEnabled() {
10+
// return false // Uncomment to disable RNRepo locally
11+
return System.getenv("DISABLE_RNREPO") == null
12+
}
13+
14+
// Use RNRepo in CI builds.
15+
// Set DISABLE_RNREPO to any value to disable RNRepo.
16+
if (isCIEnabled() && isRNRepoEnabled()) {
17+
apply plugin: "org.rnrepo.tools.prebuilds-plugin"
18+
}
19+
520
/**
621
* This is the configuration block to customize your React Native Android app.
722
* By default you don't need to apply any configuration, just uncomment the lines you need.

apps/fabric-example/android/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@ buildscript {
1111
google()
1212
mavenCentral()
1313
}
14+
// RNRepo plugin classpath for CI builds (plugin applied in app/build.gradle).
15+
// To disable RNRepo support, set DISABLE_RNREPO environment variable to ANY value.
16+
def rnrepoClasspath = {
17+
def rnrepoDir = new File(
18+
providers.exec {
19+
workingDir(rootDir)
20+
commandLine("node", "--print", "require.resolve('@rnrepo/build-tools/package.json')")
21+
}.standardOutput.asText.get().trim()
22+
).getParentFile().absolutePath
23+
return fileTree(dir: "${rnrepoDir}/gradle-plugin/build/libs", include: ["prebuilds-plugin.jar"])
24+
}
1425
dependencies {
1526
classpath("com.android.tools.build:gradle")
1627
classpath("com.facebook.react:react-native-gradle-plugin")
1728
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
29+
classpath rnrepoClasspath()
1830
}
1931
}
2032

apps/fabric-example/ios/Podfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ require Pod::Executable.execute_command('node', ['-p',
77
{paths: [process.argv[1]]},
88
)', __dir__]).strip
99

10+
def is_ci_enabled?
11+
%w[1 true].include?(ENV['CI'].to_s.downcase)
12+
end
13+
14+
# ENV['DISABLE_RNREPO'] = "1" # Uncomment to disable RNRepo even in CI
15+
def is_rnrepo_enabled?
16+
ENV['DISABLE_RNREPO'].nil?
17+
end
18+
19+
# Use RNRepo in CI builds. Set DISABLE_RNREPO to any value to disable RNRepo.
20+
if is_ci_enabled? && is_rnrepo_enabled?
21+
require Pod::Executable.execute_command('node', ['-p',
22+
'require.resolve(
23+
"@rnrepo/build-tools/cocoapods-plugin/lib/plugin.rb",
24+
{paths: [process.argv[1]]},
25+
)', __dir__]).strip
26+
end
27+
1028
platform :ios, min_ios_version_supported
1129
prepare_react_native_project!
1230

@@ -26,6 +44,9 @@ target 'FabricExample' do
2644
)
2745

2846
post_install do |installer|
47+
if is_ci_enabled? && is_rnrepo_enabled?
48+
rnrepo_post_install(installer)
49+
end
2950
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
3051
react_native_post_install(
3152
installer,

apps/fabric-example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@react-native/eslint-config": "0.81.4",
3737
"@react-native/metro-config": "0.81.4",
3838
"@react-native/typescript-config": "0.81.4",
39+
"@rnrepo/build-tools": "~0.1.3-beta.0",
3940
"@types/jest": "^29.5.13",
4041
"@types/react": "^19.1.0",
4142
"@types/react-test-renderer": "^19.1.0",

apps/fabric-example/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,11 @@
18281828
"@react-navigation/elements" "^2.6.3"
18291829
color "^4.2.3"
18301830

1831+
"@rnrepo/build-tools@~0.1.3-beta.0":
1832+
version "0.1.3-beta.0"
1833+
resolved "https://registry.yarnpkg.com/@rnrepo/build-tools/-/build-tools-0.1.3-beta.0.tgz#07900af5347c05b60c7ec65bb4351b921f5df9e9"
1834+
integrity sha512-ifo8j/1+cnTVTz2Au/dDIgoj+1z8mbyeFCvk5l30EP3vVWDb0PUafMsPycKF7/nLrnDIJKlh7g7GpdnwnbM2yA==
1835+
18311836
"@sideway/address@^4.1.5":
18321837
version "4.1.5"
18331838
resolved "https://registry.yarnpkg.com/@sideway/address/-/address-4.1.5.tgz#4bc149a0076623ced99ca8208ba780d65a99b9d5"

rnrepo.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"denyList": {
3+
"android": ["react-native-svg"],
4+
"ios": ["react-native-svg"]
5+
}
6+
}

0 commit comments

Comments
 (0)