Class: Fastlane::Actions::AddFastlaneVarAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.app_key_for(namespace) ⇒ Object

Returns the app key for cryptex. optionally namespaced



87
88
89
90
91
92
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 87

def self.app_key_for(namespace)
  default_app_key = Helper::ReactNativeReleaseHelper::APP_CRYPTEX_KEY 
  return default_app_key if namespace.strip.empty?

  "#{namespace}_#{default_app_key}"
end

.authorsObject



71
72
73
74
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 71

def self.authors
  # So no one will ever forget your contribution to fastlane :) You are awesome btw!
  ["cball", "isaiahgrey93"]
end

.available_optionsObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 50

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :key,
                                 env_name: "FL_ADD_APP_VAR_KEY",
                                 description: "Enter the ENV name",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :value,
                                 env_name: "FL_ADD_APP_VAR_VALUE",
                                 description: "Enter the ENV value",
                                 type: String),
  ]
end

.default_env_pathObject



94
95
96
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 94

def self.default_env_path
  Helper::ReactNativeReleaseHelper::APP_ENV_PATH
end

.descriptionObject



41
42
43
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 41

def self.description
  "Adds a single ENV var for fastlane to the encrypted repository"
end

.detailsObject



45
46
47
48
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 45

def self.details
  # Optional:
  # this is your chance to provide a more detailed description of this action
end

.env_path_for(namespace) ⇒ Object

Returns a path for an env var. optionally namespaced



81
82
83
84
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 81

def self.env_path_for(namespace)
  return default_env_path if namespace.strip.empty?
  "#{default_env_path}.#{namespace}"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 76

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

.return_valueObject



63
64
65
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 63

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fastlane/plugin/react_native_release/actions/add_fastlane_var.rb', line 7

def self.run(params)
  is_ci = ENV['CI'] === 'true'
  cryptex_key = Helper::ReactNativeReleaseHelper::FASTLANE_CRYPTEX_KEY
 
  key = params[:key]
  value = params[:value]
  existing_app_vars = {}

  if !is_ci && !UI.confirm("This will add #{key}=#{value} to the #{cryptex_key} namespace in the encrypted context repo. Proceed?")
    UI.abort_with_message!("Stepping away...")
  end

  begin
    existing_vars = other_action.cryptex(
      type: 'export_env',
      key:  cryptex_key
    )
  rescue => ex
    # If key doesn't exist cryptex will error
  end

  other_action.cryptex(
    type: "import_env",
    key:  cryptex_key,
    hash: existing_vars.merge({ key => value })
  )

  UI.success('Encrypted fastlane ENV vars')
end