Skip to content

Commit 7082fbe

Browse files
authored
Merge pull request #2 from Instabug/GCSI-515
[GCSI-515] update fastlane build actions android/ios
2 parents 3eb36c6 + 82c47e0 commit 7082fbe

17 files changed

+515
-197
lines changed

.rubocop.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require:
33
- rubocop/require_tools
44
- rubocop-performance
55
AllCops:
6-
TargetRubyVersion: 2.6
6+
TargetRubyVersion: 3.2.2
77
NewCops: enable
88
Include:
99
- "**/*.rb"
@@ -70,6 +70,7 @@ Require/MissingRequireStatement:
7070
- "**/Rakefile"
7171
- fastlane/**/*
7272
- supply/**/*
73+
- "lib/fastlane/plugin/**/*.rb"
7374
Layout/FirstHashElementIndentation:
7475
Enabled: false
7576
Layout/HashAlignment:
@@ -87,6 +88,8 @@ Style/MixinGrouping:
8788
- "**/spec/**/*"
8889
Lint/SuppressedException:
8990
Enabled: false
91+
Lint/IneffectiveAccessModifier:
92+
Enabled: false
9093
Lint/UnusedBlockArgument:
9194
Enabled: false
9295
Lint/AmbiguousBlockAssociation:
@@ -120,6 +123,8 @@ Layout/LineLength:
120123
Max: 370
121124
Metrics/ParameterLists:
122125
Max: 17
126+
Metrics/PerceivedComplexity:
127+
Max: 10
123128
Style/GuardClause:
124129
Enabled: false
125130
Style/StringLiterals:
@@ -192,5 +197,4 @@ Bundler/OrderedGems:
192197
Enabled: true
193198
TreatCommentsAsGroupSeparators: false
194199
Gemspec/DevelopmentDependencies:
195-
Enabled: true
196-
EnforcedStyle: Gemfile
200+
Enabled: false

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# instabug-stores-upload plugin
1+
# instabug_stores_upload plugin
22

3-
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-instabug-stores-upload)
3+
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-instabug_stores_upload)
44

55
## Getting Started
66

7-
This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-instabug-stores-upload`, add it to your project by running:
7+
This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-instabug_stores_upload`, add it to your project by running:
88

99
```bash
10-
fastlane add_plugin instabug-stores-upload
10+
fastlane add_plugin instabug_stores_upload
1111
```
1212

13-
## About instabug-stores-upload
13+
## About instabug_stores_upload
1414

1515
Wrapper plugin for uploading builds to App Store and Play Store with Instabug-specific metadata reporting. This plugin provides custom actions that wrap the standard Fastlane actions and automatically report build and upload events to Instabug systems for better observability and integration into internal pipelines.
1616

fastlane-plugin-instabug-stores-upload.gemspec

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
33
require 'fastlane/plugin/instabug_stores_upload/version'
44

55
Gem::Specification.new do |spec|
6-
spec.name = 'fastlane-plugin-instabug-stores-upload'
6+
spec.name = 'fastlane-plugin-instabug_stores_upload'
77
spec.version = Fastlane::InstabugStoresUpload::VERSION
88
spec.author = 'Instabug'
99
spec.email = '[email protected]'
@@ -17,11 +17,12 @@ Gem::Specification.new do |spec|
1717
spec.metadata['rubygems_mfa_required'] = 'true'
1818
spec.required_ruby_version = '>= 3.2.2'
1919

20-
spec.add_development_dependency 'bundler'
21-
spec.add_development_dependency 'rspec'
22-
spec.add_development_dependency 'rake'
23-
spec.add_development_dependency 'rubocop', '1.50.2'
24-
spec.add_development_dependency 'rubocop-require_tools'
25-
spec.add_development_dependency 'simplecov'
26-
spec.add_development_dependency 'fastlane', '~> 2.228.0'
20+
spec.add_development_dependency('bundler')
21+
spec.add_development_dependency('fastlane', '~> 2.228.0')
22+
spec.add_development_dependency('rake')
23+
spec.add_development_dependency('rspec')
24+
spec.add_development_dependency('rubocop', '1.50.2')
25+
spec.add_development_dependency('rubocop-performance')
26+
spec.add_development_dependency('rubocop-require_tools')
27+
spec.add_development_dependency('simplecov')
2728
end

fastlane/Fastfile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Example lane for building iOS app with Instabug reporting
44
lane :build_ios_app do |options|
55
branch_name = options[:branch_name]
6-
6+
77
instabug_build_ios_app(
8-
branch_name: branch_name,
9-
instabug_api_key: ENV["INSTABUG_API_KEY"],
8+
branch_name:,
9+
instabug_api_key: ENV.fetch("INSTABUG_API_KEY", nil),
1010
# All standard build_ios_app parameters are supported
1111
workspace: "MyApp.xcworkspace",
1212
scheme: "MyApp",
@@ -18,42 +18,42 @@ end
1818
# Example lane for building Android app with Instabug reporting
1919
lane :build_android_app do |options|
2020
branch_name = options[:branch_name]
21-
21+
2222
instabug_build_android_app(
23-
branch_name: branch_name,
24-
instabug_api_key: ENV["INSTABUG_API_KEY"],
23+
branch_name:,
24+
instabug_api_key: ENV.fetch("INSTABUG_API_KEY", nil),
2525
# All standard gradle parameters are supported
2626
task: "assembleRelease",
2727
project_dir: "android/",
2828
properties: {
2929
"android.injected.signing.store.file" => "keystore.jks",
30-
"android.injected.signing.store.password" => ENV["KEYSTORE_PASSWORD"],
30+
"android.injected.signing.store.password" => ENV.fetch("KEYSTORE_PASSWORD", nil),
3131
"android.injected.signing.key.alias" => "key0",
32-
"android.injected.signing.key.password" => ENV["KEY_PASSWORD"]
32+
"android.injected.signing.key.password" => ENV.fetch("KEY_PASSWORD", nil)
3333
}
3434
)
3535
end
3636

3737
# Example lane for uploading to App Store with Instabug reporting
3838
lane :upload_to_app_store do |options|
3939
branch_name = options[:branch_name]
40-
40+
4141
instabug_upload_to_app_store(
42-
branch_name: branch_name,
43-
instabug_api_key: ENV["INSTABUG_API_KEY"],
42+
branch_name:,
43+
instabug_api_key: ENV.fetch("INSTABUG_API_KEY", nil),
4444
# All standard upload_to_app_store parameters are supported
4545
ipa: "path/to/your/app.ipa",
4646
skip_waiting_for_build_processing: true
4747
)
4848
end
4949

50-
# Example lane for uploading to Play Store with Instabug reporting
50+
# Example lane for uploading to Play Store with Instabug reporting
5151
lane :upload_to_play_store do |options|
52-
branch_name = options[:branch_name]
53-
52+
branch_name = options[:branch_name]
53+
5454
instabug_upload_to_play_store(
55-
branch_name: branch_name,
56-
instabug_api_key: ENV["INSTABUG_API_KEY"],
55+
branch_name:,
56+
instabug_api_key: ENV.fetch("INSTABUG_API_KEY", nil),
5757
# All standard upload_to_play_store parameters are supported
5858
aab: "path/to/your/app.aab",
5959
track: "internal"

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_android_app_action.rb

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,71 @@ module Actions
66
class InstabugBuildAndroidAppAction < Action
77
def self.run(params)
88
UI.message("Starting Instabug Android build...")
9-
9+
1010
# Extract Instabug-specific parameters
11-
branch_name = params.delete(:branch_name)
12-
instabug_api_key = params.delete(:instabug_api_key)
13-
11+
branch_name = params[:branch_name]
12+
instabug_api_key = params[:instabug_api_key]
13+
1414
# Validate required parameters
1515
if branch_name.nil? || branch_name.empty?
1616
UI.user_error!("branch_name is required for Instabug reporting")
1717
end
18-
18+
19+
# Filter out Instabug-specific parameters before passing to gradle
20+
filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::GradleAction)
21+
1922
begin
2023
# Report build start to Instabug
2124
Helper::InstabugStoresUploadHelper.report_status(
22-
branch_name: branch_name,
25+
branch_name:,
2326
api_key: instabug_api_key,
2427
status: "inprogress",
2528
step: "build_app"
2629
)
2730

31+
# Start timing the build
32+
build_start_time = Time.now
33+
2834
# Execute the actual Android build using gradle
29-
result = Actions::GradleAction.run(params)
35+
result = Actions::GradleAction.run(filtered_params)
36+
37+
# Calculate build time in seconds
38+
build_time = (Time.now - build_start_time).round
39+
40+
# Extract Android build path (APK or AAB)
41+
build_path = fetch_android_build_path(Actions.lane_context)
42+
43+
if build_path.nil? || build_path.empty?
44+
UI.user_error!("Could not find any generated APK or AAB. Please check your gradle settings.")
45+
else
46+
UI.success("Successfully found build artifact(s) at: #{build_path}")
47+
end
3048

3149
# Report build success to Instabug
3250
Helper::InstabugStoresUploadHelper.report_status(
33-
branch_name: branch_name,
51+
branch_name:,
3452
api_key: instabug_api_key,
3553
status: "success",
36-
step: "build_app"
54+
step: "build_app",
55+
extras: {
56+
build_time:,
57+
build_path: Array(build_path)
58+
}
3759
)
3860

3961
UI.success("Android build completed successfully!")
4062
result
41-
rescue => e
42-
UI.error("Android build failed: #{e.message}")
63+
rescue StandardError => e
64+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
65+
UI.error("Android build failed: #{error_message}")
4366

4467
# Report build failure to Instabug
4568
Helper::InstabugStoresUploadHelper.report_status(
46-
branch_name: branch_name,
69+
branch_name:,
4770
api_key: instabug_api_key,
4871
status: "failure",
49-
step: "build_app"
72+
step: "build_app",
73+
error_message: error_message
5074
)
5175
raise e
5276
end
@@ -71,7 +95,7 @@ def self.details
7195
def self.available_options
7296
# Start with the original gradle options
7397
options = Actions::GradleAction.available_options
74-
98+
7599
# Add Instabug-specific options
76100
instabug_options = [
77101
FastlaneCore::ConfigItem.new(
@@ -88,9 +112,17 @@ def self.available_options
88112
optional: false,
89113
type: String,
90114
sensitive: true
91-
)
115+
),
116+
FastlaneCore::ConfigItem.new(
117+
key: :instabug_api_base_url,
118+
env_name: "INSTABUG_API_BASE_URL",
119+
description: "Instabug API base URL (defaults to https://api.instabug.com)",
120+
optional: true,
121+
type: String,
122+
skip_type_validation: true # Since we don't extract this param
123+
)
92124
]
93-
125+
94126
# Combine both sets of options
95127
options + instabug_options
96128
end
@@ -119,6 +151,24 @@ def self.example_code
119151
def self.category
120152
:building
121153
end
154+
155+
# This helper method provides a clean and prioritized way to get the Android build output.
156+
# It checks for the most common output types in a specific order.
157+
# This is used to get the build path for the Android build artifact.
158+
def self.fetch_android_build_path(lane_context)
159+
build_keys = [
160+
SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS,
161+
SharedValues::GRADLE_APK_OUTPUT_PATH,
162+
SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS,
163+
SharedValues::GRADLE_AAB_OUTPUT_PATH
164+
]
165+
build_keys.each do |build_key|
166+
build_path = lane_context[build_key]
167+
return build_path if build_path && !build_path.empty?
168+
end
169+
170+
nil
171+
end
122172
end
123173
end
124-
end
174+
end

0 commit comments

Comments
 (0)