feat: remove artifacts (#15), check for match password (close #13), and check json key (close #11)

This commit is contained in:
Malo Léon 2023-06-09 16:37:06 +02:00
parent 45d8528b3e
commit 5f9e60e254
2 changed files with 35 additions and 8 deletions

View File

@ -5,11 +5,16 @@ module Fastlane
module Actions module Actions
class BuildAndDeployAction < Action class BuildAndDeployAction < Action
def self.run(params) def self.run(params)
# Check parameters # Check parameters
unless Helper::IosCdHelper.is_set(params[:beta_type]) unless Helper::IosCdHelper.is_set(params[:beta_type])
UI.user_error("❌ Parameters beta_type cannot be null") raise ArgumentError, "❌ Parameters beta_type cannot be null"
puts("Error on beta type parameter") 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 end
UI.message("⌛️ Building and deploying to Store in #{params[:beta_type]}..") UI.message("⌛️ Building and deploying to Store in #{params[:beta_type]}..")
@ -19,9 +24,23 @@ module Fastlane
UI.message("👉🏼 Credentials decrypted.") UI.message("👉🏼 Credentials decrypted.")
# Retrieve credentials # Retrieve credentials
creds = Helper::IosCdHelper.parseIosCredentials('.') 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
# 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 # Delete keychain if existing
if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db")) if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db"))
other_action.delete_keychain( other_action.delete_keychain(
@ -83,7 +102,7 @@ module Fastlane
api_key: api_key, api_key: api_key,
type: 'appstore', type: 'appstore',
app_identifier: creds['app_identifier_extensions'], 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_name: creds['temp_keychain_user'].to_s,
keychain_password: creds['temp_keychain_password'].to_s, keychain_password: creds['temp_keychain_password'].to_s,
git_url: creds['git_url'].to_s, git_url: creds['git_url'].to_s,
@ -125,6 +144,12 @@ module Fastlane
name: creds['temp_keychain_user'] name: creds['temp_keychain_user']
) )
end end
# Delete build artifacts
artifacts = ['Runner.app.dSYM.zip', 'Runner.ipa']
artifacts.each do |file|
File.delete(file) if File.exist?(file)
end
end end
def self.description def self.description

View File

@ -15,6 +15,8 @@ module Fastlane
# Decrypts ios credentials # Decrypts ios credentials
def self.decrypt_ios_keys(ios_directory) def self.decrypt_ios_keys(ios_directory)
# Define the GPG command with options # 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']} \ 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" --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 # Move the extracted files to the current directory
`jar xvf #{ios_directory}/ios_keys.zip && mv #{ios_directory}/ios_keys/* #{ios_directory}` `jar xvf #{ios_directory}/ios_keys.zip && mv #{ios_directory}/ios_keys/* #{ios_directory}`
else 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
end end
# Parse credential file # Parse credential file
def self.parseIosCredentials(ios_directory) def self.parse_ios_credentials(ios_directory)
if File.exist?("#{ios_directory}/ios_credentials.json") if File.exist?("#{ios_directory}/ios_credentials.json")
# Read file and decrypt it # Read file and decrypt it
file = File.read("#{ios_directory}/ios_credentials.json") file = File.read("#{ios_directory}/ios_credentials.json")
JSON.parse(file) JSON.parse(file)
else else
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
end end