Skip to content

Commit fc09df2

Browse files
committed
chore: add android build and deploy workflows and improve ios workflow
1 parent 743b587 commit fc09df2

File tree

10 files changed

+154
-73
lines changed

10 files changed

+154
-73
lines changed

examples/SampleApp/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ yarn-error.log
7373
!.yarn/releases
7474
!.yarn/sdks
7575
!.yarn/versions
76+
77+
# Credentials
78+
credentials/
79+
app-build/

examples/SampleApp/Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ GEM
164164
fastlane-plugin-firebase_app_distribution (0.9.1)
165165
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
166166
google-apis-firebaseappdistribution_v1alpha (~> 0.2.0)
167+
fastlane-plugin-increment_version_code (0.4.3)
167168
fastlane-plugin-load_json (0.0.1)
168169
fastlane-plugin-stream_actions (0.3.73)
169170
xctest_list (= 1.2.1)
@@ -326,6 +327,7 @@ DEPENDENCIES
326327
concurrent-ruby (< 1.3.4)
327328
fastlane
328329
fastlane-plugin-firebase_app_distribution
330+
fastlane-plugin-increment_version_code
329331
fastlane-plugin-load_json
330332
fastlane-plugin-stream_actions (= 0.3.73)
331333
logger

examples/SampleApp/android/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ android {
7979

8080
buildToolsVersion rootProject.ext.buildToolsVersion
8181
compileSdk rootProject.ext.compileSdkVersion
82-
namespace "com.sampleapp"
82+
namespace "io.getstream.reactnative.sampleapp"
8383

8484
defaultConfig {
85-
applicationId "com.sampleapp"
85+
applicationId "io.getstream.reactnative.sampleapp"
8686
minSdkVersion rootProject.ext.minSdkVersion
8787
multiDexEnabled true
8888
targetSdkVersion rootProject.ext.targetSdkVersion
8989
vectorDrawables.useSupportLibrary = true
90-
versionCode 22
90+
versionCode 1
9191
versionName "0.0.22"
9292
}
9393

examples/SampleApp/android/app/google-services.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"client_info": {
6363
"mobilesdk_app_id": "1:674907137625:android:5effa1cd0fef9003d7f348",
6464
"android_client_info": {
65-
"package_name": "com.sampleapp"
65+
"package_name": "io.getstream.reactnative.sampleapp"
6666
}
6767
},
6868
"oauth_client": [
@@ -98,7 +98,7 @@
9898
"client_info": {
9999
"mobilesdk_app_id": "1:674907137625:android:07c76802bbfd5654d7f348",
100100
"android_client_info": {
101-
"package_name": "com.sampleapp.rnpushtest"
101+
"package_name": "io.getstream.reactnative.sampleapp.rnpushtest"
102102
}
103103
},
104104
"oauth_client": [

examples/SampleApp/android/app/src/androidTest/java/com/sampleapp/DetoxTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sampleapp;
1+
package io.getstream.reactnative.sampleapp;
22

33
import com.wix.detox.Detox;
44
import com.wix.detox.config.DetoxConfig;
@@ -24,7 +24,7 @@ public void runDetoxTests() {
2424
DetoxConfig detoxConfig = new DetoxConfig();
2525
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90;
2626
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60;
27-
detoxConfig.rnContextLoadTimeoutSec = (com.sampleapp.BuildConfig.DEBUG ? 180 : 60);
27+
detoxConfig.rnContextLoadTimeoutSec = (io.getstream.reactnative.sampleapp.BuildConfig.DEBUG ? 180 : 60);
2828

2929
Detox.runTests(mActivityRule, detoxConfig);
3030
}

examples/SampleApp/android/app/src/main/java/com/sampleapp/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sampleapp
1+
package io.getstream.reactnative.sampleapp
22

33
import com.facebook.react.ReactActivity
44
import com.facebook.react.ReactActivityDelegate

examples/SampleApp/android/app/src/main/java/com/sampleapp/MainApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.sampleapp
1+
package io.getstream.reactnative.sampleapp
22

33
import android.app.Application
44
import com.facebook.react.PackageList

examples/SampleApp/fastlane/Fastfile

Lines changed: 133 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
default_platform(:ios)
21
skip_docs
32

3+
# Common Configuration
44
github_repo = ENV['GITHUB_REPOSITORY'] || 'GetStream/stream-chat-react-native'
5-
bundle_id = 'io.getstream.reactnative.SampleApp'
6-
xcode_project = 'ios/SampleApp.xcodeproj'
7-
xcode_workspace = 'ios/SampleApp.xcworkspace'
85
root_path = File.absolute_path('../../../')
96
sdk_size_ext = 'KB'
107
@force_check = false
8+
build_output_directory = "./app-build"
9+
10+
# iOS Platform Configuration
11+
bundle_id = 'io.getstream.reactnative.SampleApp'
12+
xcode_project = 'ios/SampleApp.xcodeproj'
13+
xcode_workspace = 'ios/SampleApp.xcworkspace'
14+
output_ipa_name = "reactnativesampleapp.ipa"
15+
16+
# Android Platform Configuration
17+
package_name = 'io.getstream.reactnative.sampleapp'
18+
firebase_app_id = "1:860064972837:android:45442c1123323ac9f17fcc"
19+
firebase_credentials_file = "./credentials/firebase-credentials.json"
20+
output_apk_name = "reactnativesampleapp.apk"
21+
apk_path = "#{build_output_directory}/#{output_apk_name}"
22+
1123

1224
before_all do
1325
if is_ci
@@ -20,82 +32,140 @@ end
2032
###### iOS lanes ######
2133
#######################
2234

23-
lane :deploy_to_testflight_qa do |options|
24-
match_me
25-
26-
settings_to_override = {
27-
BUNDLE_IDENTIFIER: bundle_id,
28-
PROVISIONING_PROFILE_SPECIFIER: "match AppStore #{bundle_id}"
29-
}
30-
31-
increment_version_number(
32-
version_number: load_json(json_path: './package.json')['version'],
33-
xcodeproj: xcode_project
34-
)
35-
36-
current_build_number = app_store_build_number(
37-
api_key: appstore_api_key,
38-
live: false,
39-
app_identifier: bundle_id
35+
platform :ios do
36+
lane :deploy_to_testflight_qa do |options|
37+
match_me
38+
39+
deploy = options.fetch(:deploy, false)
40+
41+
UI.message("Deploying to Testflight: #{deploy}")
42+
43+
settings_to_override = {
44+
BUNDLE_IDENTIFIER: bundle_id,
45+
PROVISIONING_PROFILE_SPECIFIER: "match AppStore #{bundle_id}"
46+
}
47+
48+
gym(
49+
workspace: xcode_workspace,
50+
scheme: 'SampleApp',
51+
export_method: 'app-store',
52+
export_options: './fastlane/testflight_gym_export_options.plist',
53+
silent: true,
54+
clean: true,
55+
xcargs: settings_to_override,
56+
include_symbols: true,
57+
output_directory: build_output_directory
4058
)
4159

42-
increment_build_number(
43-
build_number: current_build_number + 1,
44-
xcodeproj: xcode_project
45-
)
60+
if deploy
61+
increment_version_number(
62+
version_number: load_json(json_path: './package.json')['version'],
63+
xcodeproj: xcode_project
64+
)
4665

47-
gym(
48-
workspace: xcode_workspace,
49-
scheme: 'SampleApp',
50-
export_method: 'app-store',
51-
export_options: './fastlane/testflight_gym_export_options.plist',
52-
silent: true,
53-
clean: true,
54-
xcargs: settings_to_override,
55-
include_symbols: true,
56-
output_directory: './dist'
57-
)
66+
current_build_number = app_store_build_number(
67+
api_key: appstore_api_key,
68+
live: false,
69+
app_identifier: bundle_id
70+
)
71+
72+
increment_build_number(
73+
build_number: current_build_number + 1,
74+
xcodeproj: xcode_project
75+
)
5876

59-
if options[:deploy]
60-
begin
6177
upload_to_testflight(
6278
groups: ['Testers'],
6379
changelog: 'Lots of amazing new features to test out!',
64-
reject_build_waiting_for_review: false
80+
reject_build_waiting_for_review: false,
81+
ipa: "#{build_output_directory}/#{output_ipa_name}"
6582
)
66-
rescue StandardError => e
67-
if e.message.include?('Another build is in review')
68-
UI.important('Another build is already in beta review. Skipping beta review submission')
69-
else
70-
UI.user_error!(e)
71-
end
83+
else
84+
UI.message("Skipping Testflight upload! (deploy: #{deploy})")
7285
end
7386
end
74-
end
75-
76-
private_lane :appstore_api_key do
77-
@appstore_api_key ||= app_store_connect_api_key(
78-
key_id: 'MT3PRT8TB7',
79-
issuer_id: '69a6de96-0738-47e3-e053-5b8c7c11a4d1',
80-
key_content: ENV.fetch('APPSTORE_API_KEY', nil),
81-
in_house: false
82-
)
83-
end
8487

85-
desc "If `readonly: true` (by default), installs all Certs and Profiles necessary for development and ad-hoc.\nIf `readonly: false`, recreates all Profiles necessary for development and ad-hoc, updates them locally and remotely."
86-
lane :match_me do |options|
87-
custom_match(
88-
api_key: appstore_api_key,
89-
app_identifier: [bundle_id],
90-
readonly: options[:readonly],
91-
register_device: options[:register_device]
92-
)
88+
private_lane :appstore_api_key do
89+
@appstore_api_key ||= app_store_connect_api_key(
90+
key_id: 'MT3PRT8TB7',
91+
issuer_id: '69a6de96-0738-47e3-e053-5b8c7c11a4d1',
92+
key_content: ENV.fetch('APPSTORE_API_KEY', nil),
93+
in_house: false
94+
)
95+
end
96+
97+
desc "If `readonly: true` (by default), installs all Certs and Profiles necessary for development and ad-hoc.\nIf `readonly: false`, recreates all Profiles necessary for development and ad-hoc, updates them locally and remotely."
98+
lane :match_me do |options|
99+
custom_match(
100+
api_key: appstore_api_key,
101+
app_identifier: [bundle_id],
102+
readonly: options[:readonly],
103+
register_device: options[:register_device]
104+
)
105+
end
93106
end
94107

95108
###########################
96109
###### Android lanes ######
97110
###########################
98111

112+
platform :android do
113+
lane :firebase_build_and_upload do |options|
114+
deploy = options.fetch(:deploy, false)
115+
116+
UI.message("Deploying to Firebase: #{deploy}")
117+
118+
# Clean
119+
gradle(
120+
task: "clean",
121+
project_dir: "./android"
122+
)
123+
124+
# Build the AAB
125+
gradle(
126+
task: "assemble",
127+
build_type: "Release",
128+
project_dir: "./android"
129+
)
130+
131+
Dir.chdir('..') do
132+
sh("mkdir -p #{build_output_directory} && mv -f #{lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]} #{apk_path}")
133+
end
134+
135+
if deploy
136+
latest_app_distribution_release = firebase_app_distribution_get_latest_release(
137+
app: firebase_app_id,
138+
service_credentials_file: firebase_credentials_file
139+
)
140+
141+
# Handle case when no previous releases exist
142+
if latest_app_distribution_release.nil? || latest_app_distribution_release.empty?
143+
puts "No previous releases found. Starting with version code 1"
144+
latest_app_distribution_version_code = 0 # Will be incremented to 1
145+
else
146+
latest_app_distribution_version_code = latest_app_distribution_release[:buildVersion].to_i
147+
puts "Latest version code from App Distribution: #{latest_app_distribution_version_code}"
148+
end
149+
150+
increment_version_code(
151+
gradle_file_path: "./android/app/build.gradle",
152+
version_code: latest_app_distribution_version_code + 1
153+
)
154+
155+
# Upload to Firebase App Distribution
156+
firebase_app_distribution(
157+
app: firebase_app_id,
158+
service_credentials_file: firebase_credentials_file,
159+
android_artifact_path: apk_path,
160+
android_artifact_type: "APK",
161+
groups: "stream-testers"
162+
)
163+
else
164+
UI.message("Skipping Firebase upload! (deploy: #{deploy})")
165+
end
166+
end
167+
end
168+
99169
##########################
100170
###### Common lanes ######
101171
##########################

examples/SampleApp/fastlane/Pluginfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
gem 'fastlane-plugin-firebase_app_distribution'
66
gem 'fastlane-plugin-load_json'
77
gem 'fastlane-plugin-stream_actions', '0.3.73'
8+
gem 'fastlane-plugin-increment_version_code'

examples/SampleApp/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
"release-next": "echo \"Skipping next release for SampleApp\"",
2121
"test:unit": "echo \"Skipping unit tests for SampleApp\"",
2222
"clean": "watchman watch-del-all && yarn cache clean && rm -rf ios/build && pod cache clean --all && rm -rf android/build && cd android && ./gradlew clean && cd -",
23-
"clean-all": "yarn clean && rm -rf node_modules && rm -rf ios/Pods && rm -rf vendor && bundle install && yarn install && cd ios && bundle exec pod install && cd -"
23+
"clean-all": "yarn clean && rm -rf node_modules && rm -rf ios/Pods && rm -rf vendor && bundle install && yarn install && cd ios && bundle exec pod install && cd -",
24+
"fastlane:android-build": "bundle exec fastlane android firebase_build_and_upload deploy:false",
25+
"fastlane:android-deploy": "bundle exec fastlane android firebase_build_and_upload deploy:true",
26+
"fastlane:ios-build": "bundle exec fastlane ios deploy_to_testflight_qa deploy:false",
27+
"fastlane:ios-deploy": "bundle exec fastlane ios deploy_to_testflight_qa deploy:true"
2428
},
2529
"dependencies": {
2630
"@emoji-mart/data": "^1.2.1",

0 commit comments

Comments
 (0)