From e003011b9abadbf4b94efa0a1043c061f2a7622a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Mon, 15 May 2023 17:00:23 +0200 Subject: [PATCH] feat: Improved pipeline efficiency and adapted to new credentials template --- .../ios_cd/actions/build_and_deploy_action.rb | 49 ++++++++----- .../plugin/ios_cd/actions/promote_action.rb | 71 +++++++++++++++++++ .../plugin/ios_cd/helper/ios_cd_helper.rb | 28 +------- 3 files changed, 102 insertions(+), 46 deletions(-) create mode 100644 plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/actions/promote_action.rb 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 40e069f..5e62d3a 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 @@ -21,8 +21,20 @@ module Fastlane creds = Helper::IosCdHelper.parseIosCredentials('.') UI.message("πŸ‘‰πŸΌ Credentials parsed.") - # Ensure temporary keychain exists - Helper::IosCdHelper.ensure_temp_keychain(creds['temp_keychain_user'], creds['temp_keychain_password']) + # Delete keychain if existing + if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db")) + other_action.delete_keychain( + name: creds['temp_keychain_user'].to_s + ) + end + + # Create keychain to store certifs + other_action.create_keychain( + name: creds['temp_keychain_user'].to_s, + password: creds['temp_keychain_password'].to_s, + unlock: false, + timeout: 0 + ) UI.message("πŸ‘‰πŸΌ New keychain created") # Obtain App Store Connect API key @@ -33,17 +45,16 @@ module Fastlane duration: 1200, in_house: false ) - UI.message("πŸ‘‰πŸΌ API Key formated") last_testflight_build_number = other_action.latest_testflight_build_number( api_key: api_key, - team_id: "118579280", - team_name: "Jagger & Lewis", + team_id: creds['team_id'].to_s, + team_name: creds['team_name'].to_s, platform: 'ios', app_identifier: creds['developer_app_identifier'].to_s, - username: "leonmalo@sfr.fr" + username: creds['username'].to_s ) + 1 # Increment build number for latest TestFlight build @@ -72,13 +83,13 @@ module Fastlane type: 'appstore', app_identifier: creds['app_identifier_extensions'], git_basic_authorization: Base64.strict_encode64(ENV["GIT_AUTHORIZATION"]), - keychain_name: creds['temp_keychain_user'], - keychain_password: creds['temp_keychain_password'], - git_url: creds['git_url'], - username: "leonmalo@sfr.fr", - team_id: "118579280", - team_name: "Jagger & Lewis", - git_url: "https://github.com/JaggerLewis/jl2022_cert.git", + keychain_name: creds['temp_keychain_user'].to_s, + keychain_password: creds['temp_keychain_password'].to_s, + git_url: creds['git_url'].to_s, + username: creds['username'].to_s, + team_id: creds['team_id'].to_s, + team_name: creds['team_name'].to_s, + git_url: creds['git_url'].to_s, storage_mode: "git" ) UI.message("πŸ‘‰πŸΌ App signed") @@ -88,7 +99,6 @@ module Fastlane other_action.gym( configuration: "Release", workspace: "Runner.xcworkspace", - scheme: "your_schema", export_method: "app-store", export_options: { provisioningProfiles: creds['provisioning_profiles'] @@ -99,9 +109,6 @@ module Fastlane # Upload build to App Store Connect using Pilot other_action.pilot( api_key: api_key, - username: "leonmalo@sfr.fr", - team_id: "118579280", - team_name: "Jagger & Lewis", apple_id: creds['developer_app_id'].to_s, app_identifier: creds['developer_app_identifier'].to_s, skip_waiting_for_build_processing: true, @@ -110,9 +117,13 @@ module Fastlane notify_external_testers: false, ipa: "./Runner.ipa" ) - UI.message("πŸ‘‰πŸΌ App uploaded") - other_action.deleteTemp_keychain + # Delete keychain if existing + if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db")) + other_action.delete_keychain( + name: creds['temp_keychain_user'] + ) + end end def self.description diff --git a/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/actions/promote_action.rb b/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/actions/promote_action.rb new file mode 100644 index 0000000..de15c0b --- /dev/null +++ b/plugins/fastlane-plugin-ios_cd/lib/fastlane/plugin/ios_cd/actions/promote_action.rb @@ -0,0 +1,71 @@ +require 'fastlane/action' +require_relative '../helper/ios_cd_helper' + +module Fastlane + module Actions + class PromoteAction < Action + def self.run(params) + + UI.message("βŒ›οΈ Promoting to Store in external test..") + + # Decrypt the keys archive and Extract the keys archive + Helper::IosCdHelper.decrypt_ios_keys('.') + UI.message("πŸ‘‰πŸΌ Credentials decrypted.") + + # Retrieve credentials + creds = Helper::IosCdHelper.parseIosCredentials('.') + UI.message("πŸ‘‰πŸΌ Credentials parsed.") + + # Obtain App Store Connect API key + api_key = other_action.app_store_connect_api_key( + key_id: creds['apple_key_id'].to_s, + issuer_id: creds['apple_issuer_id'].to_s, + key_content: creds['apple_key_content'].to_s, + duration: 1200, + in_house: false + ) + UI.message("πŸ‘‰πŸΌ API Key formated") + + # Upload build to App Store Connect using Pilot + other_action.pilot( + api_key: api_key, + apple_id: creds['developer_app_id'].to_s, + app_identifier: creds['developer_app_identifier'].to_s, + skip_waiting_for_build_processing: false, + distribute_only: true, + skip_submission: true, + distribute_external: true, + notify_external_testers: true, + groups: [ + "BΓͺta externe", + ], + app_platform:'ios', + ) + + end + + def self.description + "Testflight and AppStore deployment plugin for Fastlane, simplifying the build and deployment porcess to internal, external, and production channels, and promoting builds for testing." + end + + def self.authors + ["SAS Wyatt Studio"] + end + + def self.return_value + end + + def self.details + "The Fastlane Testflight / Appstore deloyment action streamlines the build and deployment to internal, external and production channels. Allow you to promote builds on testflight beta tests." + end + + def self.available_options + [] + end + + def self.is_supported?(platform) + [:ios].include?(platform) + end + end + end +end 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 308892f..db2d2b9 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 @@ -5,31 +5,6 @@ require 'fastlane_core/ui/ui' module Fastlane module Helper class IosCdHelper - # Define method to delete temporary keychain - def self.delete_temp_keychain(name) - if File.exist?(File.expand_path("~/Library/Keychains/#{name}-db")) - Actions::DeleteKeychainAction.run( - name: name - ) - end - end - - # Define method to create temporary keychain - def self.create_temp_keychain(name, password) - Actions::CreateKeychainAction.run( - name: name, - password: password, - unlock: false, - timeout: 0 - ) - end - - # Define method to ensure that temporary keychain exists - def self.ensure_temp_keychain(name, password) - delete_temp_keychain(name) - create_temp_keychain(name, password) - end - # Check if a parameter is set or not def self.is_set(variable) str_variable = variable @@ -40,8 +15,7 @@ module Fastlane # Decrypts ios credentials def self.decrypt_ios_keys(ios_directory) # Define the GPG command with options - # gpg_command = "gpg --quiet --batch --yes --decrypt --passphrase=#{ENV['IOS_KEYS_SECRET_PASSPHRASE']} \ - gpg_command = "gpg --quiet --batch --yes --decrypt --passphrase=toto1234 \ + 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" # Execute the GPG command using system