From c4be015c0ff77da08a3f870b783c49458f407891 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Wed, 31 Jul 2019 03:09:02 +0300 Subject: [PATCH 1/3] add removing functionality for ManuallyUpdateCodeSigning lane --- xcode/commonFastfile | 49 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 73e596c..91ccc2f 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -207,10 +207,26 @@ lane :ManuallyUpdateCodeSigning do |options| git_url = conf.config_file_options[:git_url] shallow_clone = false branch = 'fastlane_certificates' - storage = Match::Storage.for_mode('git', { git_url: git_url, shallow_clone: shallow_clone, git_branch: branch, clone_branch_directly: false}) - storage.download - encryption = Match::Encryption.for_storage_mode('git', { git_url: git_url, working_directory: storage.working_directory}) - encryption.decrypt_files + + storage_conf = lambda do + new_storage = Match::Storage.for_mode('git', { git_url: git_url, shallow_clone: shallow_clone, git_branch: branch, clone_branch_directly: false}) + new_storage.download + return new_storage + end + + encryption_conf = lambda do |stor| + new_encryption = Match::Encryption.for_storage_mode('git', { git_url: git_url, working_directory: stor.working_directory}) + new_encryption.decrypt_files + return new_encryption + end + + get_all_files = lambda do |stor| + return Dir[File.join(stor.working_directory, "**", "*.{cer,p12,mobileprovision}")] + end + + storage = storage_conf.call + encryption = encryption_conf.call(storage) + old_files = get_all_files.call(storage) sh("open #{storage.working_directory}") @@ -220,10 +236,33 @@ lane :ManuallyUpdateCodeSigning do |options| encryption.encrypt_files - files_to_commit = Dir[File.join(storage.working_directory, "**", "*.{cer,p12,mobileprovision}")] + files_to_commit = get_all_files.call(storage) + old_directory = storage.working_directory storage.save_changes!(files_to_commit: files_to_commit) + + + # need to check, because saving changes with delete is another function (update repo if needed) + files_diff = old_files - files_to_commit + + if files_diff.length > 0 + storage = storage_conf.call + encryption = encryption_conf.call(storage) + + files_to_delete = files_diff.map do |file| + old_file = file + old_file.slice! old_directory + new_file = File.join(storage.working_directory, old_file) + File.delete(new_file) if File.exist?(new_file) + file = new_file + end + + encryption.encrypt_files + storage.save_changes!(files_to_delete: files_to_delete) + end + end + def get_keychain_options(options) keychain_name = options[:keychain_name] keychain_password = options[:keychain_password] From 373792222e3d0fe344514da4101ae62a679b1e77 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Wed, 31 Jul 2019 12:43:32 +0300 Subject: [PATCH 2/3] refactor --- xcode/commonFastfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 91ccc2f..36ece68 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -214,18 +214,18 @@ lane :ManuallyUpdateCodeSigning do |options| return new_storage end - encryption_conf = lambda do |stor| + encryption_conf_for_storage = lambda do |stor| new_encryption = Match::Encryption.for_storage_mode('git', { git_url: git_url, working_directory: stor.working_directory}) new_encryption.decrypt_files return new_encryption end get_all_files = lambda do |stor| - return Dir[File.join(stor.working_directory, "**", "*.{cer,p12,mobileprovision}")] + Dir[File.join(stor.working_directory, "**", "*.{cer,p12,mobileprovision}")] end storage = storage_conf.call - encryption = encryption_conf.call(storage) + encryption = encryption_conf_for_storage.call(storage) old_files = get_all_files.call(storage) sh("open #{storage.working_directory}") @@ -246,7 +246,7 @@ lane :ManuallyUpdateCodeSigning do |options| if files_diff.length > 0 storage = storage_conf.call - encryption = encryption_conf.call(storage) + encryption = encryption_conf_for_storage.call(storage) files_to_delete = files_diff.map do |file| old_file = file From 59b15d7db62f22874101e6e08c419697c5cd8532 Mon Sep 17 00:00:00 2001 From: Sergey Kopytov Date: Wed, 31 Jul 2019 14:29:48 +0300 Subject: [PATCH 3/3] add comment --- xcode/commonFastfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 36ece68..fe6cd0a 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -244,6 +244,9 @@ lane :ManuallyUpdateCodeSigning do |options| # need to check, because saving changes with delete is another function (update repo if needed) files_diff = old_files - files_to_commit + # match can not work with both save/delete functionality `You can't provide both files_to_delete and files_to_commit right now` + # to avoid this we use storage twice if needed + if files_diff.length > 0 storage = storage_conf.call encryption = encryption_conf_for_storage.call(storage)