Class: Fastlane::Actions::CreateFastlaneSessionAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



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

def self.authors
  ["cball", "isaiahgrey93"]
end

.available_optionsObject



57
58
59
60
61
62
63
64
# File 'lib/fastlane/plugin/react_native_release/actions/create_fastlane_session.rb', line 57

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: "FL_CREATE_FASTLANE_SESSION_USERNAME",
                                 description: "Enter the Apple username to generate a App Store Connect session",
                                 type: String)
  ]
end

.descriptionObject



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

def self.description
  "Simplify 2FA authentication for App Store Connect"
end

.detailsObject



53
54
55
# File 'lib/fastlane/plugin/react_native_release/actions/create_fastlane_session.rb', line 53

def self.details
  "Creates a cookie for authenticating with App Store connecting. Handles generating, encrypting, and storing the cookie."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  [:ios, :android].include?(platform)
end

.return_valueObject



49
50
51
# File 'lib/fastlane/plugin/react_native_release/actions/create_fastlane_session.rb', line 49

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

def self.run(params)
  username = params[:username]
  key = Helper::ReactNativeReleaseHelper::FASTLANE_SESSION_CRYPTEX_KEY
  fastlane_key = Helper::ReactNativeReleaseHelper::FASTLANE_CRYPTEX_KEY
  fastlane_session_cookie_path = "#{File.expand_path('~')}/.fastlane/spaceship/#{username}/cookie"

  UI.message "Generating a new fastlane session."
  UI.message "Please enter the 6 digit 2FA code if one is sent to your device otherwise the script will continue automatically."
  
  sh("fastlane spaceauth -u #{username.shellescape}")

  # store the session
  other_action.cryptex(
    type: "import",
    in: fastlane_session_cookie_path,
    key: key
  )

  # store the username that created the session in fastlane_vars
  existing_fastlane_vars = other_action.cryptex(
    type: 'export_env',
    key: fastlane_key,
  )

  other_action.cryptex(
    type: "import_env",
    key: fastlane_key,
    # PILOT_USERNAME needs to be set to the same username as the session above
    hash: existing_fastlane_vars.merge({ 'PILOT_USERNAME' => username })
  )

  UI.success "Uploaded session for #{username} to #{key}."
end