Class: Fastlane::Actions::IonicAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::IonicAction
- Defined in:
- lib/fastlane/plugin/ionic/actions/ionic_action.rb
Constant Summary collapse
- ANDROID_ARGS_MAP =
valid action params
{ keystore_path: 'keystore', keystore_password: 'storePassword', key_password: 'password', keystore_alias: 'alias', build_number: 'versionCode', min_sdk_version: 'gradleArg=-PcdvMinSdkVersion', capacitor_no_fetch: 'capacitorNoFetch', android_package_type: 'packageType' }
- IOS_ARGS_MAP =
{ scheme: 'scheme', type: 'packageType', team_id: 'developmentTeam', provisioning_profile: 'provisioningProfile', build_flag: 'buildFlag' }
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .output ⇒ Object
Class Method Summary collapse
-
.build(params) ⇒ Object
actual building! (run step #2).
-
.check_platform(params) ⇒ Object
add platform if missing (run step #1).
- .get_android_args(params) ⇒ Object
-
.get_app_name ⇒ Object
app_name.
- .get_ios_args(params) ⇒ Object
-
.get_platform_args(params, platform_args_map) ⇒ Object
extract arguments only valid for the platform from all arguments + map action params to the cli param they will be used for.
- .run(params) ⇒ Object
-
.set_build_paths(params, release) ⇒ Object
export build paths (run step #3).
Class Method Details
.authors ⇒ Object
457 458 459 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 457 def self. ['ThatzOkay'] end |
.available_options ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 254 def self. [ FastlaneCore::ConfigItem.new( key: :platform, env_name: "CAPACITOR_PLATFORM", description: "Platform to build on. Should be either android or ios", is_string: true, default_value: '', verify_block: proc do |value| UI.user_error!("Platform should be either android or ios") unless ['', 'android', 'ios'].include? value end ), FastlaneCore::ConfigItem.new( key: :release, env_name: "CAPACITOR_RELEASE", description: "Build for release if true, or for debug if false", is_string: false, default_value: true, verify_block: proc do |value| UI.user_error!("Release should be boolean") unless [false, true].include? value end ), FastlaneCore::ConfigItem.new( key: :device, env_name: "CAPACITOR_DEVICE", description: "Build for device", is_string: false, default_value: true, verify_block: proc do |value| UI.user_error!("Device should be boolean") unless [false, true].include? value end ), FastlaneCore::ConfigItem.new( key: :prod, env_name: "IONIC_PROD", description: "Build for production", is_string: false, default_value: false, verify_block: proc do |value| UI.user_error!("Prod should be boolean") unless [false, true].include? value end ), FastlaneCore::ConfigItem.new( key: :type, env_name: "CAPACITOR_IOS_PACKAGE_TYPE", description: "This will determine what type of build is generated by Xcode. Valid options are development, enterprise, adhoc, and appstore", is_string: true, default_value: 'appstore', verify_block: proc do |value| UI.user_error!("Valid options are development, enterprise, adhoc, and appstore.") unless ['development', 'enterprise', 'adhoc', 'appstore', 'ad-hoc', 'app-store'].include? value end ), FastlaneCore::ConfigItem.new( key: :verbose, env_name: "CAPACITOR_VERBOSE", description: "Pipe out more verbose output to the shell", default_value: false, is_string: false, verify_block: proc do |value| UI.user_error!("Verbose should be boolean") unless [false, true].include? value end ), FastlaneCore::ConfigItem.new( key: :team_id, env_name: "CAPACITOR_IOS_TEAM_ID", description: "The development team (Team ID) to use for code signing", is_string: true, default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_id) ), FastlaneCore::ConfigItem.new( key: :scheme, env_name: "CAPACITOR_IOS_SCHEME", description: "The Schema of the app seen as in xcode", is_string: true, default_value: 'App' ), FastlaneCore::ConfigItem.new( key: :workspace, env_name: "CAPACITOR_IOS_WORKSPACE", description: "The xcode workspace file path", is_string: true, default_value: 'ios/App/App.xcworkspace' ), FastlaneCore::ConfigItem.new( key: :provisioning_profile, env_name: "CAPACITOR_IOS_PROVISIONING_PROFILE", description: "GUID of the provisioning profile to be used for signing", is_string: true, default_value: '' ), FastlaneCore::ConfigItem.new( key: :android_package_type, env_name: "CAPACITOR_ANDROID_PACKAGE_TYPE", description: "This will determine what type of Android build is generated. Valid options are apk or bundle", default_value: 'apk', verify_block: proc do |value| UI.user_error!("Valid options are apk or bundle.") unless ['apk', 'bundle'].include? value end ), FastlaneCore::ConfigItem.new( key: :keystore_path, env_name: "CAPACITOR_ANDROID_KEYSTORE_PATH", description: "Path to the Keystore for Android", is_string: true, default_value: '' ), FastlaneCore::ConfigItem.new( key: :keystore_password, env_name: "CAPACITOR_ANDROID_KEYSTORE_PASSWORD", description: "Android Keystore password", is_string: true, default_value: '' ), FastlaneCore::ConfigItem.new( key: :key_password, env_name: "CAPACITOR_ANDROID_KEY_PASSWORD", description: "Android Key password (default is keystore password)", is_string: true, default_value: '' ), FastlaneCore::ConfigItem.new( key: :keystore_alias, env_name: "CAPACITOR_ANDROID_KEYSTORE_ALIAS", description: "Android Keystore alias", is_string: true, default_value: '' ), FastlaneCore::ConfigItem.new( key: :build_number, env_name: "CAPACITOR_BUILD_NUMBER", description: "Sets the build number for iOS and version code for Android", optional: true, is_string: false ), FastlaneCore::ConfigItem.new( key: :browserify, env_name: "CAPACITOR_BROWSERIFY", description: "Specifies whether to browserify build or not", default_value: false, is_string: false ), FastlaneCore::ConfigItem.new( key: :capacitor_prepare, env_name: "CAPACITOR_PREPARE", description: "Specifies whether to run `ionic capacitor prepare` before building", default_value: true, is_string: false ), FastlaneCore::ConfigItem.new( key: :min_sdk_version, env_name: "CAPACITOR_ANDROID_MIN_SDK_VERSION", description: "Overrides the value of minSdkVersion set in AndroidManifest.xml", default_value: '', is_string: false ), FastlaneCore::ConfigItem.new( key: :capacitor_no_fetch, env_name: "CAPACITOR_NO_FETCH", description: "Call `capacitor platform add` with `--nofetch` parameter", default_value: false, is_string: false ), FastlaneCore::ConfigItem.new( key: :capacitor_no_resources, env_name: "CAPACITOR_NO_RESOURCES", description: "Call `capacitor platform add` with `--no-resources` parameter", default_value: false, is_string: false ), FastlaneCore::ConfigItem.new( key: :build_flag, env_name: "CAPACITOR_IOS_BUILD_FLAG", description: "An array of Xcode buildFlag. Will be appended on compile command", is_string: false, optional: true, default_value: [] ), FastlaneCore::ConfigItem.new( key: :capacitor_build_config_file, env_name: "CAPACITOR_BUILD_CONFIG_FILE", description: "Call `ionic capacitor compile` with `--buildConfig=<ConfigFile>` to specify build config file path", is_string: true, optional: true, default_value: '' ), FastlaneCore::ConfigItem.new( key: :skip_asset_gen, env_name: "SKIP_ASSET_GEN", description: "Skip generation of assets", is_string: false, optional: true, default_value: false ) ] end |
.build(params) ⇒ Object
actual building! (run step #2)
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 99 def self.build(params) args = [params[:release] ? '--prod' : '--debug'] args << '--device' if params[:device] args << '--prod' if params[:prod] args << '--browserify' if params[:browserify] args << '--verbose' if params[:verbose] unless params[:capacitor_build_config_file].to_s.empty? args << "--buildConfig=#{Shellwords.escape(params[:capacitor_build_config_file])}" end android_args = self.get_android_args(params) if params[:platform].to_s == 'android' ios_args = self.get_ios_args(params) if params[:platform].to_s == 'ios' # special handling for `build_number` param if params[:platform].to_s == 'ios' && !params[:build_number].to_s.empty? cf_bundle_version = params[:build_number].to_s Actions::UpdateInfoPlistAction.run( xcodeproj: "./ios/#{self.get_app_name}.xcodeproj", plist_path: "#{self.get_app_name}/#{self.get_app_name}-Info.plist", block: lambda { |plist| plist['CFBundleVersion'] = cf_bundle_version } ) end if params[:skip_asset_gen] == false is_windows = (ENV['OS'] == 'Windows_NT') if is_windows output = `powershell -Command "(gcm bunx).Path"` if !output.empty? if `bun pm ls`.include?('@capacitor/assets') sh "bunx capacitor-assets generate" end else if `npm list @capacitor/assets`.include?('@capacitor/assets') sh "npx capacitor-assets generate" end end else if !`which bunx`.empty? if `bun pm ls`.include?('@capacitor/assets') sh "bunx capacitor-assets generate" end else if `npm list @capacitor/assets`.include?('@capacitor/assets') sh "npx capacitor-assets generate" end end end end prod_flag = params[:release] ? '--prod' : '' sh "ionic capacitor build #{params[:platform]} --no-open #{prod_flag}" configuration = params[:release] ? 'release' : 'debug' if params[:platform].to_s == 'ios' latest_sdk = `xcodebuild -showsdks`.lines .select { |line| line.include?('iphoneos') } .last &.split &.last cmd = [ '/usr/bin/xcodebuild', "-sdk #{latest_sdk}", "-configuration #{configuration}", "-workspace #{params[:workspace]}", "-scheme #{params[:scheme]}", 'archive', "-archivePath ./#{params[:scheme]}", 'CODE_SIGN_STYLE=Automatic', "DEVELOPMENT_TEAM=#{params[:team_id]}" ].join(' ') cmd += ' | xcpretty -r junit --no-color' if `which xcpretty`.strip != '' sh cmd sh '/usr/libexec/PlistBuddy -c Clear _XcodeTaskExportOptions.plist' sh "/usr/libexec/PlistBuddy -c \"Add :teamID string #{params[:team_id]}\" _XcodeTaskExportOptions.plist" sh "/usr/libexec/PlistBuddy -c \"Add :method string #{params[:type]}\" _XcodeTaskExportOptions.plist" archive_cmd = [ '/usr/bin/xcodebuild', '-exportArchive', "-archivePath ./#{params[:scheme]}.xcarchive", "-exportPath ./output/#{latest_sdk}/#{configuration}", '-exportOptionsPlist _XcodeTaskExportOptions.plist' ] sh archive_cmd elsif params[:platform].to_s == 'android' sh "ionic capacitor build #{params[:platform]} --no-open #{prod_flag}" if params[:android_package_type] == 'bundle' if !params[:keystore_path].empty? sh "./android/gradlew --project-dir android app:bundleRelease -Pandroid.injected.signing.store.file=#{params[:keystore_path]} -Pandroid.injected.signing.store.password=#{params[:keystore_password]} -Pandroid.injected.signing.key.alias=#{params[:keystore_alias]} -Pandroid.injected.signing.key.password=#{params[:key_password]}" else sh "./android/gradlew --project-dir android app:bundleRelease" end else if !params[:keystore_path].empty? sh "./android/gradlew --project-dir android app:assembleRelease -Pandroid.injected.signing.store.file=#{params[:keystore_path]} -Pandroid.injected.signing.store.password=#{params[:keystore_password]} -Pandroid.injected.signing.key.alias=#{params[:keystore_alias]} -Pandroid.injected.signing.key.password=#{params[:key_password]}" else sh "./android/gradlew --project-dir android app:assembleRelease" end end end end |
.category ⇒ Object
479 480 481 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 479 def self.category :building end |
.check_platform(params) ⇒ Object
add platform if missing (run step #1)
82 83 84 85 86 87 88 89 90 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 82 def self.check_platform(params) platform = params[:platform] args = [] args << '--nofetch' if params[:capacitor_no_fetch] args << '--no-resources' if params[:capacitor_no_resources] if platform && !File.directory?("./#{platform}") sh "ionic capacitor platform add #{platform} --no-interactive #{args.join(' ')}" end end |
.description ⇒ Object
246 247 248 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 246 def self.description "Build your Ionic app" end |
.details ⇒ Object
250 251 252 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 250 def self.details "Easily integrate your Ionic build into a Fastlane setup" end |
.example_code ⇒ Object
465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 465 def self.example_code [ "ionic( platform: 'ios' )", "ionic( platform: 'android', keystore_path: './staging.keystore', keystore_alias: 'alias_name', keystore_password: 'store_password' )" ] end |
.get_android_args(params) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 55 def self.get_android_args(params) if params[:key_password].empty? params[:key_password] = params[:keystore_password] end return self.get_platform_args(params, ANDROID_ARGS_MAP) end |
.get_app_name ⇒ Object
app_name
93 94 95 96 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 93 def self.get_app_name config = JSON.parse(File.read('ionic.config.json')) return config['name'] end |
.get_ios_args(params) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 63 def self.get_ios_args(params) app_identifier = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier) if params[:provisioning_profile].empty? # If `match` or `sigh` were used before this, use the certificates returned from there params[:provisioning_profile] = ENV['SIGH_UUID'] || ENV["sigh_#{app_identifier}_#{params[:type].sub('-', '')}" || ""] end if params[:type] == 'adhoc' params[:type] = 'ad-hoc' end if params[:type] == 'appstore' params[:type] = 'app-store' end return self.get_platform_args(params, IOS_ARGS_MAP) end |
.get_platform_args(params, platform_args_map) ⇒ Object
extract arguments only valid for the platform from all arguments + map action params to the cli param they will be used for
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 32 def self.get_platform_args(params, platform_args_map) platform_args = [] platform_args_map.each do |action_key, cli_param| param_value = params[action_key] # handle `build_flag` being an Array if action_key.to_s == 'build_flag' && param_value.kind_of?(Array) unless param_value.empty? param_value.each do |flag| platform_args << "--#{cli_param}=#{flag.shellescape}" end end # handle all other cases else if !param_value.to_s.empty? && param_value.kind_of?(String) platform_args << "--#{cli_param}=#{param_value.shellescape}" end end end return platform_args.join(' ') end |
.is_supported?(platform) ⇒ Boolean
461 462 463 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 461 def self.is_supported?(platform) true end |
.output ⇒ Object
450 451 452 453 454 455 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 450 def self.output [ ['CAPACITOR_ANDROID_RELEASE_BUILD_PATH', 'Path to the signed release APK or AAB if it was generated'], ['CAPACITOR_IOS_RELEASE_BUILD_PATH', 'Path to the signed release IPA if it was generated'] ] end |
.run(params) ⇒ Object
236 237 238 239 240 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 236 def self.run(params) self.check_platform(params) self.build(params) self.set_build_paths(params, params[:release]) end |
.set_build_paths(params, release) ⇒ Object
export build paths (run step #3)
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/fastlane/plugin/ionic/actions/ionic_action.rb', line 208 def self.set_build_paths(params, release) app_name = self.get_app_name build_type = release ? 'release' : 'debug' # Update the build path accordingly if Android is being # built as an Android Application Bundle. android_package_type = params[:android_package_type] || 'apk' android_package_extension = android_package_type == 'bundle' ? '.aab' : '.apk' is_signed = !params[:keystore_path].empty? signed = is_signed ? '' : '-unsigned' ENV['CAPACITOR_ANDROID_RELEASE_BUILD_PATH'] = "./android/app/build/outputs/#{android_package_type}/#{build_type}/app-#{build_type}#{signed}#{android_package_extension}" configuration = params[:release] ? 'release' : 'debug' if params[:platform].to_s == 'ios' latest_sdk = `xcodebuild -showsdks`.lines .select { |line| line.include?('iphoneos') } .last &.split &.last ENV['CAPACITOR_IOS_RELEASE_BUILD_PATH'] = "./output/#{latest_sdk}/#{configuration}/#{params[:scheme]}.ipa" end # TODO: https://github.com/bamlab/fastlane-plugin-cordova/issues/7 # TODO: Set env vars that gym and Co automatically use end |