Class: Fastlane::Actions::FivAndroidKeystoreAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



120
121
122
# File 'lib/fastlane/plugin/fivethree_ionic/actions/fiv_android_keystore_action.rb', line 120

def self.authors
  ["fivethree"]
end

.available_optionsObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/fastlane/plugin/fivethree_ionic/actions/fiv_android_keystore_action.rb', line 93

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :output_directory,
                                 env_name: "ANDROID_KEYSTORE_OUTPUT_DIRECTORY",
                                 description: "",
                                 is_string: true,
                                 optional: false,
                                 default_value: File.absolute_path(File.join(Dir.pwd, ".android_signing"))),
    FastlaneCore::ConfigItem.new(key: :keystore_name,
                                 env_name: "ANDROID_KEYSTORE_KEYSTORE_NAME",
                                 description: "",
                                 is_string: true,
                                 optional: false)
  ]
end

.descriptionObject



85
86
87
# File 'lib/fastlane/plugin/fivethree_ionic/actions/fiv_android_keystore_action.rb', line 85

def self.description
  "Generate an Android keystore file"
end

.detailsObject



89
90
91
# File 'lib/fastlane/plugin/fivethree_ionic/actions/fiv_android_keystore_action.rb', line 89

def self.details
  "Generate an Android keystore file"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/fastlane/plugin/fivethree_ionic/actions/fiv_android_keystore_action.rb', line 124

def self.is_supported?(platform)
  platform == :android
end

.outputObject



109
110
111
112
113
114
# File 'lib/fastlane/plugin/fivethree_ionic/actions/fiv_android_keystore_action.rb', line 109

def self.output
  [
    ['ANDROID_KEYSTORE_KEYSTORE_PATH', 'Path to keystore'],
    ['ANDROID_KEYSTORE_RELEASE_SIGNING_PATH', 'Path to release-signing.properties']
  ]
end

.return_valueObject



116
117
118
# File 'lib/fastlane/plugin/fivethree_ionic/actions/fiv_android_keystore_action.rb', line 116

def self.return_value
  "Path to keystore"
end

.run(params) ⇒ Object



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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fastlane/plugin/fivethree_ionic/actions/fiv_android_keystore_action.rb', line 9

def self.run(params)

  output_directory = params[:output_directory]
  keystore_name = params[:keystore_name]
  keystore_path = File.join(output_directory, keystore_name) + '.keystore'

  # Validating output doesn't exist yet for our android signing info
  if File.directory?(output_directory)
    if File.exists?(keystore_path)
      return keystore_path
    end
  else
    UI.message "android keystore doesnt exist yet. creating one for you..."
    Dir.mkdir output_directory
  end


  puts "Please enter the keystore password for new keystore:"
  keychain_entry = CredentialsManager::AccountManager.new(user: "#{keystore_name}_android_keystore_storepass")
  password = keychain_entry.password

  puts "Please enter the keystore password for new keystore:"
  keypass_entry = CredentialsManager::AccountManager.new(user: "#{keystore_name}_android_keystore_keypass")
  key_password = keypass_entry.password

  alias_name = Fastlane::Actions::PromptAction.run(text:"Enter kexystore alias")


  full_name = Fastlane::Actions::PromptAction.run(text:"Enter kexystore full name")
  org = Fastlane::Actions::PromptAction.run(text:"Enter kexystore org")
  org_unit = Fastlane::Actions::PromptAction.run(text:"Enter kexystore org unit")
  city_locality = Fastlane::Actions::PromptAction.run(text:"Enter city")
  state_province = Fastlane::Actions::PromptAction.run(text:"Enter state")
  country = Fastlane::Actions::PromptAction.run(text:"country")
  
  Actions.lane_context[SharedValues::ANDROID_KEYSTORE_KEYSTORE_PATH] = keystore_path
  
  # Create keystore with command
  unless File.file?(keystore_path)
    keytool_parts = [
      "keytool -genkey -v",
      "-keystore #{keystore_path}",
      "-alias #{alias_name}",
      "-keyalg RSA -keysize 2048 -validity 10000",
      "-storepass #{password} ",
      "-keypass #{key_password}",
      "-dname \"CN=#{full_name}, OU=#{org_unit}, O=#{org}, L=#{city_locality}, S=#{state_province}, C=#{country}\"",
    ]
    sh keytool_parts.join(" ")
  else
    UI.message "Keystore file already exists - #{keystore_path}"
  end
  
  # Create release-signing.properties for automatic signing with Ionic
    
    release_signing_path = File.join(output_directory, "release-signing.properties")
    Actions.lane_context[SharedValues::ANDROID_KEYSTORE_RELEASE_SIGNING_PATH] = release_signing_path
    
    unless File.file?(release_signing_path)
      out_file = File.new(release_signing_path, "w")
      out_file.puts("storeFile=#{keystore_name}")
      out_file.puts("storePassword=#{password}")
      out_file.puts("keyAlias=#{alias_name}")
      out_file.puts("keyPassword=#{key_password}")
      out_file.close
    else
      UI.message "release-signing.properties file already exists - #{release_signing_path}"
    end
  
  return keystore_path
end