Class: Fastlane::Actions::DecryptAppVarsAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



107
108
109
110
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_app_vars.rb', line 107

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

.available_optionsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_app_vars.rb', line 72

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :namespace,
                                 env_name: "FL_DECRYPT_APP_VARS_NAMESPACE", # The name of the environment variable
                                 description: "What namespace should we use? (alpha, beta, release, ENTER = root)", # a short description of this parameter
                                 type: String,
                                 verify_block: lambda do |value|
                                  unless Helper::ReactNativeReleaseHelper::VALID_NAMESPACES.include?(value)
                                    UI.user_error!("Invalid namespace #{value}. Valid targets are #{Helper::ReactNativeReleaseHelper::VALID_NAMESPACES.join(', ')}") 
                                    next
                                  end
                                end),
    FastlaneCore::ConfigItem.new(key: :write_env,
                                 env_name: "FL_DECRYPT_APP_VARS_WRITE_ENV", # The name of the environment variable
                                 description: "If we should write an .env file", # a short description of this parameter
                                 type: Boolean,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :skip_confirmation,
                                 env_name: "FL_ENCRYPT_APP_VARS_SKIP_CONFIRMATION", # The name of the environment variable
                                 description: "Allows commands to be run from within CLI and skip the UI.message confirmation dialog", # a short description of this parameter
                                 type: Boolean,
                                 short_option:'s',
                                 default_value: false,
                                 optional: true)
  ]
end

.descriptionObject



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

def self.description
  "Decrypts app env vars and sets the values in the root .env file"
end

.detailsObject



67
68
69
70
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_app_vars.rb', line 67

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_app_vars.rb', line 112

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

.return_valueObject



99
100
101
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_app_vars.rb', line 99

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fastlane/plugin/react_native_release/actions/decrypt_app_vars.rb', line 7

def self.run(params)
  is_ci = ENV['CI'] === 'true'
  namespace = params[:namespace]
  write_env = params[:write_env]
  skip_confirmation= params[:skip_confirmation]
  default_cryptex_app_key = Helper::ReactNativeReleaseHelper::APP_CRYPTEX_KEY
  cryptex_app_key = Helper::ReactNativeReleaseHelper.app_key_for(namespace)
  is_same_key = default_cryptex_app_key == cryptex_app_key
  message = ''

  if(!skip_confirmation)
    if is_same_key
      message = "This will decrypt values from #{cryptex_app_key}. Proceed?"
    else
      message = "This will decrypt and merge values from #{cryptex_app_key} into #{default_cryptex_app_key}. Proceed?"
    end
  

    if !is_ci && !UI.confirm(message)
      UI.abort_with_message!("Stepping away...")
    end
  end

  app_vars = other_action.cryptex(
    type: "export_env",
    key: default_cryptex_app_key
  )

  namespaced_vars = other_action.cryptex(
    type: "export_env",
    key: cryptex_app_key
  )

  merged_vars = app_vars.merge(namespaced_vars)
  has_env_file = File.exists?(Helper::ReactNativeReleaseHelper::APP_ENV_PATH)
  should_write_env = write_env && (is_ci || skip_confirmation || !has_env_file || UI.confirm("It looks like you already have an .env file. Overwrite it?"))

  # write an env file with the merged values
  if (should_write_env)
    # TODO: handle running action from root and from ios/android folders. This will not work properly in the root as is.
    open('../.env', 'w') do |f|
      merged_vars.each {|key, value| f.puts "#{key}=#{value}" }
    end

    UI.success('.env written')
  else
    UI.success('not writing .env')
  end

  merged_vars
end