diff --git a/.rubocop.yml b/.rubocop.yml index 28525e4..08dc344 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,7 @@ require: - rubocop/require_tools - rubocop-performance AllCops: + SuggestExtensions: false TargetRubyVersion: 2.5 NewCops: enable Include: @@ -55,6 +56,7 @@ Lint/UselessAssignment: - "**/spec/**/*" Require/MissingRequireStatement: Exclude: + - "lib/fastlane/plugin/eln/actions/*.rb" # Не понятно, почему ругается. Разобраться - "**/spec/**/*.rb" - "**/spec_helper.rb" - spaceship/lib/spaceship/babosa_fix.rb diff --git a/README.md b/README.md index 4f1fa53..6d955f1 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,19 @@ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To ```bash fastlane add_plugin eln ``` +Choose Git URL and enter the URL of this repository. -## About eln +## About ELN -E-Legion +ELN is a set of lanes which can automate some routines in CI actions. -**Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here. +### Available actions +|Action|Description| +|------|-----------| +|eln_certs_get|Gets all private certificates and provision described in ELN_CERTS_PROVISION_PROFILE_NAME_LIST environment variable| +|eln_certs_update|Adds new developer devices to developer.apple from file described in FL_REGISTER_DEVICES_FILE and force update provisions from ELN_CERTS_PROVISION_PROFILE_NAME_LIST| +**Important note:** Make sure you already added MATCH environment variables. ## Example Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`. diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 269470e..c18231a 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -1,3 +1,13 @@ lane :test do - eln + eln_certs_get + eln_certs_update +end + +lane :test_params do + eln_certs_get( + eln_certs_provision_profile_name_list: "Some App Name:com.team.some-app,Some Extension Name:com.team.some-extension" + ) + eln_certs_update( + eln_certs_provision_profile_name_list: "Some App Name:com.team.some-app,Some Extension Name:com.team.some-extension" + ) end diff --git a/lib/fastlane/plugin/eln/actions/eln_certs.rb b/lib/fastlane/plugin/eln/actions/eln_certs.rb deleted file mode 100644 index 5b74cd2..0000000 --- a/lib/fastlane/plugin/eln/actions/eln_certs.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'fastlane/action' -require_relative '../helper/eln_helper' - -module Fastlane - module Actions - - class ElnCertsAction < Action - - def self.authors - ["viktor.volkov@e-legion.com"] - end - - def self.available_options - [ - FastlaneCore::ConfigItem.new(key: :eln_certs_provision_profile_name_list, - env_name: "ELN_CERTS_PROVISION_PROFILE_NAME_LIST", - description: "Provisions and identifiers to create. Provision and identifiers should be separated by colon, pairs should be separated by comma, e.g \"profile name_1:identifier_1,profile name_2:identifier_2\"", - optional: false, - type: String), - ] - end - end - end -end diff --git a/lib/fastlane/plugin/eln/actions/eln_certs_get.rb b/lib/fastlane/plugin/eln/actions/eln_certs_get.rb index a16b5ec..e377d2e 100644 --- a/lib/fastlane/plugin/eln/actions/eln_certs_get.rb +++ b/lib/fastlane/plugin/eln/actions/eln_certs_get.rb @@ -1,17 +1,13 @@ require 'fastlane/action' require_relative '../helper/eln_helper' -require_relative 'eln_certs' module Fastlane module Actions - - class ElnCertsGetAction < ElnCertsAction + class ElnCertsGetAction < Action def self.run(params) - - provisions_pairs = Helper::CertsHelper.validate_provisions(params) - provisions_pairs.each { - |key, value| - + list = params[:eln_certs_provision_profile_name_list] + provisions_pairs = Helper::CertsHelper.validate_provisions(list) + provisions_pairs.each do |key, value| other_action.match( profile_name: key, app_identifier: value, @@ -19,11 +15,15 @@ def self.run(params) force_for_new_devices: false, force: false ) - } + end + end + + def self.authors + ["viktor.volkov@e-legion.com"] end def self.description - "E-Legion" + "Gets private certificate and provision profile" end def self.return_value @@ -31,15 +31,22 @@ def self.return_value end def self.details - # Optional: - "Plugin for good start" + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :eln_certs_provision_profile_name_list, + env_name: "ELN_CERTS_PROVISION_PROFILE_NAME_LIST", + description: "Provisions and identifiers to create. Provision and identifiers should be separated by colon, pairs should be separated by comma, e.g \"profile name_1:identifier_1,profile name_2:identifier_2\"", + optional: false, + type: String, + verify_block: proc do |value| + UI.user_error("Certificates and provisions are empty!") unless value && !value.empty? + end) + ] end def self.is_supported?(platform) - # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) - # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform - # - # [:ios, :mac, :android].include?(platform) true end end diff --git a/lib/fastlane/plugin/eln/actions/eln_certs_update.rb b/lib/fastlane/plugin/eln/actions/eln_certs_update.rb index 9a9a3bb..1fbe8b1 100644 --- a/lib/fastlane/plugin/eln/actions/eln_certs_update.rb +++ b/lib/fastlane/plugin/eln/actions/eln_certs_update.rb @@ -1,17 +1,14 @@ require 'fastlane/action' require_relative '../helper/eln_helper' -require_relative 'eln_certs' module Fastlane module Actions - - class ElnCertsUpdateAction < ElnCertsAction + class ElnCertsUpdateAction < Action def self.run(params) - provisions_pairs = Helper::CertsHelper.validate_provisions(params) + list = params[:eln_certs_provision_profile_name_list] + provisions_pairs = Helper::CertsHelper.validate_provisions(list) other_action.register_devices - provisions_pairs.each { - |key, value| - + provisions_pairs.each do |key, value| other_action.match( profile_name: key, app_identifier: value, @@ -19,11 +16,15 @@ def self.run(params) force_for_new_devices: false, force: false ) - } + end + end + + def self.authors + ["viktor.volkov@e-legion.com"] end def self.description - "E-Legion" + "Adds new devices and force updates provision profiles" end def self.return_value @@ -31,15 +32,22 @@ def self.return_value end def self.details - # Optional: - "Plugin for good start" + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :eln_certs_provision_profile_name_list, + env_name: "ELN_CERTS_PROVISION_PROFILE_NAME_LIST", + description: "Provisions and identifiers to create. Provision and identifiers should be separated by colon, pairs should be separated by comma, e.g \"profile name_1:identifier_1,profile name_2:identifier_2\"", + optional: false, + type: String, + verify_block: proc do |value| + UI.user_error("Certificates and provisions are empty!") unless value && !value.empty? + end) + ] end def self.is_supported?(platform) - # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) - # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform - # - # [:ios, :mac, :android].include?(platform) true end end diff --git a/lib/fastlane/plugin/eln/helper/eln_helper.rb b/lib/fastlane/plugin/eln/helper/eln_helper.rb index 993dff7..063189f 100644 --- a/lib/fastlane/plugin/eln/helper/eln_helper.rb +++ b/lib/fastlane/plugin/eln/helper/eln_helper.rb @@ -5,10 +5,9 @@ module Fastlane module Helper class CertsHelper - - def self.validate_provisions(params) - provisions_pairs = params[:eln_certs_provision_profile_name_list].split(",") - possible_wrong_pair = provisions_pairs.select { |pair| !!pair[/.+[:].+/] == false } + def self.validate_provisions(list) + provisions_pairs = list.split(",") + possible_wrong_pair = provisions_pairs.select { |pair| !!pair[/.+:.+/] == false } unless possible_wrong_pair.length == 0 error = [ "Invalid format for next pairs:" @@ -17,9 +16,8 @@ def self.validate_provisions(params) "Example: Some Project Development:com.e-legion.some-project" ] UI.error(error.join("\n")) - exit end - return provisions_pairs.map { |pair| pair.split(":") } + return provisions_pairs.map { |pair| pair.split(":").map(&:strip) } end end end diff --git a/spec/eln_action_spec.rb b/spec/eln_action_spec.rb deleted file mode 100644 index 2fc344e..0000000 --- a/spec/eln_action_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -describe Fastlane::Actions::ElnAction do - describe '#run' do - it 'prints a message' do - expect(Fastlane::UI).to receive(:message).with("The eln plugin is working!") - - Fastlane::Actions::ElnAction.run(nil) - end - end -end diff --git a/spec/eln_helper_spec.rb b/spec/eln_helper_spec.rb new file mode 100644 index 0000000..254f3fe --- /dev/null +++ b/spec/eln_helper_spec.rb @@ -0,0 +1,14 @@ +describe Fastlane::Helper::CertsHelper do + describe '#run' do + it "valid" do + expect(Fastlane::Helper::CertsHelper.validate_provisions("some:value")).to eql([["some", "value"]]) + expect(Fastlane::Helper::CertsHelper.validate_provisions("some:value, some:value2")).to eql([["some", "value"], ["some", "value2"]]) + expect(Fastlane::Helper::CertsHelper.validate_provisions("some:value, some: value2")).to eql([["some", "value"], ["some", "value2"]]) + expect(Fastlane::Helper::CertsHelper.validate_provisions("some spaced value :value, some: value2")).to eql([["some spaced value", "value"], ["some", "value2"]]) + end + it "fails" do + expect(Fastlane::UI).to receive(:error) + Fastlane::Helper::CertsHelper.validate_provisions("some:value,some") + end + end +end