Class: Fastlane::Actions::TestflightBuildAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.available_optionsObject



85
86
87
88
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/fastlane/plugin/stream_actions/actions/testflight_build.rb', line 85

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :api_key,
      description: 'AppStore Connect API Key',
      is_string: false,
      verify_block: proc do |api_key|
        UI.user_error!('AppStore Connect API Key has to be specified') if api_key.nil? || api_key.empty?
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :xcode_project,
      description: 'Path to the Xcode project',
      verify_block: proc do |path|
        UI.user_error!('Path to the Xcode project has to be specified') if path.nil? || path.empty?
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :sdk_target,
      description: 'SDK target name',
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :app_target,
      description: 'DemoApp target name',
      verify_block: proc do |target|
        UI.user_error!('DemoApp target name has to be specified') if target.nil? || target.empty?
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :app_version,
      description: 'DemoApp version',
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :extensions,
      description: 'Extensions/dependencies target names to bump build number',
      is_string: false,
      default_value: []
    ),
    FastlaneCore::ConfigItem.new(
      key: :app_identifier,
      description: 'DemoApp bundle identifier',
      verify_block: proc do |id|
        UI.user_error!('DemoApp bundle identifier has to be specified') if id.nil? || id.empty?
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :export_method,
      description: 'Method used to export the archive',
      default_value: 'app-store'
    ),
    FastlaneCore::ConfigItem.new(
      key: :export_options_plist,
      description: 'Path to plist file with export options. We have to pass manually since `gym` detects profiles from `match` and that breaks it',
      default_value: './fastlane/testflight_export_options.plist'
    ),
    FastlaneCore::ConfigItem.new(
      key: :export_options,
      description: 'Hash with export options. We have to pass manually since `gym` detects profiles from `match` and that breaks it',
      is_string: false,
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :output_directory,
      description: 'Output directory for the build',
      default_value: 'archives'
    ),
    FastlaneCore::ConfigItem.new(
      key: :xcargs,
      description: 'Pass additional arguments to xcodebuild for the build phase',
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      env_name: 'GITHUB_PR_NUM',
      key: :github_pr_num,
      description: 'GitHub PR number'
    ),
    FastlaneCore::ConfigItem.new(
      env_name: 'GITHUB_PR_NUM',
      key: :configuration,
      description: 'Build configuration',
      default_value: 'Release'
    )
  ]
end

.descriptionObject



81
82
83
# File 'lib/fastlane/plugin/stream_actions/actions/testflight_build.rb', line 81

def self.description
  'Builds a DemoApp and uploads it to TestFlight'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


172
173
174
# File 'lib/fastlane/plugin/stream_actions/actions/testflight_build.rb', line 172

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/stream_actions/actions/testflight_build.rb', line 4

def self.run(params)
  build_number = other_action.latest_testflight_build_number(
    app_identifier: params[:app_identifier],
    api_key: params[:api_key]
  ) + 1

  targets = params[:extensions] << params[:app_target]

  targets.each do |target|
    other_action.increment_build_number_in_plist(build_number: build_number.to_s, target: target)
  end

  if params[:app_version]
    targets.each do |target|
      other_action.increment_version_number_in_plist(version_number: params[:app_version].to_s, target: target)
    end
  else
    Spaceship::ConnectAPI.token = Spaceship::ConnectAPI::Token.from(hash: params[:api_key])
    app_store_versions = Spaceship::ConnectAPI::App.find(params[:app_identifier]).app_store_versions
    unless app_store_versions.empty?
      targets.each do |target|
        other_action.increment_version_number_in_plist(version_number: app_store_versions.first.version_string, target: target)
      end
    end
  end

  other_action.gym(
    project: params[:xcode_project],
    scheme: params[:app_target],
    configuration: params[:configuration],
    export_method: params[:export_method],
    export_options: params[:export_options] || params[:export_options_plist],
    clean: true,
    include_symbols: true,
    output_directory: params[:output_directory],
    xcargs: params[:xcargs]
  )

  external_groups = other_action.current_branch == 'main' ? ['Public Link'] : []
  other_action.pilot(
    api_key: params[:api_key],
    team_id: '118902954',
    app_identifier: params[:app_identifier],
    app_platform: 'ios',
    ipa: lane_context[SharedValues::IPA_OUTPUT_PATH],
    groups: external_groups,
    distribute_external: external_groups.any?,
    notify_external_testers: external_groups.any?,
    reject_build_waiting_for_review: true,
    changelog: testflight_instructions(params)
  )

  if params[:github_pr_num] && !params[:github_pr_num].strip.empty?
    message = "Build for regression testing №#{build_number} has been uploaded to TestFlight 🎁"
    sh("gh pr comment #{params[:github_pr_num]} -b '#{message}'")
  end
end

.testflight_instructions(params) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fastlane/plugin/stream_actions/actions/testflight_build.rb', line 62

def self.testflight_instructions(params)
  return "This is the official #{params[:app_target]} sample app" unless params[:sdk_target]

  version_number = other_action.get_version_number(target: params[:sdk_target])[/\d+\.\d+\.\d/]
  if ENV['GITHUB_EVENT_NAME'] == 'pull_request'
    sha = ENV['GITHUB_SHA'] ? ENV['GITHUB_SHA'][0..8] : sh('git rev-parse --short HEAD')
    "This is the build for Regression testing on release candidate v#{version_number} (sha: #{sha})."
  else
    "This is the official sample app built with iOS #{params[:sdk_target]} SDK v#{version_number}. It's designed " \
      'to highlight engaging features and new improvements to the SDK, but remember that this is just one ' \
      'possible implementation. You can start your own by borrowing and customizing the code from this ' \
      "sample, or build something completely different using Stream's components."
  end
end