Class: Fastlane::Actions::LatestTestflightBuildNumberAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/latest_testflight_build_number.rb

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, sh, step_text

Class Method Details

.authorsObject



83
84
85
# File 'lib/fastlane/actions/latest_testflight_build_number.rb', line 83

def self.authors
  ["daveanderson"]
end

.available_optionsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/actions/latest_testflight_build_number.rb', line 51

def self.available_options
  user = CredentialsManager::AppfileConfig.try_fetch_value(:itunes_connect_id)
  user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)

  [
    FastlaneCore::ConfigItem.new(key: :app_identifier,
                                 short_option: "-a",
                                 env_name: "FASTLANE_APP_IDENTIFIER",
                                 description: "The bundle identifier of your app",
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)),
    FastlaneCore::ConfigItem.new(key: :username,
                                 short_option: "-u",
                                 env_name: "ITUNESCONNECT_USER",
                                 description: "Your Apple ID Username",
                                 default_value: user),
    FastlaneCore::ConfigItem.new(key: :version,
                                 env_name: "LATEST_VERSION",
                                 description: "The version number whose latest build number we want",
                                 optional: true)
  ]
end

.descriptionObject



43
44
45
# File 'lib/fastlane/actions/latest_testflight_build_number.rb', line 43

def self.description
  "Fetches most recent build number from TestFlight"
end

.detailsObject



47
48
49
# File 'lib/fastlane/actions/latest_testflight_build_number.rb', line 47

def self.details
  "Provides a way to have increment_build_number be based on the latest build you uploaded to iTC."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/fastlane/actions/latest_testflight_build_number.rb', line 87

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

.outputObject



73
74
75
76
77
# File 'lib/fastlane/actions/latest_testflight_build_number.rb', line 73

def self.output
  [
    ['LATEST_TESTFLIGHT_BUILD_NUMBER', 'The latest build number of the latest version of the app uploaded to TestFlight']
  ]
end

.return_valueObject



79
80
81
# File 'lib/fastlane/actions/latest_testflight_build_number.rb', line 79

def self.return_value
  "Integer representation of the latest build number uploaded to TestFlight"
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/actions/latest_testflight_build_number.rb', line 11

def self.run(params)
  require 'spaceship'

  credentials = CredentialsManager::AccountManager.new(user: params[:username])
  Spaceship::Tunes.(credentials.user, credentials.password)
  Spaceship::Tunes.select_team
  app = Spaceship::Tunes::Application.find(params[:app_identifier])

  version_number = params[:version]
  unless version_number
    # Automatically fetch the latest version in testflight
    if app.build_trains.keys.last
      version_number = app.build_trains.keys.last
    else
      Helper.log.info "You have to specify a new version number: "
      version_number = STDIN.gets.strip
    end
  end

  Helper.log.info "Fetching the latest build number for version #{version_number}"

  train = app.build_trains[version_number]
  build_number = train.builds.map(&:build_version).map(&:to_i).sort.last

  Helper.log.info "Latest upload is build number: #{build_number}"
  Actions.lane_context[SharedValues::LATEST_TESTFLIGHT_BUILD_NUMBER] = build_number
end