-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid_lanes.rb
132 lines (110 loc) · 3.77 KB
/
android_lanes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# frozen_string_literal: true
platform :android do
desc 'Read version from pubspec.yaml'
lane :read_version do |options|
$version_name = get_flutter_version()
UI.message("Version: #{$version_name}")
end
desc 'Increment build number for Play Store'
lane :increment_build_number_lane do |options|
app_identifier = options[:app_identifier]
json_key_file = ENV['JSON_KEY_FILE_PATH']
UI.message("App Identifier: #{app_identifier}")
UI.message("JSON Key File: #{json_key_file}")
UI.user_error!("Missing app_identifier") unless app_identifier
UI.user_error!("Missing JSON key file") unless json_key_file
begin
previous_build_number = google_play_track_version_codes(
package_name: app_identifier,
track: 'internal',
json_key: json_key_file
)[0]
$build_number = previous_build_number + 1
UI.message("Previous build number: #{previous_build_number}")
UI.message("New build number: #{$build_number}")
increment_version_code(
gradle_file_path: './app/build.gradle',
version_code: $build_number
)
rescue => e
UI.error("Failed to increment build number: #{e.message}")
raise
end
end
desc 'Increment build number for Firebase distribution'
lane :increment_firebase_build_number_lane do |options|
firebase_app_id = options[:firebase_app_id]
UI.user_error!("Missing firebase_app_id") unless firebase_app_id
begin
latest_release = firebase_app_distribution_get_latest_release(
app: firebase_app_id
)
$build_number = latest_release ? latest_release[:buildVersion].to_i + 1 : 1
increment_version_code(
gradle_file_path: './app/build.gradle',
version_code: $build_number
)
rescue => e
UI.error("Failed to increment Firebase build number: #{e.message}")
raise
end
end
desc 'Build Flutter application'
lane :flutter_build do |options|
validate_build_options(options)
flavor = options[:flavor]
target = options[:target]
build_type = options[:build] || 'appbundle'
UI.message("Building with:")
UI.message("Flavor: #{flavor}")
UI.message("Target: #{target}")
UI.message("Build Type: #{build_type}")
Dir.chdir '../../' do
sh("flutter build #{build_type} --flavor #{flavor} --release -t #{target} --no-tree-shake-icons")
end
end
desc 'Upload to Play Store'
lane :build_store do |options|
json_key_file = ENV['JSON_KEY_FILE_PATH']
app_identifier = options[:app_identifier]
flavor = options[:flavor]
track = options[:track] || 'internal'
bundle_path = "../build/app/outputs/bundle/#{flavor}Release/app-#{flavor}-release.aab"
upload_to_play_store(
track: track,
aab: bundle_path,
package_name: app_identifier,
json_key: json_key_file
)
end
desc 'Upload to Firebase App Distribution'
lane :upload_to_firebase do |options|
firebase_app_id = options[:firebase_app_id]
flavor = options[:flavor]
apk_path = "../build/app/outputs/apk/#{flavor}/release/app-#{flavor}-release.apk"
firebase_app_distribution(
app: firebase_app_id,
groups: 'Internal',
android_artifact_type: 'APK',
android_artifact_path: apk_path
)
end
desc 'Deploy to Play Store'
lane :deploy_android do |options|
read_version(options)
increment_build_number_lane(options)
flutter_build(options)
build_store(options)
send_slack_message(options)
add_git_tag_method(options)
end
desc 'Deploy to Firebase'
lane :deploy_android_firebase do |options|
read_version(options)
increment_firebase_build_number_lane(options)
flutter_build(options)
upload_to_firebase(options)
send_slack_message(options)
add_git_tag_method(options)
end
end