refactor: move some fn in helper class

This commit is contained in:
Malo Léon 2023-07-05 16:38:57 +02:00
parent f1141a78ad
commit 385e7c05a9
2 changed files with 34 additions and 20 deletions

View File

@ -21,25 +21,19 @@ module Fastlane
# Decrypt the keys archive and Extract the keys archive # Decrypt the keys archive and Extract the keys archive
Helper::IosCdHelper.decrypt_ios_keys('.') Helper::IosCdHelper.decrypt_ios_keys('.')
UI.message("👉🏼 Credentials decrypted.") UI.message("🍺 Credentials decrypted.")
# Retrieve credentials # Retrieve credentials
creds = Helper::IosCdHelper.parse_ios_credentials('.') creds = Helper::IosCdHelper.parse_ios_credentials('.')
UI.message("👉🏼 Credentials parsed.") UI.message("🍺 Credentials parsed.")
# Delete decrypted artifacts # Delete decrypted artifacts
artifacts = ['ios_keys.zip', 'ios_credentials.json'] artifacts = ['ios_keys.zip', 'ios_credentials.json']
artifacts.each do |file| Helper::IosCdHelper.delete_artifacts(artifacts)
File.delete(file) if File.exist?(file)
end
# Check credentials # 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'] 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 Helper::IosCdHelper.check_required_fields(required_fields, creds.keys)
unless missing_fields.empty?
raise ArgumentError, "❌ missing keys in credential json file : #{missing_fields}"
end
# Delete keychain if existing # Delete keychain if existing
if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db")) if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db"))
@ -55,7 +49,7 @@ module Fastlane
unlock: false, unlock: false,
timeout: 0 timeout: 0
) )
UI.message("👉🏼 New keychain created") UI.message("🍺 New keychain created")
# Obtain App Store Connect API key # Obtain App Store Connect API key
api_key = other_action.app_store_connect_api_key( api_key = other_action.app_store_connect_api_key(
@ -65,7 +59,7 @@ module Fastlane
duration: 500, duration: 500,
in_house: false in_house: false
) )
UI.message("👉🏼 API Key formated") UI.message("🍺 API Key formated")
last_testflight_build_number = last_testflight_build_number =
other_action.latest_testflight_build_number( other_action.latest_testflight_build_number(
@ -82,7 +76,7 @@ module Fastlane
build_number: last_testflight_build_number, build_number: last_testflight_build_number,
xcodeproj: "Runner.xcodeproj" xcodeproj: "Runner.xcodeproj"
) )
UI.message("👉🏼 Build number incremented") UI.message("🍺 Build number incremented")
# Install Cocoapods # Install Cocoapods
other_action.cocoapods( other_action.cocoapods(
@ -91,7 +85,7 @@ module Fastlane
integrate: true, integrate: true,
podfile: "./Podfile" podfile: "./Podfile"
) )
UI.message("👉🏼 Pod got") UI.message("🍺 Pod got")
# Set up code signing using match # Set up code signing using match
# Configures and runs `match` which manages code signing certificates and provisioning profiles for the project. # 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_id: creds['team_id'].to_s,
team_name: creds['team_name'].to_s, team_name: creds['team_name'].to_s,
git_url: creds['git_url'].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 # Build and export app using Gym
# Builds and packages an iOS app or framework for distribution to the App Store, TestFlight, or Enterprise distribution. # 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'] provisioningProfiles: creds['provisioning_profiles']
} }
) )
UI.message("👉🏼 App built") UI.message("🍺 App built")
# Upload build to App Store Connect using Pilot # Upload build to App Store Connect using Pilot
other_action.pilot( other_action.pilot(
@ -146,9 +140,7 @@ module Fastlane
# Delete build artifacts # Delete build artifacts
artifacts = ['Runner.app.dSYM.zip', 'Runner.ipa'] artifacts = ['Runner.app.dSYM.zip', 'Runner.ipa']
artifacts.each do |file| Helper::IosCdHelper.delete_artifacts(artifacts)
File.delete(file) if File.exist?(file)
end
end end
def self.description def self.description

View File

@ -41,6 +41,28 @@ module Fastlane
UI.user_error!("❌ Ios credentials doesn't exist") UI.user_error!("❌ Ios credentials doesn't exist")
puts("json file doesn't exist") puts("json file doesn't exist")
end 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 end
end end