diff --git a/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/actions/build_and_deploy_action.rb b/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/actions/build_and_deploy_action.rb index 6656043..972175d 100644 --- a/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/actions/build_and_deploy_action.rb +++ b/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/actions/build_and_deploy_action.rb @@ -21,25 +21,19 @@ module Fastlane # Decrypt the keys archive and Extract the keys archive Helper::IosCdHelper.decrypt_ios_keys('.') - UI.message("👉🏼 Credentials decrypted.") + UI.message("🍺 Credentials decrypted.") # Retrieve credentials creds = Helper::IosCdHelper.parse_ios_credentials('.') - UI.message("👉🏼 Credentials parsed.") + UI.message("🍺 Credentials parsed.") # Delete decrypted artifacts artifacts = ['ios_keys.zip', 'ios_credentials.json'] - artifacts.each do |file| - File.delete(file) if File.exist?(file) - end + Helper::IosCdHelper.delete_artifacts(artifacts) # Check credentials required_fields = ['developer_app_id', 'username', 'developer_app_identifier', 'app_identifier_extensions', 'apple_issuer_id', 'apple_key_id', 'team_id', 'team_name', 'apple_key_content', 'git_url', 'git_basic_authorization', 'provisioning_profiles', 'temp_keychain_user', 'temp_keychain_password'] - missing_fields = required_fields - creds.keys - - unless missing_fields.empty? - raise ArgumentError, "❌ missing keys in credential json file : #{missing_fields}" - end + Helper::IosCdHelper.check_required_fields(required_fields, creds.keys) # Delete keychain if existing if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db")) @@ -55,7 +49,7 @@ module Fastlane unlock: false, timeout: 0 ) - UI.message("👉🏼 New keychain created") + UI.message("🍺 New keychain created") # Obtain App Store Connect API key api_key = other_action.app_store_connect_api_key( @@ -65,7 +59,7 @@ module Fastlane duration: 500, in_house: false ) - UI.message("👉🏼 API Key formated") + UI.message("🍺 API Key formated") last_testflight_build_number = other_action.latest_testflight_build_number( @@ -82,7 +76,7 @@ module Fastlane build_number: last_testflight_build_number, xcodeproj: "Runner.xcodeproj" ) - UI.message("👉🏼 Build number incremented") + UI.message("🍺 Build number incremented") # Install Cocoapods other_action.cocoapods( @@ -91,7 +85,7 @@ module Fastlane integrate: true, podfile: "./Podfile" ) - UI.message("👉🏼 Pod got") + UI.message("🍺 Pod got") # Set up code signing using match # Configures and runs `match` which manages code signing certificates and provisioning profiles for the project. @@ -109,9 +103,9 @@ module Fastlane team_id: creds['team_id'].to_s, team_name: creds['team_name'].to_s, git_url: creds['git_url'].to_s, - storage_mode: "git", + storage_mode: "git" ) - UI.message("👉🏼 App signed") + UI.message("🍺 App signed") # Build and export app using Gym # Builds and packages an iOS app or framework for distribution to the App Store, TestFlight, or Enterprise distribution. @@ -123,7 +117,7 @@ module Fastlane provisioningProfiles: creds['provisioning_profiles'] } ) - UI.message("👉🏼 App built") + UI.message("🍺 App built") # Upload build to App Store Connect using Pilot other_action.pilot( @@ -146,9 +140,7 @@ module Fastlane # Delete build artifacts artifacts = ['Runner.app.dSYM.zip', 'Runner.ipa'] - artifacts.each do |file| - File.delete(file) if File.exist?(file) - end + Helper::IosCdHelper.delete_artifacts(artifacts) end def self.description diff --git a/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/helper/ios_cd_helper.rb b/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/helper/ios_cd_helper.rb index 939f5cf..24178ad 100644 --- a/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/helper/ios_cd_helper.rb +++ b/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/helper/ios_cd_helper.rb @@ -41,6 +41,28 @@ module Fastlane UI.user_error!("❌ Ios credentials doesn't exist") puts("json file doesn't exist") end + + def self.check_required_fields(required_fields, json) + missing_fields = required_fields - json + + unless missing_fields.empty? + raise ArgumentError, "❌ missing keys in credential json file : #{missing_fields}" + end + end + + def self.check_environment_variables(variables) + variables.each do |variable| + unless ENV.key?(variable) + raise "❌ The environment variable '#{variable}' is not defined." + end + end + end + + def self.delete_artifacts(artifacts) + artifacts.each do |file| + File.delete(file) if File.exist?(file) + end + end end end end