Class: Fastlane::Actions::UpdateTestplanAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/stream_actions/actions/update_testplan.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.available_optionsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fastlane/plugin/stream_actions/actions/update_testplan.rb', line 28

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :path,
      description: 'The test plan file path',
      verify_block: proc do |path|
        UI.user_error!("Cannot find the testplan file '#{path}'") unless File.exist?(path)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :env_vars,
      description: 'The environment variables to add to test plan',
      is_string: false,
      verify_block: proc do |env_vars|
        UI.user_error!("The environment variables array should not be empty") if env_vars.nil? || env_vars.empty?
      end
    )
  ]
end

.descriptionObject



24
25
26
# File 'lib/fastlane/plugin/stream_actions/actions/update_testplan.rb', line 24

def self.description
  'Adds environment variables to a test plan'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/fastlane/plugin/stream_actions/actions/update_testplan.rb', line 48

def self.is_supported?(platform)
  [:ios].include?(platform)
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fastlane/plugin/stream_actions/actions/update_testplan.rb', line 4

def self.run(params)
  data_hash = JSON.parse(File.read(params[:path]))

  data_hash['defaultOptions']['environmentVariableEntries'] ||= []

  if params[:env_vars].kind_of?(Hash)
    data_hash['defaultOptions']['environmentVariableEntries'] << params[:env_vars]
  else
    params[:env_vars].each { |env| data_hash['defaultOptions']['environmentVariableEntries'] << env }
  end

  File.write(params[:path], JSON.pretty_generate(data_hash))

  UI.message("👀 Testplan environment variables:\n#{data_hash['defaultOptions']['environmentVariableEntries']}")
end