Method: Fastlane::Actions::GenerateAndroidKeystoreAction.run

Defined in:
lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb

.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
# File 'lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb', line 7

def self.run(params)
  encrypt_in_repo = params[:encrypt_in_repo]
  key = Helper::ReactNativeReleaseHelper::ANDROID_KEYSTORE_CRYPTEX_KEY

  # Confirm if there is an existing key in the repo... we don't want to overwrite prod!
  begin
    existing_remote_key = other_action.cryptex(
      type: "export",
      key: key
    )
  # If we don't have a keystore, cryptex will throw an exception.
  rescue => ex
    # create a new keystore and encrypt it
    UI.message('no keystore found in repo. creating it.')
    keystore = create_keystore_with_params(params)
    message = 'Created keystore'

    if encrypt_in_repo
      encrypt_keystore(keystore)
      message.concat(' and saved to repo.')
    end

    UI.success(message)
  end

  # If encrypting, confirm remote overwrite
  if (encrypt_in_repo && UI.confirm("This will overwrite your existing keystore! Are you sure?"))
    keystore_path = create_keystore_with_params(params)
    encrypt_keystore(keystore_path)
    UI.success('Created keystore and saved to repo.')
  elsif encrypt_in_repo
    # The user does not want to proceed
    UI.abort_with_message!("Stepping away...")
  else
    # Create, but don't encrypt
    create_keystore_with_params(params)

    UI.success('Created keystore, but did not save it to the repo.')
  end
end