From 7bee714ada2783dfcd530eb1934b00e8b920bf66 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 20 Feb 2019 17:19:26 +0300 Subject: [PATCH 01/29] update commonFastfile, so it won't run build scripts for non-build lanes --- xcode/commonFastfile | 48 +++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index d03a2f0..308854a 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -1,6 +1,6 @@ $appName = File.basename(Dir['../*.xcworkspace'].first, '.*') -before_all do |lane, options| +private_lane :beforeBuild do |options| appName = options[:appName] || $appName podsReposPath = File.expand_path "~/.cocoapods/repos/master/" lockFilePath = "#{podsReposPath}/.git/index.lock" @@ -24,33 +24,33 @@ before_all do |lane, options| ) end -after_all do |lane, options| - if options[:uploadToFabric] - appName = options[:appName] || $appName +private_lane :afterBuild do |options| + appName = options[:appName] || $appName + podsReposPath = File.expand_path "~/.cocoapods/repos/master/" + lockFilePath = "#{podsReposPath}/.git/index.lock" - token = sh("cat ../#{appName}.xcodeproj/project.pbxproj | grep 'Fabric/run' | awk '{print $4}' | tr -d '\\n'") - secret = sh("printf `cat ../#{appName}.xcodeproj/project.pbxproj | grep 'Fabric/run' | awk '{print $5}' | sed 's/..$//'` | tr -d '\\n'") - - releaseNotesFile = "release-notes.txt" - sh("touch ../#{releaseNotesFile}") - - crashlytics( - ipa_path: "./#{appName}.ipa", - crashlytics_path: "./Pods/Crashlytics/", - api_token: token, - build_secret: secret, - notes_path: releaseNotesFile, - groups: "touch-instinct" - ) - - upload_symbols_to_crashlytics( - dsym_path: "./#{appName}.app.dSYM.zip", - api_token: token - ) + # check if .lock file exists in pod repos - then remove all master repo + if File.exists? lockFilePath + sh("rm -rf #{podsReposPath}") end + + carthage(platform: "iOS") + + cocoapods( + clean: true, + repo_update: true + ) + + set_info_plist_value( + path: "./#{appName}/Info.plist", + key: "CFBundleVersion", + value: options[:buildNumber] || 10000 + ) end private_lane :buildConfiguration do |options| + beforeBuild(options) + configuration = lane_context[SharedValues::LANE_NAME] method = configuration.start_with?("Enterprise") ? "enterprise" : "development" appName = options[:appName] || $appName @@ -71,4 +71,6 @@ private_lane :buildConfiguration do |options| export_options: exportOptions, skip_package_ipa: !uploadToFabric ) + + afterBuild(options) end From f6297210267fe187aa5ba9435d2bba1b453fa081 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 20 Feb 2019 18:40:59 +0300 Subject: [PATCH 02/29] add createPushCertificate and syncCodeSignning private lanes --- xcode/commonFastfile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 308854a..a639e41 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -74,3 +74,34 @@ private_lane :buildConfiguration do |options| afterBuild(options) end + +private_lane :createPushCertificate do |options| + certificates_path = File.expand_path "../certificates" + Dir.mkdir(certificates_path) unless File.directory?(certificates_path) + + get_push_certificate( + development: true, + generate_p12: true, + active_days_limit: 30, # create new certificate if old one will expire in 30 days + save_private_key: false, + app_identifier: options[:app_identifier], + p12_password: "123", # empty password won't work with Pusher + output_path: certificates_path + ) +end + +private_lane :syncCodeSignning do |options| + keychain_password = prompt( + text: "Please enter your keychain password (account password): ", + secure_text: true + ) + + match( + app_identifier: options[:app_identifier], + type: "development", + readonly: true, + storage_mode: "git", + git_url: "git@github.com:petropavel13/FastlaneCertificates.git", + keychain_password: keychain_password + ) +end From 51271e8a2a585ec65c4c9d16de2966b95324e546 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 21 Feb 2019 13:29:57 +0300 Subject: [PATCH 03/29] try to use project repo as storage --- xcode/commonFastfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index a639e41..82d8abe 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -76,7 +76,7 @@ private_lane :buildConfiguration do |options| end private_lane :createPushCertificate do |options| - certificates_path = File.expand_path "../certificates" + certificates_path = File.expand_path "../pushcerts" Dir.mkdir(certificates_path) unless File.directory?(certificates_path) get_push_certificate( @@ -101,7 +101,10 @@ private_lane :syncCodeSignning do |options| type: "development", readonly: true, storage_mode: "git", - git_url: "git@github.com:petropavel13/FastlaneCertificates.git", - keychain_password: keychain_password + git_url: options[:git_url], + git_branch: "fastlane_certificates", + keychain_password: keychain_password, + skip_docs: true, + platform: "ios" ) end From 97d8f0edcf7ad82f0bfc3736cd5777763dd27df4 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 21 Feb 2019 14:20:36 +0300 Subject: [PATCH 04/29] split syncCodeSigning to getCodeSigning & updateCodeSigning --- xcode/commonFastfile | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 82d8abe..5a4bdd3 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -90,21 +90,32 @@ private_lane :createPushCertificate do |options| ) end -private_lane :syncCodeSignning do |options| +private_lane :syncCodeSigning do |options| + match( + app_identifier: options[:app_identifier], + type: "development", + readonly: options[:readonly] || true, + storage_mode: "git", + git_url: options[:git_url], + git_branch: "fastlane_certificates", + keychain_password: options[:keychain_password], + skip_docs: true, + platform: "ios" + ) +end + +private_lane :getCodeSigning do |options| keychain_password = prompt( text: "Please enter your keychain password (account password): ", secure_text: true ) - match( - app_identifier: options[:app_identifier], - type: "development", - readonly: true, - storage_mode: "git", - git_url: options[:git_url], - git_branch: "fastlane_certificates", - keychain_password: keychain_password, - skip_docs: true, - platform: "ios" - ) + options[:readonly] = true + options[:keychain_password] = keychain_password + syncCodeSigning(options) +end + +private_lane :updateCodeSigning do |options| + options[:readonly] = false + syncCodeSigning(options) end From 94f0291c3a0a1fa9c847a3ec91b08c2222293957 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 21 Feb 2019 14:38:26 +0300 Subject: [PATCH 05/29] ability to pass some parameters via options --- xcode/commonFastfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 5a4bdd3..3cab303 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -76,11 +76,11 @@ private_lane :buildConfiguration do |options| end private_lane :createPushCertificate do |options| - certificates_path = File.expand_path "../pushcerts" + certificates_path = File.expand_path "../Certificates" Dir.mkdir(certificates_path) unless File.directory?(certificates_path) get_push_certificate( - development: true, + development: options[:development] || true, generate_p12: true, active_days_limit: 30, # create new certificate if old one will expire in 30 days save_private_key: false, @@ -93,7 +93,7 @@ end private_lane :syncCodeSigning do |options| match( app_identifier: options[:app_identifier], - type: "development", + type: options[:type] || "development", readonly: options[:readonly] || true, storage_mode: "git", git_url: options[:git_url], From adb958d25c267d54c3fecc32d2191162d65edb6d Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 21 Feb 2019 14:49:14 +0300 Subject: [PATCH 06/29] make createPushCertificate public lane --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 3cab303..52275bc 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -75,7 +75,7 @@ private_lane :buildConfiguration do |options| afterBuild(options) end -private_lane :createPushCertificate do |options| +lane :createPushCertificate do |options| certificates_path = File.expand_path "../Certificates" Dir.mkdir(certificates_path) unless File.directory?(certificates_path) From 214ea3e5e2f38c20689748454eaa4bb66e86ff89 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 22 Feb 2019 14:24:25 +0300 Subject: [PATCH 07/29] load configuration options from yaml file --- xcode/commonFastfile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 52275bc..f1eebb4 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -91,9 +91,21 @@ lane :createPushCertificate do |options| end private_lane :syncCodeSigning do |options| + type = options[:type] || "development" + + configurations_path = "./fastlane/configurations.yaml" + if File.exists? configurations_path + require "yaml" + + configurations = YAML.load_file(configurations_path) + options.merge(configurations[type]) + end + match( app_identifier: options[:app_identifier], - type: options[:type] || "development", + username: options[:username] || options[:apple_id], + team_id: options[:team_id], + type: type, readonly: options[:readonly] || true, storage_mode: "git", git_url: options[:git_url], From b87aa69a4b9c32f9effc3d9cc2b99853d69ccb8d Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 22 Feb 2019 14:40:46 +0300 Subject: [PATCH 08/29] small refactor --- xcode/commonFastfile | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index f1eebb4..ccd1d76 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -93,13 +93,8 @@ end private_lane :syncCodeSigning do |options| type = options[:type] || "development" - configurations_path = "./fastlane/configurations.yaml" - if File.exists? configurations_path - require "yaml" - - configurations = YAML.load_file(configurations_path) - options.merge(configurations[type]) - end + options_override = load_options_from("configurations.yaml")[type] + options.merge(options_override) match( app_identifier: options[:app_identifier], @@ -131,3 +126,13 @@ private_lane :updateCodeSigning do |options| options[:readonly] = false syncCodeSigning(options) end + +def load_options_from(file_path) + if File.exists? file_path + require "yaml" + + return YAML.load_file(file_path) + end + + return nil +end From da9e84731b36fe3cba7b960535b50ccd962cd245 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 22 Feb 2019 15:33:16 +0300 Subject: [PATCH 09/29] symbolize hash keys --- xcode/commonFastfile | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index ccd1d76..318fb88 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -93,8 +93,8 @@ end private_lane :syncCodeSigning do |options| type = options[:type] || "development" - options_override = load_options_from("configurations.yaml")[type] - options.merge(options_override) + options_override = load_options_from("configurations.yaml")[type.to_sym] + options = options.merge(options_override) match( app_identifier: options[:app_identifier], @@ -107,7 +107,8 @@ private_lane :syncCodeSigning do |options| git_branch: "fastlane_certificates", keychain_password: options[:keychain_password], skip_docs: true, - platform: "ios" + platform: "ios", + verbose: true ) end @@ -131,8 +132,26 @@ def load_options_from(file_path) if File.exists? file_path require "yaml" - return YAML.load_file(file_path) + options = YAML.load_file(file_path) + + return symbolize_keys(options) end return nil end + +# http://www.virtuouscode.com/2009/07/14/recursively-symbolize-keys/ +def symbolize_keys(hash) + hash.inject({}){|result, (key, value)| + new_key = case key + when String then key.to_sym + else key + end + new_value = case value + when Hash then symbolize_keys(value) + else value + end + result[new_key] = new_value + result + } +end From 982532c200f60906f19f555f612cc8379e22806a Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 22 Feb 2019 16:13:10 +0300 Subject: [PATCH 10/29] remove verbose --- xcode/commonFastfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 318fb88..a16ce41 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -107,8 +107,7 @@ private_lane :syncCodeSigning do |options| git_branch: "fastlane_certificates", keychain_password: options[:keychain_password], skip_docs: true, - platform: "ios", - verbose: true + platform: "ios" ) end From 2061a8cb364a40071e583ddd7d8551a36e6c20f8 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 25 Feb 2019 13:39:39 +0300 Subject: [PATCH 11/29] merge updateCodeSigning and getCodeSigning to syncCodeSigning --- xcode/commonFastfile | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index a16ce41..32db2ec 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -96,6 +96,11 @@ private_lane :syncCodeSigning do |options| options_override = load_options_from("configurations.yaml")[type.to_sym] options = options.merge(options_override) + keychain_password = options[:keychain_password] || prompt( + text: "Please enter your keychain password (account password): ", + secure_text: true + ) + match( app_identifier: options[:app_identifier], username: options[:username] || options[:apple_id], @@ -105,28 +110,12 @@ private_lane :syncCodeSigning do |options| storage_mode: "git", git_url: options[:git_url], git_branch: "fastlane_certificates", - keychain_password: options[:keychain_password], + keychain_password: keychain_password, skip_docs: true, platform: "ios" ) end -private_lane :getCodeSigning do |options| - keychain_password = prompt( - text: "Please enter your keychain password (account password): ", - secure_text: true - ) - - options[:readonly] = true - options[:keychain_password] = keychain_password - syncCodeSigning(options) -end - -private_lane :updateCodeSigning do |options| - options[:readonly] = false - syncCodeSigning(options) -end - def load_options_from(file_path) if File.exists? file_path require "yaml" From b216095142dda59219b3ed5dc9b4b27e6b62c1b0 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 25 Feb 2019 16:52:38 +0300 Subject: [PATCH 12/29] =?UTF-8?q?revert=20code=20in=20afterBuild=20private?= =?UTF-8?q?=20lane.=20open=20or=20create=20keychain=20befor=D1=83=20syncCo?= =?UTF-8?q?deSign?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xcode/commonFastfile | 102 +++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 29 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 32db2ec..42c5396 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -25,27 +25,29 @@ private_lane :beforeBuild do |options| end private_lane :afterBuild do |options| - appName = options[:appName] || $appName - podsReposPath = File.expand_path "~/.cocoapods/repos/master/" - lockFilePath = "#{podsReposPath}/.git/index.lock" + if options[:uploadToFabric] + appName = options[:appName] || $appName - # check if .lock file exists in pod repos - then remove all master repo - if File.exists? lockFilePath - sh("rm -rf #{podsReposPath}") + token = sh("cat ../#{appName}.xcodeproj/project.pbxproj | grep 'Fabric/run' | awk '{print $4}' | tr -d '\\n'") + secret = sh("printf `cat ../#{appName}.xcodeproj/project.pbxproj | grep 'Fabric/run' | awk '{print $5}' | sed 's/..$//'` | tr -d '\\n'") + + releaseNotesFile = "release-notes.txt" + sh("touch ../#{releaseNotesFile}") + + crashlytics( + ipa_path: "./#{appName}.ipa", + crashlytics_path: "./Pods/Crashlytics/", + api_token: token, + build_secret: secret, + notes_path: releaseNotesFile, + groups: "touch-instinct" + ) + + upload_symbols_to_crashlytics( + dsym_path: "./#{appName}.app.dSYM.zip", + api_token: token + ) end - - carthage(platform: "iOS") - - cocoapods( - clean: true, - repo_update: true - ) - - set_info_plist_value( - path: "./#{appName}/Info.plist", - key: "CFBundleVersion", - value: options[:buildNumber] || 10000 - ) end private_lane :buildConfiguration do |options| @@ -59,6 +61,12 @@ private_lane :buildConfiguration do |options| exportOptions = icloudEnvironment.to_s.empty? ? {} : {iCloudContainerEnvironment: icloudEnvironment} exportOptions[:compileBitcode] = options[:compileBitcode] || false + options.merge(get_keychain_options(options)) + openKeychain(options) + + options[:type] = method + syncCodeSigning(options) + gym( clean: true, workspace: "./#{appName}.xcworkspace", @@ -72,10 +80,12 @@ private_lane :buildConfiguration do |options| skip_package_ipa: !uploadToFabric ) + closeKeychain(options) + afterBuild(options) end -lane :createPushCertificate do |options| +lane :СreatePushCertificate do |options| certificates_path = File.expand_path "../Certificates" Dir.mkdir(certificates_path) unless File.directory?(certificates_path) @@ -90,16 +100,11 @@ lane :createPushCertificate do |options| ) end -private_lane :syncCodeSigning do |options| +lane :syncCodeSigning do |options| type = options[:type] || "development" - options_override = load_options_from("configurations.yaml")[type.to_sym] - options = options.merge(options_override) - - keychain_password = options[:keychain_password] || prompt( - text: "Please enter your keychain password (account password): ", - secure_text: true - ) + options_override = load_options_from("configurations.yaml") + options = options.merge(options_override[type.to_sym]) match( app_identifier: options[:app_identifier], @@ -110,12 +115,51 @@ private_lane :syncCodeSigning do |options| storage_mode: "git", git_url: options[:git_url], git_branch: "fastlane_certificates", - keychain_password: keychain_password, + keychain_name: options[:keychain_name], + keychain_password: options[:keychain_password], skip_docs: true, platform: "ios" ) end +private_lane :openKeychain do |options| + if is_ci? + create_keychain( + name: options[:keychain_name], + password: options[:keychain_password], + unlock: true + ) + else + unlock_keychain( + name: options[:keychain_name], + password: options[:keychain_password] + ) + end +end + +private_lane :closeKeychain do |options| + if is_ci? + delete_keychain(name: options[:keychain_name]) + end +end + +def get_keychain_options(options) + keychain_name = options[:keychain_name] + keychain_password = options[:keychain_password] + + if is_ci? + keychain_name = keychain_name || "ci.keychain" + keychain_password = keychain_name || "" + else + keychain_password = keychain_password || prompt( + text: "Please enter your keychain password (account password): ", + secure_text: true + ) + end + + return {:keychain_name => keychain_name, :keychain_password => keychain_password} +end + def load_options_from(file_path) if File.exists? file_path require "yaml" From 9a9b420623080738cedb212766740c631b051862 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 25 Feb 2019 17:45:09 +0300 Subject: [PATCH 13/29] small fixes --- xcode/commonFastfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 42c5396..8b54e1d 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -10,11 +10,12 @@ private_lane :beforeBuild do |options| sh("rm -rf #{podsReposPath}") end - carthage(platform: "iOS") + if File.exists? "./Cartfile" + carthage(platform: "iOS") + end cocoapods( - clean: true, - repo_update: true + repo_update: false ) set_info_plist_value( @@ -61,7 +62,7 @@ private_lane :buildConfiguration do |options| exportOptions = icloudEnvironment.to_s.empty? ? {} : {iCloudContainerEnvironment: icloudEnvironment} exportOptions[:compileBitcode] = options[:compileBitcode] || false - options.merge(get_keychain_options(options)) + options = options.merge(get_keychain_options(options)) openKeychain(options) options[:type] = method @@ -131,7 +132,7 @@ private_lane :openKeychain do |options| ) else unlock_keychain( - name: options[:keychain_name], + path: options[:keychain_name], password: options[:keychain_password] ) end @@ -149,7 +150,7 @@ def get_keychain_options(options) if is_ci? keychain_name = keychain_name || "ci.keychain" - keychain_password = keychain_name || "" + keychain_password = keychain_password || "" else keychain_password = keychain_password || prompt( text: "Please enter your keychain password (account password): ", From 55cc0c1f0a61a1256ab69cedb2956a63548adc8d Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 25 Feb 2019 18:43:45 +0300 Subject: [PATCH 14/29] app store configuration prepare --- xcode/commonFastfile | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 8b54e1d..771d2c6 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -54,8 +54,8 @@ end private_lane :buildConfiguration do |options| beforeBuild(options) - configuration = lane_context[SharedValues::LANE_NAME] - method = configuration.start_with?("Enterprise") ? "enterprise" : "development" + configuration = options[:configuration] || lane_context[SharedValues::LANE_NAME] + method = configuration_type_from_lane_name(configuration) appName = options[:appName] || $appName uploadToFabric = options[:uploadToFabric] icloudEnvironment = options[:iCloudContainerEnvironment] || "" @@ -65,7 +65,7 @@ private_lane :buildConfiguration do |options| options = options.merge(get_keychain_options(options)) openKeychain(options) - options[:type] = method + options[:type] = profile_type_from_configuration_type(method) syncCodeSigning(options) gym( @@ -161,6 +161,21 @@ def get_keychain_options(options) return {:keychain_name => keychain_name, :keychain_password => keychain_password} end +def configuration_type_from_lane_name(lane_name) + case + when lane_name.start_with?("Enterprise") + "enterprise" + when lane_name.start_with?("AppStore") + "app-store" + else + "development" + end +end + +def profile_type_from_configuration_type(configuration_type) + configuration_type.gsub("-", "") # "app-store" => "appstore" +end + def load_options_from(file_path) if File.exists? file_path require "yaml" From 5c7bf4d04776bdecdc2ba554c57cd37394cb8ca1 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 6 Mar 2019 10:58:13 +0300 Subject: [PATCH 15/29] upload to appstore option WIP --- xcode/commonFastfile | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 771d2c6..876d171 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -49,13 +49,35 @@ private_lane :afterBuild do |options| api_token: token ) end + + if options[:uploadToAppStore] + app_version = get_info_plist_value( + path: "./#{appName}/Info.plist", + key: "CFBundleShortVersionString" + ) + + upload_to_app_store( + username: options[:username] || options[:apple_id], + app_identifier: options[:app_identifier], + app_version: options[:app_version] || app_version, + ipa: "#{appName}.ipa", + build_number: options[:buildNumber], + skip_metadata: true, + team_id: options[:itc_team_id], + dev_portal_team_id: options[:team_id] + ) + end end private_lane :buildConfiguration do |options| - beforeBuild(options) - configuration = options[:configuration] || lane_context[SharedValues::LANE_NAME] method = configuration_type_from_lane_name(configuration) + options[:type] = profile_type_from_configuration_type(method) + + options = merge_options_with_config_file(options) + + beforeBuild(options) + appName = options[:appName] || $appName uploadToFabric = options[:uploadToFabric] icloudEnvironment = options[:iCloudContainerEnvironment] || "" @@ -102,11 +124,6 @@ lane :СreatePushCertificate do |options| end lane :syncCodeSigning do |options| - type = options[:type] || "development" - - options_override = load_options_from("configurations.yaml") - options = options.merge(options_override[type.to_sym]) - match( app_identifier: options[:app_identifier], username: options[:username] || options[:apple_id], @@ -176,6 +193,13 @@ def profile_type_from_configuration_type(configuration_type) configuration_type.gsub("-", "") # "app-store" => "appstore" end +def merge_options_with_config_file(options) + type = options[:type] || "development" + + options_override = load_options_from("configurations.yaml") + return options.merge(options_override[type.to_sym]) +end + def load_options_from(file_path) if File.exists? file_path require "yaml" From 5038956f51bdba405d0f48550af760964e9a4f82 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 7 Mar 2019 20:48:25 +0300 Subject: [PATCH 16/29] upload to app store finished --- xcode/commonFastfile | 158 ++++++++++++++++++++++++------------------- 1 file changed, 90 insertions(+), 68 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 876d171..52b82eb 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -1,7 +1,6 @@ $appName = File.basename(Dir['../*.xcworkspace'].first, '.*') -private_lane :beforeBuild do |options| - appName = options[:appName] || $appName +private_lane :installDependencies do |options| podsReposPath = File.expand_path "~/.cocoapods/repos/master/" lockFilePath = "#{podsReposPath}/.git/index.lock" @@ -17,95 +16,110 @@ private_lane :beforeBuild do |options| cocoapods( repo_update: false ) +end - set_info_plist_value( - path: "./#{appName}/Info.plist", - key: "CFBundleVersion", - value: options[:buildNumber] || 10000 +private_lane :uploadToFabric do |options| + token, secret = fabric_keys_from_xcodeproj(options[:xcodeproj_path]) + + releaseNotesFile = "release-notes.txt" + sh("touch ../#{releaseNotesFile}") + + crashlytics( + ipa_path: options[:ipa_path], + crashlytics_path: "./Pods/Crashlytics/", + api_token: token, + build_secret: secret, + notes_path: releaseNotesFile, + groups: "touch-instinct" + ) + + upload_symbols_to_crashlytics( + dsym_path: options[:dsym_path], + api_token: token ) end -private_lane :afterBuild do |options| - if options[:uploadToFabric] - appName = options[:appName] || $appName - - token = sh("cat ../#{appName}.xcodeproj/project.pbxproj | grep 'Fabric/run' | awk '{print $4}' | tr -d '\\n'") - secret = sh("printf `cat ../#{appName}.xcodeproj/project.pbxproj | grep 'Fabric/run' | awk '{print $5}' | sed 's/..$//'` | tr -d '\\n'") - - releaseNotesFile = "release-notes.txt" - sh("touch ../#{releaseNotesFile}") - - crashlytics( - ipa_path: "./#{appName}.ipa", - crashlytics_path: "./Pods/Crashlytics/", - api_token: token, - build_secret: secret, - notes_path: releaseNotesFile, - groups: "touch-instinct" - ) - - upload_symbols_to_crashlytics( - dsym_path: "./#{appName}.app.dSYM.zip", - api_token: token - ) - end - - if options[:uploadToAppStore] - app_version = get_info_plist_value( - path: "./#{appName}/Info.plist", - key: "CFBundleShortVersionString" - ) - - upload_to_app_store( - username: options[:username] || options[:apple_id], - app_identifier: options[:app_identifier], - app_version: options[:app_version] || app_version, - ipa: "#{appName}.ipa", - build_number: options[:buildNumber], - skip_metadata: true, - team_id: options[:itc_team_id], - dev_portal_team_id: options[:team_id] - ) - end +private_lane :uploadToAppStore do |options| + upload_to_app_store( + username: options[:username] || options[:apple_id], + ipa: options[:ipa_path], + force: true, # skip metainfo prompt + skip_metadata: true, + team_id: options[:itc_team_id], + dev_portal_team_id: options[:team_id] + ) end private_lane :buildConfiguration do |options| + appName = options[:appName] || $appName configuration = options[:configuration] || lane_context[SharedValues::LANE_NAME] method = configuration_type_from_lane_name(configuration) + + options[:scheme] = appName + options[:configuration] = configuration + options[:method] = method options[:type] = profile_type_from_configuration_type(method) options = merge_options_with_config_file(options) - beforeBuild(options) + installDependencies(options) - appName = options[:appName] || $appName - uploadToFabric = options[:uploadToFabric] - icloudEnvironment = options[:iCloudContainerEnvironment] || "" - exportOptions = icloudEnvironment.to_s.empty? ? {} : {iCloudContainerEnvironment: icloudEnvironment} - exportOptions[:compileBitcode] = options[:compileBitcode] || false - - options = options.merge(get_keychain_options(options)) openKeychain(options) - options[:type] = profile_type_from_configuration_type(method) syncCodeSigning(options) + if is_ci + increment_build_number( + build_number: options[:buildNumber] + ) + end + + ipa_name = "#{appName}.ipa" + options[:output_name] = ipa_name + + options[:ipa_path] = "./#{ipa_name}" + options[:dsym_path] = "./#{appName}.app.dSYM.zip" + + options[:xcodeproj_path] = "../#{appName}.xcodeproj" + options[:workspace] = "./#{appName}.xcworkspace" + + if !(options[:uploadToFabric] || options[:uploadToAppStore]) + options[:skip_package_ipa] = true + buildArchive(options) # check build failures and static analysis + end + + if options[:uploadToFabric] + buildArchive(options) + uploadToFabric(options) + end + + if options[:uploadToAppStore] + options[:compileBitcode] = true + + buildArchive(options) + uploadToAppStore(options) + end + + closeKeychain(options) +end + +private_lane :buildArchive do |options| + exportOptions = {compileBitcode: options[:compileBitcode] || false} + gym( clean: true, - workspace: "./#{appName}.xcworkspace", - scheme: appName, + workspace: options[:workspace], + scheme: options[:scheme], archive_path: "./", output_directory: "./", - output_name: "#{appName}.ipa", - configuration: configuration, - export_method: method, + output_name: options[:output_name], + configuration: options[:configuration], + export_method: options[:method], export_options: exportOptions, - skip_package_ipa: !uploadToFabric + skip_package_ipa: options[:skip_package_ipa], + include_symbols: options[:compileBitcode] || false, + include_bitcode: options[:compileBitcode] || false, ) - - closeKeychain(options) - - afterBuild(options) end lane :СreatePushCertificate do |options| @@ -128,7 +142,7 @@ lane :syncCodeSigning do |options| app_identifier: options[:app_identifier], username: options[:username] || options[:apple_id], team_id: options[:team_id], - type: type, + type: options[:type], readonly: options[:readonly] || true, storage_mode: "git", git_url: options[:git_url], @@ -227,3 +241,11 @@ def symbolize_keys(hash) result } end + +def fabric_keys_from_xcodeproj(xcodeproj_path) + fabric_keys_from_shell_script(sh("cat ../#{xcodeproj_path}/project.pbxproj | grep 'Fabric/run'")) +end + +def fabric_keys_from_shell_script(shell_script_contents) + shell_script_contents.partition('Fabric/run\" ').last.partition('";').first.split(" ") +end From 5e9b785962df2ca4d72d8a2cc0e4f7ffc8a55d5e Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 7 Mar 2019 21:10:02 +0300 Subject: [PATCH 17/29] fixes --- xcode/commonFastfile | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 52b82eb..b75e150 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -52,22 +52,17 @@ end private_lane :buildConfiguration do |options| appName = options[:appName] || $appName - configuration = options[:configuration] || lane_context[SharedValues::LANE_NAME] - method = configuration_type_from_lane_name(configuration) options[:scheme] = appName - options[:configuration] = configuration - options[:method] = method - options[:type] = profile_type_from_configuration_type(method) + configuration = options[:configuration] || lane_context[SharedValues::LANE_NAME] + options = options.merge(make_options_for_lane_name(configuration)) options = merge_options_with_config_file(options) - installDependencies(options) + options = options.merge(get_keychain_options(options)) openKeychain(options) - syncCodeSigning(options) - if is_ci increment_build_number( build_number: options[:buildNumber] @@ -83,18 +78,29 @@ private_lane :buildConfiguration do |options| options[:xcodeproj_path] = "../#{appName}.xcodeproj" options[:workspace] = "./#{appName}.xcworkspace" + installDependencies(options) + if !(options[:uploadToFabric] || options[:uploadToAppStore]) options[:skip_package_ipa] = true + + syncCodeSigning(options) + buildArchive(options) # check build failures and static analysis end if options[:uploadToFabric] buildArchive(options) + + syncCodeSigning(options) + uploadToFabric(options) end if options[:uploadToAppStore] options[:compileBitcode] = true + options = options.merge(make_options_for_lane_name("AppStore")) + + syncCodeSigning(options) buildArchive(options) uploadToAppStore(options) @@ -207,6 +213,15 @@ def profile_type_from_configuration_type(configuration_type) configuration_type.gsub("-", "") # "app-store" => "appstore" end +def make_options_for_lane_name(lane_name) + method = configuration_type_from_lane_name(lane_name) + return { + :configuration => lane_name, + :method => method, + :type => profile_type_from_configuration_type(method) + } +end + def merge_options_with_config_file(options) type = options[:type] || "development" From 5efaf159905a63adc7ab45e7a726f6269701bf3e Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 11 Mar 2019 18:42:02 +0300 Subject: [PATCH 18/29] fix paths --- xcode/commonFastfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index b75e150..d792814 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -9,7 +9,7 @@ private_lane :installDependencies do |options| sh("rm -rf #{podsReposPath}") end - if File.exists? "./Cartfile" + if File.exists? "../Cartfile" carthage(platform: "iOS") end @@ -258,7 +258,7 @@ def symbolize_keys(hash) end def fabric_keys_from_xcodeproj(xcodeproj_path) - fabric_keys_from_shell_script(sh("cat ../#{xcodeproj_path}/project.pbxproj | grep 'Fabric/run'")) + fabric_keys_from_shell_script(sh("cat #{xcodeproj_path}/project.pbxproj | grep 'Fabric/run'")) end def fabric_keys_from_shell_script(shell_script_contents) From dd5d6f3e69b9e67e9c09273f1a5454954757dc38 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 22 Mar 2019 16:20:31 +0300 Subject: [PATCH 19/29] don't remove keychain after build --- xcode/commonFastfile | 8 -------- 1 file changed, 8 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index d792814..1e9b08e 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -105,8 +105,6 @@ private_lane :buildConfiguration do |options| buildArchive(options) uploadToAppStore(options) end - - closeKeychain(options) end private_lane :buildArchive do |options| @@ -175,12 +173,6 @@ private_lane :openKeychain do |options| end end -private_lane :closeKeychain do |options| - if is_ci? - delete_keychain(name: options[:keychain_name]) - end -end - def get_keychain_options(options) keychain_name = options[:keychain_name] keychain_password = options[:keychain_password] From 660067ed69bb802408def6716dd8ddf1836a559f Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 22 Mar 2019 16:32:19 +0300 Subject: [PATCH 20/29] revert iCloudContainerEnvironment --- xcode/commonFastfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 1e9b08e..7d3ef60 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -108,7 +108,9 @@ private_lane :buildConfiguration do |options| end private_lane :buildArchive do |options| - exportOptions = {compileBitcode: options[:compileBitcode] || false} + icloudEnvironment = options[:iCloudContainerEnvironment] || "" + exportOptions = icloudEnvironment.to_s.empty? ? {} : {iCloudContainerEnvironment: icloudEnvironment} + exportOptions[:compileBitcode] = options[:compileBitcode] || false gym( clean: true, From 66ca5e2d4e5f176839450fc61f54e4f2cbdb8ff4 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 28 Mar 2019 22:28:04 +0300 Subject: [PATCH 21/29] wipe swift 4.x builded binaries --- xcode/commonFastfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 7d3ef60..78603cd 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -11,6 +11,8 @@ private_lane :installDependencies do |options| if File.exists? "../Cartfile" carthage(platform: "iOS") + # wipe swift 4.x builded binaries + sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") end cocoapods( From dd532f0aacd63d8b582ae687e57246017c7d7b79 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 28 Mar 2019 22:32:52 +0300 Subject: [PATCH 22/29] wipe and then run --- xcode/commonFastfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 78603cd..60cf6dd 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -10,9 +10,10 @@ private_lane :installDependencies do |options| end if File.exists? "../Cartfile" - carthage(platform: "iOS") - # wipe swift 4.x builded binaries + # wipe swift 4.x builded binaries sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") + + carthage(platform: "iOS") end cocoapods( From fb406b7940ad5c4043bbaeec542640141c2543bb Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 29 Mar 2019 11:03:57 +0300 Subject: [PATCH 23/29] attempt to fix temporary cache issues --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 60cf6dd..1ed252d 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -13,7 +13,7 @@ private_lane :installDependencies do |options| # wipe swift 4.x builded binaries sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") - carthage(platform: "iOS") + carthage(command: "update", platform: "iOS") end cocoapods( From 1f2ed6f92b5719befaecc21e8b9dfc88af0166b6 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 4 Apr 2019 17:02:26 +0300 Subject: [PATCH 24/29] fix profile type selection when checked uploadToAppStore --- xcode/commonFastfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 1ed252d..2908c76 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -84,6 +84,7 @@ private_lane :buildConfiguration do |options| installDependencies(options) if !(options[:uploadToFabric] || options[:uploadToAppStore]) + options = merge_options_with_config_file(options) options[:skip_package_ipa] = true syncCodeSigning(options) @@ -92,8 +93,9 @@ private_lane :buildConfiguration do |options| end if options[:uploadToFabric] - buildArchive(options) + options = merge_options_with_config_file(options) + buildArchive(options) syncCodeSigning(options) uploadToFabric(options) @@ -102,6 +104,7 @@ private_lane :buildConfiguration do |options| if options[:uploadToAppStore] options[:compileBitcode] = true options = options.merge(make_options_for_lane_name("AppStore")) + options = merge_options_with_config_file(options) syncCodeSigning(options) From 641afa42f3634600d46bed3b955757383d67d333 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 5 Apr 2019 00:24:09 +0300 Subject: [PATCH 25/29] add ability to pass compileBitcode option --- xcode/commonFastfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 2908c76..a4c69a9 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -102,7 +102,8 @@ private_lane :buildConfiguration do |options| end if options[:uploadToAppStore] - options[:compileBitcode] = true + options[:compileBitcode] = options[:compileBitcode] || true + options[:include_symbols] = options[:include_symbols] || true options = options.merge(make_options_for_lane_name("AppStore")) options = merge_options_with_config_file(options) @@ -129,7 +130,7 @@ private_lane :buildArchive do |options| export_method: options[:method], export_options: exportOptions, skip_package_ipa: options[:skip_package_ipa], - include_symbols: options[:compileBitcode] || false, + include_symbols: options[:include_symbols] || false, include_bitcode: options[:compileBitcode] || false, ) end From 70432c18f6fe5de963b0bfc4ccc9e39e87d3c398 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 5 Apr 2019 00:27:21 +0300 Subject: [PATCH 26/29] don't wipe binaries anymore --- xcode/commonFastfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index a4c69a9..c713347 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -10,10 +10,7 @@ private_lane :installDependencies do |options| end if File.exists? "../Cartfile" - # wipe swift 4.x builded binaries - sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") - - carthage(command: "update", platform: "iOS") + carthage(platform: "iOS") end cocoapods( From a8f3a1c7543c407179772858a64cd655b7fc1f82 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 5 Apr 2019 00:37:22 +0300 Subject: [PATCH 27/29] fix ruby bool coalesce --- xcode/commonFastfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index c713347..e69671c 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -99,8 +99,8 @@ private_lane :buildConfiguration do |options| end if options[:uploadToAppStore] - options[:compileBitcode] = options[:compileBitcode] || true - options[:include_symbols] = options[:include_symbols] || true + options[:compileBitcode] = options[:compileBitcode].nil? true : options[:compileBitcode] + options[:include_symbols] = options[:include_symbols].nil? true : options[:include_symbols] options = options.merge(make_options_for_lane_name("AppStore")) options = merge_options_with_config_file(options) From 412b1dafeb17004fdfa7b0cd039cc021135f3e3d Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 5 Apr 2019 00:38:44 +0300 Subject: [PATCH 28/29] fix ruby bool coalesce #2 --- xcode/commonFastfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index e69671c..ff0aae4 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -99,8 +99,8 @@ private_lane :buildConfiguration do |options| end if options[:uploadToAppStore] - options[:compileBitcode] = options[:compileBitcode].nil? true : options[:compileBitcode] - options[:include_symbols] = options[:include_symbols].nil? true : options[:include_symbols] + options[:compileBitcode] = options[:compileBitcode].nil? ? true : options[:compileBitcode] + options[:include_symbols] = options[:include_symbols].nil? ? true : options[:include_symbols] options = options.merge(make_options_for_lane_name("AppStore")) options = merge_options_with_config_file(options) From 4fa303f2c093fb117ece55a0bd81aa4bb15992cb Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 22 Apr 2019 12:15:08 +0300 Subject: [PATCH 29/29] update crashlytics_path --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index ff0aae4..32612c6 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -26,7 +26,7 @@ private_lane :uploadToFabric do |options| crashlytics( ipa_path: options[:ipa_path], - crashlytics_path: "./Pods/Crashlytics/", + crashlytics_path: "./Pods/Crashlytics/submit", api_token: token, build_secret: secret, notes_path: releaseNotesFile,