Class: Fastlane::Actions::GenerateAndroidKeystoreAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



127
128
129
130
# File 'lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb', line 127

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

.available_optionsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb', line 89

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :encrypt_in_repo,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_ENCRYPT_IN_REPO",
                                 description: "If the new keystore should be encrypted and saved",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :password,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_PASSWORD",
                                 description: "Password for the Keystore",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :alias,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_ALIAS",
                                 description: "ALIAS for the Keystore",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :destination,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_DESTINATION",
                                 description: "Where to put decrypted keystore",
                                 default_value: Helper::ReactNativeReleaseHelper::ANDROID_KEYSTORE_PATH),
    FastlaneCore::ConfigItem.new(key: :fullname,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_FULLNAME",
                                 description: "Fullname of keystore owner",
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :city,
                                 env_name: "FL_GENERATE_ANDROID_KEYSTORE_CITY",
                                 description: "City of keystore owner",
                                 type: String),
  ]
end

.create_keystore_with_params(params) ⇒ Object

Creates a new android keystore based on the provided params. Wraps Cryptex.



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

def self.create_keystore_with_params(params)
  begin
    other_action.cryptex_generate_keystore(
      destination: params[:destination],
      password: params[:password],
      fullname: params[:fullname],
      city: params[:city],
      alias: params[:alias]
    )
  rescue => ex
    UI.abort_with_message!("Could not create keystore. Do you already have one with this alias?")
  end

  params[:destination]
end

.descriptionObject



80
81
82
# File 'lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb', line 80

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

.detailsObject



84
85
86
87
# File 'lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb', line 84

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

.encrypt_keystore(keystore_path) ⇒ Object

Saves a keystore to the repo. Note this will overwrite it!



66
67
68
69
70
71
72
73
74
# File 'lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb', line 66

def self.encrypt_keystore(keystore_path)
  key = Helper::ReactNativeReleaseHelper::ANDROID_KEYSTORE_CRYPTEX_KEY

  other_action.cryptex(
    type: "import",
    in: keystore_path,
    key: key
  )
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb', line 132

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

.return_valueObject



119
120
121
# File 'lib/fastlane/plugin/react_native_release/actions/generate_android_keystore.rb', line 119

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
# 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