Skip to content

[GCSI-515] update fastlane build actions android/ios #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: GCSI-409
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require:
- rubocop/require_tools
- rubocop-performance
AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 3.2.2
NewCops: enable
Include:
- "**/*.rb"
Expand Down Expand Up @@ -70,6 +70,7 @@ Require/MissingRequireStatement:
- "**/Rakefile"
- fastlane/**/*
- supply/**/*
- "lib/fastlane/plugin/**/*.rb"
Layout/FirstHashElementIndentation:
Enabled: false
Layout/HashAlignment:
Expand All @@ -87,6 +88,8 @@ Style/MixinGrouping:
- "**/spec/**/*"
Lint/SuppressedException:
Enabled: false
Lint/IneffectiveAccessModifier:
Enabled: false
Lint/UnusedBlockArgument:
Enabled: false
Lint/AmbiguousBlockAssociation:
Expand Down Expand Up @@ -120,6 +123,8 @@ Layout/LineLength:
Max: 370
Metrics/ParameterLists:
Max: 17
Metrics/PerceivedComplexity:
Max: 10
Style/GuardClause:
Enabled: false
Style/StringLiterals:
Expand Down Expand Up @@ -192,5 +197,4 @@ Bundler/OrderedGems:
Enabled: true
TreatCommentsAsGroupSeparators: false
Gemspec/DevelopmentDependencies:
Enabled: true
EnforcedStyle: Gemfile
Enabled: false
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# instabug-stores-upload plugin
# instabug_stores_upload plugin

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

## Getting Started

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:
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:

```bash
fastlane add_plugin instabug-stores-upload
fastlane add_plugin instabug_stores_upload
```

## About instabug-stores-upload
## About instabug_stores_upload

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.

Expand Down
17 changes: 9 additions & 8 deletions fastlane-plugin-instabug-stores-upload.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'fastlane/plugin/instabug_stores_upload/version'

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

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rubocop', '1.50.2'
spec.add_development_dependency 'rubocop-require_tools'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'fastlane', '~> 2.228.0'
spec.add_development_dependency('bundler')
spec.add_development_dependency('fastlane', '~> 2.228.0')
spec.add_development_dependency('rake')
spec.add_development_dependency('rspec')
spec.add_development_dependency('rubocop', '1.50.2')
spec.add_development_dependency('rubocop-performance')
spec.add_development_dependency('rubocop-require_tools')
spec.add_development_dependency('simplecov')
end
32 changes: 16 additions & 16 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Example lane for building iOS app with Instabug reporting
lane :build_ios_app do |options|
branch_name = options[:branch_name]

instabug_build_ios_app(
branch_name: branch_name,
instabug_api_key: ENV["INSTABUG_API_KEY"],
branch_name:,
instabug_api_key: ENV.fetch("INSTABUG_API_KEY", nil),
# All standard build_ios_app parameters are supported
workspace: "MyApp.xcworkspace",
scheme: "MyApp",
Expand All @@ -18,42 +18,42 @@ end
# Example lane for building Android app with Instabug reporting
lane :build_android_app do |options|
branch_name = options[:branch_name]

instabug_build_android_app(
branch_name: branch_name,
instabug_api_key: ENV["INSTABUG_API_KEY"],
branch_name:,
instabug_api_key: ENV.fetch("INSTABUG_API_KEY", nil),
# All standard gradle parameters are supported
task: "assembleRelease",
project_dir: "android/",
properties: {
"android.injected.signing.store.file" => "keystore.jks",
"android.injected.signing.store.password" => ENV["KEYSTORE_PASSWORD"],
"android.injected.signing.store.password" => ENV.fetch("KEYSTORE_PASSWORD", nil),
"android.injected.signing.key.alias" => "key0",
"android.injected.signing.key.password" => ENV["KEY_PASSWORD"]
"android.injected.signing.key.password" => ENV.fetch("KEY_PASSWORD", nil)
}
)
end

# Example lane for uploading to App Store with Instabug reporting
lane :upload_to_app_store do |options|
branch_name = options[:branch_name]

instabug_upload_to_app_store(
branch_name: branch_name,
instabug_api_key: ENV["INSTABUG_API_KEY"],
branch_name:,
instabug_api_key: ENV.fetch("INSTABUG_API_KEY", nil),
# All standard upload_to_app_store parameters are supported
ipa: "path/to/your/app.ipa",
skip_waiting_for_build_processing: true
)
end

# Example lane for uploading to Play Store with Instabug reporting
# Example lane for uploading to Play Store with Instabug reporting
lane :upload_to_play_store do |options|
branch_name = options[:branch_name]
branch_name = options[:branch_name]

instabug_upload_to_play_store(
branch_name: branch_name,
instabug_api_key: ENV["INSTABUG_API_KEY"],
branch_name:,
instabug_api_key: ENV.fetch("INSTABUG_API_KEY", nil),
# All standard upload_to_play_store parameters are supported
aab: "path/to/your/app.aab",
track: "internal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,71 @@ module Actions
class InstabugBuildAndroidAppAction < Action
def self.run(params)
UI.message("Starting Instabug Android build...")

# Extract Instabug-specific parameters
branch_name = params.delete(:branch_name)
instabug_api_key = params.delete(:instabug_api_key)
branch_name = params[:branch_name]
instabug_api_key = params[:instabug_api_key]

# Validate required parameters
if branch_name.nil? || branch_name.empty?
UI.user_error!("branch_name is required for Instabug reporting")
end


# Filter out Instabug-specific parameters before passing to gradle
filtered_params = Helper::InstabugStoresUploadHelper.filter_instabug_params(params, Actions::GradleAction)

begin
# Report build start to Instabug
Helper::InstabugStoresUploadHelper.report_status(
branch_name: branch_name,
branch_name:,
api_key: instabug_api_key,
status: "inprogress",
step: "build_app"
)

# Start timing the build
build_start_time = Time.now

# Execute the actual Android build using gradle
result = Actions::GradleAction.run(params)
result = Actions::GradleAction.run(filtered_params)

# Calculate build time in seconds
build_time = (Time.now - build_start_time).round

# Extract Android build path (APK or AAB)
build_path = fetch_android_build_path(Actions.lane_context)

if build_path.nil? || build_path.empty?
UI.user_error!("Could not find any generated APK or AAB. Please check your gradle settings.")
else
UI.success("Successfully found build artifact(s) at: #{build_path}")
end

# Report build success to Instabug
Helper::InstabugStoresUploadHelper.report_status(
branch_name: branch_name,
branch_name:,
api_key: instabug_api_key,
status: "success",
step: "build_app"
step: "build_app",
extras: {
build_time:,
build_path: Array(build_path)
}
)

UI.success("Android build completed successfully!")
result
rescue => e
UI.error("Android build failed: #{e.message}")
rescue StandardError => e
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
UI.error("Android build failed: #{error_message}")

# Report build failure to Instabug
Helper::InstabugStoresUploadHelper.report_status(
branch_name: branch_name,
branch_name:,
api_key: instabug_api_key,
status: "failure",
step: "build_app"
step: "build_app",
error_message: error_message
)
raise e
end
Expand All @@ -71,7 +95,7 @@ def self.details
def self.available_options
# Start with the original gradle options
options = Actions::GradleAction.available_options

# Add Instabug-specific options
instabug_options = [
FastlaneCore::ConfigItem.new(
Expand All @@ -88,9 +112,17 @@ def self.available_options
optional: false,
type: String,
sensitive: true
)
),
FastlaneCore::ConfigItem.new(
key: :instabug_api_base_url,
env_name: "INSTABUG_API_BASE_URL",
description: "Instabug API base URL (defaults to https://api.instabug.com)",
optional: true,
type: String,
skip_type_validation: true # Since we don't extract this param
)
]

# Combine both sets of options
options + instabug_options
end
Expand Down Expand Up @@ -119,6 +151,24 @@ def self.example_code
def self.category
:building
end

# This helper method provides a clean and prioritized way to get the Android build output.
# It checks for the most common output types in a specific order.
# This is used to get the build path for the Android build artifact.
def self.fetch_android_build_path(lane_context)
build_keys = [
SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS,
SharedValues::GRADLE_APK_OUTPUT_PATH,
SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS,
SharedValues::GRADLE_AAB_OUTPUT_PATH
]
Comment on lines +159 to +164
Copy link

@ahmedhany98 ahmedhany98 Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could return (array / string / nil).
And we should always send the build_path as an array to match the TDD.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied.

build_keys.each do |build_key|
build_path = lane_context[build_key]
return build_path if build_path && !build_path.empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return build_path if build_path && !build_path.empty?
return build_path if build_path.present?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.present? requires active support and we don't have Rails here.
So, I will keep the current implementation.

end

nil
end
end
end
end
end
Loading