Skip to content

Commit 45dea53

Browse files
committed
[GCSI-567] feat: handle ios build app to track build time and build path and + specs
1 parent d1690fe commit 45dea53

File tree

2 files changed

+90
-36
lines changed

2 files changed

+90
-36
lines changed

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,67 @@ module Actions
66
class InstabugBuildIosAppAction < Action
77
def self.run(params)
88
UI.message("Starting Instabug iOS build...")
9-
9+
1010
# Extract Instabug-specific parameters
1111
branch_name = params.delete(:branch_name)
1212
instabug_api_key = params.delete(:instabug_api_key)
13-
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+
1919
begin
2020
# Report build start to Instabug
2121
Helper::InstabugStoresUploadHelper.report_status(
22-
branch_name: branch_name,
22+
branch_name:,
2323
api_key: instabug_api_key,
2424
status: "inprogress",
2525
step: "build_app"
2626
)
2727

28+
# Start timing the build
29+
build_start_time = Time.now
30+
2831
# Execute the actual iOS build
2932
result = Actions::BuildIosAppAction.run(params)
3033

34+
# Calculate build time in seconds
35+
build_time = (Time.now - build_start_time).round
36+
37+
# Extract IPA path from Fastlane environment
38+
build_path = Actions.lane_context[SharedValues::IPA_OUTPUT_PATH]
39+
40+
if build_path
41+
UI.success("IPA Output Path: #{build_path}")
42+
else
43+
UI.error("No IPA path found.")
44+
end
45+
3146
# Report build success to Instabug
3247
Helper::InstabugStoresUploadHelper.report_status(
33-
branch_name: branch_name,
48+
branch_name:,
3449
api_key: instabug_api_key,
3550
status: "success",
36-
step: "build_app"
51+
step: "build_app",
52+
extras: {
53+
build_time:,
54+
build_path:
55+
}
3756
)
3857

3958
UI.success("iOS build completed successfully!")
4059
result
41-
rescue => e
60+
rescue StandardError => e
4261
UI.error("iOS build failed: #{e.message}")
4362

4463
# Report build failure to Instabug
4564
Helper::InstabugStoresUploadHelper.report_status(
46-
branch_name: branch_name,
65+
branch_name:,
4766
api_key: instabug_api_key,
4867
status: "failure",
49-
step: "build_app"
68+
step: "build_app",
69+
error_message: e.message
5070
)
5171
raise e
5272
end
@@ -71,7 +91,7 @@ def self.details
7191
def self.available_options
7292
# Start with the original build_ios_app options
7393
options = Actions::BuildIosAppAction.available_options
74-
94+
7595
# Add Instabug-specific options
7696
instabug_options = [
7797
FastlaneCore::ConfigItem.new(
@@ -88,9 +108,17 @@ def self.available_options
88108
optional: false,
89109
type: String,
90110
sensitive: true
91-
)
111+
),
112+
FastlaneCore::ConfigItem.new(
113+
key: :instabug_api_base_url,
114+
env_name: "INSTABUG_API_BASE_URL",
115+
description: "Instabug API base URL (defaults to https://api.instabug.com)",
116+
optional: true,
117+
type: String,
118+
skip_type_validation: true # Since we don't extract this param
119+
)
92120
]
93-
121+
94122
# Combine both sets of options
95123
options + instabug_options
96124
end
@@ -117,4 +145,4 @@ def self.category
117145
end
118146
end
119147
end
120-
end
148+
end

spec/instabug_build_ios_app_action_spec.rb

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

2121
describe '#run' do
2222
context 'when build succeeds' do
23-
it 'reports inprogress, calls build action, and reports success' do
23+
it 'reports inprogress, calls build action, and reports success with timing and path' do
24+
# Mock the lane context to return an IPA path
25+
allow(Fastlane::Actions).to receive(:lane_context).and_return({
26+
Fastlane::Actions::SharedValues::IPA_OUTPUT_PATH => '/path/to/app.ipa'
27+
})
28+
2429
expect(Fastlane::Actions::BuildIosAppAction).to receive(:run)
2530
.with(hash_including(workspace: 'Test.xcworkspace', scheme: 'Test', export_method: 'app-store'))
2631
.and_return('build_result')
@@ -33,7 +38,9 @@
3338
body: {
3439
branch_name: 'crash-fix/instabug-crash-123',
3540
status: 'inprogress',
36-
step: 'build_app'
41+
step: 'build_app',
42+
extras: {},
43+
error_message: nil
3744
}.to_json,
3845
headers: {
3946
'Content-Type' => 'application/json',
@@ -43,18 +50,35 @@
4350
).once
4451

4552
expect(WebMock).to have_requested(:patch, api_endpoint)
46-
.with(
47-
body: {
48-
branch_name: 'crash-fix/instabug-crash-123',
49-
status: 'success',
50-
step: 'build_app'
51-
}.to_json,
52-
headers: {
53-
'Content-Type' => 'application/json',
54-
'Authorization' => 'Bearer test-api-key',
55-
'User-Agent' => 'fastlane-plugin-instabug-stores-upload'
56-
}
57-
).once
53+
.with { |req|
54+
body = JSON.parse(req.body)
55+
body['status'] == 'success' &&
56+
body['branch_name'] == 'crash-fix/instabug-crash-123' &&
57+
body['step'] == 'build_app' &&
58+
body['extras']['build_path'] == '/path/to/app.ipa' &&
59+
body['extras']['build_time'].kind_of?(Integer)
60+
}.once
61+
end
62+
63+
it 'handles missing IPA path gracefully' do
64+
# Mock empty lane context
65+
allow(Fastlane::Actions).to receive(:lane_context).and_return({})
66+
67+
expect(Fastlane::Actions::BuildIosAppAction).to receive(:run)
68+
.and_return('build_result')
69+
70+
result = described_class.run(valid_params)
71+
72+
expect(result).to eq('build_result')
73+
expect(WebMock).to have_requested(:patch, api_endpoint)
74+
.with { |req|
75+
body = JSON.parse(req.body)
76+
body['status'] == 'success' &&
77+
body['branch_name'] == 'crash-fix/instabug-crash-123' &&
78+
body['step'] == 'build_app' &&
79+
body['extras']['build_path'].nil? &&
80+
body['extras']['build_time'].kind_of?(Integer)
81+
}.once
5882
end
5983
end
6084

@@ -64,16 +88,18 @@
6488
expect(Fastlane::Actions::BuildIosAppAction).to receive(:run)
6589
.and_raise(error)
6690

67-
expect {
91+
expect do
6892
described_class.run(valid_params)
69-
}.to raise_error(StandardError, 'Build failed')
93+
end.to raise_error(StandardError, 'Build failed')
7094

7195
expect(WebMock).to have_requested(:patch, api_endpoint)
7296
.with(
7397
body: {
7498
branch_name: 'crash-fix/instabug-crash-123',
7599
status: 'failure',
76-
step: 'build_app'
100+
step: 'build_app',
101+
extras: {},
102+
error_message: 'Build failed'
77103
}.to_json
78104
)
79105
end
@@ -83,26 +109,26 @@
83109
it 'raises user error' do
84110
params = valid_params.merge(branch_name: nil)
85111

86-
expect {
112+
expect do
87113
described_class.run(params)
88-
}.to raise_error(FastlaneCore::Interface::FastlaneError, 'branch_name is required for Instabug reporting')
114+
end.to raise_error(FastlaneCore::Interface::FastlaneError, 'branch_name is required for Instabug reporting')
89115
end
90116
end
91117

92118
context 'when branch_name is empty' do
93119
it 'raises user error' do
94120
params = valid_params.merge(branch_name: '')
95121

96-
expect {
122+
expect do
97123
described_class.run(params)
98-
}.to raise_error(FastlaneCore::Interface::FastlaneError, 'branch_name is required for Instabug reporting')
124+
end.to raise_error(FastlaneCore::Interface::FastlaneError, 'branch_name is required for Instabug reporting')
99125
end
100126
end
101127

102128
context 'when branch name does not match instabug pattern' do
103129
it 'does not make API calls but still runs build' do
104130
params = valid_params.merge(branch_name: 'feature/new-feature')
105-
131+
106132
expect(Fastlane::Actions::BuildIosAppAction).to receive(:run)
107133
.and_return('build_result')
108134

@@ -129,4 +155,4 @@
129155
expect(described_class.category).to eq(:building)
130156
end
131157
end
132-
end
158+
end

0 commit comments

Comments
 (0)