From 37cbf76fc998252e80e4c78ae5a14d6268ffa1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Mon, 15 May 2023 19:01:48 +0200 Subject: [PATCH 1/7] style: update error message with more consistency --- .../plugin/android_cd/actions/build_and_deploy_action.rb | 2 +- .../lib/fastlane/plugin/android_cd/actions/promote_action.rb | 4 ++-- .../fastlane/plugin/android_cd/helper/android_cd_helper.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb index 92552ef..f662a22 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb @@ -7,7 +7,7 @@ module Fastlane def self.run(params) # Check parameters unless Helper::AndroidCdHelper.is_set(params[:beta_type]) - UI.error("❌ Parameters beta_type cannot be null") + UI.user_error("❌ Parameters beta_type cannot be null") puts("Error on beta type parameter") end diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb index e3c9ef4..826e67c 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb @@ -7,13 +7,13 @@ module Fastlane def self.run(params) # Check from parameters unless Helper::AndroidCdHelper.is_set(params[:from]) - UI.error("❌ Parameters from cannot be null") + UI.user_error("❌ Parameters from cannot be null") puts("Error on beta type parameter") end # Check destination parameters unless Helper::AndroidCdHelper.is_set(params[:destination]) - UI.error("❌ Parameters destination cannot be null") + UI.user_error("❌ Parameters destination cannot be null") puts("Error on beta type parameter") end diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb index adb8c05..438c74d 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb @@ -17,7 +17,7 @@ module Fastlane # Move the extracted files to the current directory `jar xvf #{android_directory} && mv #{android_directory}/android_keys/* #{android_directory}` else - puts("Erreur lors de la décompression du fichier GPG") + UI.user_error("❌ Erreur lors de la décompression du fichier GPG") end end -- 2.47.2 From 0207a311b51d4e553419f4c873af9f663409e4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Mon, 15 May 2023 19:02:44 +0200 Subject: [PATCH 2/7] style: remove unecesary puts lines --- .../lib/fastlane/plugin/android_cd/actions/promote_action.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb index 826e67c..180cea2 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb @@ -8,13 +8,11 @@ module Fastlane # Check from parameters unless Helper::AndroidCdHelper.is_set(params[:from]) UI.user_error("❌ Parameters from cannot be null") - puts("Error on beta type parameter") end # Check destination parameters unless Helper::AndroidCdHelper.is_set(params[:destination]) UI.user_error("❌ Parameters destination cannot be null") - puts("Error on beta type parameter") end UI.message("⌛️ Promoting to Google Play Store from #{params[:from]} to #{params[:destination]}..") -- 2.47.2 From 76723e2185aac2532726e2cfb4e0d03854686f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Mon, 15 May 2023 19:07:10 +0200 Subject: [PATCH 3/7] refactor: remove class call with other_action --- .../plugin/android_cd/actions/build_and_deploy_action.rb | 8 ++++---- .../fastlane/plugin/android_cd/actions/promote_action.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb index f662a22..53f9935 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb @@ -17,13 +17,13 @@ module Fastlane Helper::AndroidCdHelper.decrypt_android_keys('.') # Clean the project before building - Fastlane::Actions.gradle(task: "clean") + other_action.gradle(task: "clean") # Set the build number based on the number of commits - build_number = Fastlane::Actions.number_of_commits + build_number = other_action.number_of_commits # Build the Android App Bundle - Actions(GradleAction.run( + other_action.gradle( task: "bundle", build_type: "Release", print_command: true, @@ -33,7 +33,7 @@ module Fastlane )) # Upload the Android App Bundle to the Play Store - Actions::UploadToPlayStoreAction.run( + other_action.upload_to_play_store( track: params[:beta_type], json_key: './service_account_key.json', aab: '../build/app/outputs/bundle/release/app-release.aab', diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb index 180cea2..403bcfd 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb @@ -21,7 +21,7 @@ module Fastlane Helper::AndroidCdHelper.decrypt_android_keys('.') # Upload the Android App Bundle to the Play Store - Fastlane::Actions.upload_to_play_store( + other_action.upload_to_play_store( track: params[:from], json_key: './service_account_key.json', skip_upload_apk: true, -- 2.47.2 From a4f00101708647e8b72791b588e881ce455ff94a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Mon, 15 May 2023 19:34:10 +0200 Subject: [PATCH 4/7] refactor: user_error fn --- .../actions/build_and_deploy_action.rb | 16 ++++++++-------- .../plugin/android_cd/actions/promote_action.rb | 4 ++-- .../android_cd/helper/android_cd_helper.rb | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb index 53f9935..731aed1 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb @@ -7,7 +7,7 @@ module Fastlane def self.run(params) # Check parameters unless Helper::AndroidCdHelper.is_set(params[:beta_type]) - UI.user_error("❌ Parameters beta_type cannot be null") + UI.user_error!("❌ Parameters beta_type cannot be null") puts("Error on beta type parameter") end @@ -24,13 +24,13 @@ module Fastlane # Build the Android App Bundle other_action.gradle( - task: "bundle", - build_type: "Release", - print_command: true, - properties: { - "android.injected.version.code" => build_number - } - )) + task: "bundle", + build_type: "Release", + print_command: true, + properties: { + "android.injected.version.code" => build_number + } + ) # Upload the Android App Bundle to the Play Store other_action.upload_to_play_store( diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb index 403bcfd..5188e41 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/promote_action.rb @@ -7,12 +7,12 @@ module Fastlane def self.run(params) # Check from parameters unless Helper::AndroidCdHelper.is_set(params[:from]) - UI.user_error("❌ Parameters from cannot be null") + UI.user_error!("❌ Parameters from cannot be null") end # Check destination parameters unless Helper::AndroidCdHelper.is_set(params[:destination]) - UI.user_error("❌ Parameters destination cannot be null") + UI.user_error!("❌ Parameters destination cannot be null") end UI.message("⌛️ Promoting to Google Play Store from #{params[:from]} to #{params[:destination]}..") diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb index 438c74d..9921246 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/helper/android_cd_helper.rb @@ -17,7 +17,7 @@ module Fastlane # Move the extracted files to the current directory `jar xvf #{android_directory} && mv #{android_directory}/android_keys/* #{android_directory}` else - UI.user_error("❌ Erreur lors de la décompression du fichier GPG") + UI.user_error!("❌ Erreur lors de la décompression du fichier GPG") end end -- 2.47.2 From 6b7bc14451f571e15e6d13fcaffcd9660e49de6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Fri, 9 Jun 2023 16:37:06 +0200 Subject: [PATCH 5/7] feat: remove artifacts (#15), check for match password (close #13), and check json key (close #11) --- .../ios_cd/actions/build_and_deploy_action.rb | 35 ++++++++++++++++--- .../plugin/ios_cd/helper/ios_cd_helper.rb | 8 +++-- 2 files changed, 35 insertions(+), 8 deletions(-) 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 5ed1345..1b4ca22 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 @@ -5,11 +5,16 @@ module Fastlane module Actions class BuildAndDeployAction < Action def self.run(params) - # Check parameters unless Helper::IosCdHelper.is_set(params[:beta_type]) - UI.user_error("❌ Parameters beta_type cannot be null") - puts("Error on beta type parameter") + raise ArgumentError, "❌ Parameters beta_type cannot be null" + end + + # Check if match password exist + match_password = ENV['MATCH_PASSWORD'] + + if match_password.nil? || match_password.empty? + raise ArgumentError, "❌ match password must be provided" end UI.message("⌛️ Building and deploying to Store in #{params[:beta_type]}..") @@ -19,9 +24,23 @@ module Fastlane UI.message("👉🏼 Credentials decrypted.") # Retrieve credentials - creds = Helper::IosCdHelper.parseIosCredentials('.') + creds = Helper::IosCdHelper.parse_ios_credentials('.') 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 + + # 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 + # Delete keychain if existing if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db")) other_action.delete_keychain( @@ -83,7 +102,7 @@ module Fastlane api_key: api_key, type: 'appstore', app_identifier: creds['app_identifier_extensions'], - git_basic_authorization: Base64.strict_encode64(ENV["GIT_AUTHORIZATION"]), + git_basic_authorization: Base64.strict_encode64(creds['git_basic_authorization']), keychain_name: creds['temp_keychain_user'].to_s, keychain_password: creds['temp_keychain_password'].to_s, git_url: creds['git_url'].to_s, @@ -125,6 +144,12 @@ module Fastlane name: creds['temp_keychain_user'] ) end + + # Delete build artifacts + artifacts = ['Runner.app.dSYM.zip', 'Runner.ipa'] + artifacts.each do |file| + File.delete(file) if File.exist?(file) + end 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 d183935..3d771dc 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 @@ -15,6 +15,8 @@ module Fastlane # Decrypts ios credentials def self.decrypt_ios_keys(ios_directory) # Define the GPG command with options + system('echo test') + system("echo #{ENV['IOS_KEYS_SECRET_PASSPHRASE']}") gpg_command = "gpg --quiet --batch --yes --decrypt --passphrase=#{ENV['IOS_KEYS_SECRET_PASSPHRASE']} \ --output #{ios_directory}/ios_keys.zip #{ios_directory}/ios_keys.zip.gpg" @@ -26,19 +28,19 @@ module Fastlane # Move the extracted files to the current directory `jar xvf #{ios_directory}/ios_keys.zip && mv #{ios_directory}/ios_keys/* #{ios_directory}` else - UI.user_error("❌ Erreur lors de la décompression du fichier GPG") + UI.user_error!("❌ Erreur lors de la décompression du fichier GPG") end end # Parse credential file - def self.parseIosCredentials(ios_directory) + def self.parse_ios_credentials(ios_directory) if File.exist?("#{ios_directory}/ios_credentials.json") # Read file and decrypt it file = File.read("#{ios_directory}/ios_credentials.json") JSON.parse(file) else - UI.user_error("❌ Ios credentials doesn't exist") + UI.user_error!("❌ Ios credentials doesn't exist") puts("json file doesn't exist") end end -- 2.47.2 From d86c49d7ba2d8027235b33b15ed67674783ee6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Fri, 9 Jun 2023 17:48:23 +0200 Subject: [PATCH 6/7] feat: script remove artifacts on android cd (close #15) --- .../plugin/android_cd/actions/build_and_deploy_action.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb index 731aed1..7762d14 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb @@ -44,6 +44,12 @@ module Fastlane version_code: build_number ) + # Delete artifacts files + artifacts = ['android_keys.zip', 'key.jks', 'key.properties', 'service_account_key.json'] + artifacts.each do |file| + File.delete(file) if File.exist?(file) + end + UI.success('🍺 Successfully build & deploy appbundle to Google Play Store') end -- 2.47.2 From 3c0d2b40cf8f671be8004de12b7b54d3a2a2cbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Fri, 9 Jun 2023 17:56:02 +0200 Subject: [PATCH 7/7] feat: add rase instead of user error in android script --- .../plugin/android_cd/actions/build_and_deploy_action.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb index 7762d14..ebe40c7 100644 --- a/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb +++ b/plugins/fastlane-plugin-android_cd/lib/fastlane/plugin/android_cd/actions/build_and_deploy_action.rb @@ -7,8 +7,7 @@ module Fastlane def self.run(params) # Check parameters unless Helper::AndroidCdHelper.is_set(params[:beta_type]) - UI.user_error!("❌ Parameters beta_type cannot be null") - puts("Error on beta type parameter") + raise ArgumentError, "❌ Parameters beta_type cannot be null" end UI.message("⌛️ Building and deploying to Google Play Store in #{params[:beta_type]}..") -- 2.47.2