Class: Fastlane::Actions::EnsureEnvVarsAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/ensure_env_vars.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



33
34
35
# File 'fastlane/lib/fastlane/actions/ensure_env_vars.rb', line 33

def self.authors
  ['revolter']
end

.available_optionsObject



22
23
24
25
26
27
28
29
30
31
# File 'fastlane/lib/fastlane/actions/ensure_env_vars.rb', line 22

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :env_vars,
                                 description: 'The environment variables names that should be checked',
                                 type: Array,
                                 verify_block: proc do |value|
                                   UI.user_error!('Specify at least one environment variable name') if value.empty?
                                 end)
  ]
end

.categoryObject



45
46
47
# File 'fastlane/lib/fastlane/actions/ensure_env_vars.rb', line 45

def self.category
  :misc
end

.descriptionObject



14
15
16
# File 'fastlane/lib/fastlane/actions/ensure_env_vars.rb', line 14

def self.description
  'Raises an exception if the specified env vars are not set'
end

.detailsObject



18
19
20
# File 'fastlane/lib/fastlane/actions/ensure_env_vars.rb', line 18

def self.details
  'This action will check if some environment variables are set.'
end

.example_codeObject



37
38
39
40
41
42
43
# File 'fastlane/lib/fastlane/actions/ensure_env_vars.rb', line 37

def self.example_code
  [
    'ensure_env_vars(
      env_vars: [\'GITHUB_USER_NAME\', \'GITHUB_API_TOKEN\']
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



49
50
51
# File 'fastlane/lib/fastlane/actions/ensure_env_vars.rb', line 49

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'fastlane/lib/fastlane/actions/ensure_env_vars.rb', line 4

def self.run(params)
  variables = params[:env_vars]
  missing_variables = variables.select { |variable| ENV[variable].to_s.strip.empty? }

  UI.user_error!("Missing environment variable(s) '#{missing_variables.join('\', \'')}'") unless missing_variables.empty?

  is_one = variables.length == 1
  UI.success("Environment variable#{is_one ? '' : 's'} '#{variables.join('\', \'')}' #{is_one ? 'is' : 'are'} set!")
end