-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathFastfile
195 lines (165 loc) · 5.59 KB
/
Fastfile
1
2
3
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
fastlane_version '2.86.0'
default_platform :ios
# --------- Before any lane runs --------- #
before_all do
ENV['SLACK_URL'] ||= ENV['TAB_SLACK_WEBHOOK_URL']
end
# --------- Custom lanes --------- #
desc 'Runs all unit tests that are included in the scheme.'
desc 'It\'s not recommended to include UI tests in this scheme, instead run the "ui_test" lane.'
lane :test do
_setup
skip_slack = ENV['SCAN_SLACK_CHANNEL'].to_s.strip.empty?
scan(skip_slack: skip_slack)
end
desc 'Runs UI tests that are included in the scheme.'
desc 'Environment variables to use: `TAB_UI_TEST_DEVICES`, `TAB_REPORT_FORMATS`, `TAB_UI_TEST_SCHEME`'
lane :ui_test do
_setup
skip_slack = ENV['SCAN_SLACK_CHANNEL'].to_s.strip.empty?
scan(skip_slack: skip_slack,
devices: ENV['TAB_UI_TEST_DEVICES'],
output_types: ENV['TAB_REPORT_FORMATS'],
scheme: ENV['TAB_UI_TEST_SCHEME'])
end
desc 'Runs all unit tests before deploying to App Center.'
lane :deploy_to_app_center do
_setup
scan
_build_and_deploy_to_app_center
end
desc 'Deploys to App Center without running any tests.'
lane :deploy_to_app_center_no_test do
_setup
_build_and_deploy_to_app_center
end
desc 'Runs all unit tests before deploying to TestFlight.'
lane :deploy_to_test_flight do
if _get_export_method == 'app-store'
_setup
scan
_set_build_number
_build_ipa
_upload_to_test_flight
else
UI.message('Deploy to TestFlight failed. Uploading to iTunes Connect only supports `app-store` export method.')
end
end
desc 'Creates a local IPA build without running any tests.'
lane :local_build do |options|
icon_overlay(version: _get_project_build_number) if options[:icon_overlay]
_build_ipa
end
# --------- After all lanes have run --------- #
after_all do
_notify_slack
end
# --------- Error handling --------- #
error do |lane, exception|
end
# --------- Custom functions --------- #
def _setup
ENV['SCAN_SCHEME'] = ENV['GYM_SCHEME']
ENV['SCAN_DEVICE'] ||= 'iPhone 6 (12.0)'
xcode_select(ENV['TAB_XCODE_PATH']) if is_ci && !ENV['TAB_XCODE_PATH'].nil?
unless ENV['TAB_UI_TEST_SCHEME'].nil? # rubocop:disable Style/GuardClause
ENV['TAB_REPORT_FORMATS'] = 'html' if ENV['TAB_OUTPUT_TYPES'].nil?
ENV['TAB_UI_TEST_DEVICES'] ||= 'iPhone 8'
end
end
def _build_and_deploy_to_app_center
icon_overlay(version: _get_project_build_number)
_set_build_number
_build_ipa
_upload_to_app_center
end
def _build_number
use_timestamp = ENV['TAB_USE_TIME_FOR_BUILD_NUMBER'].to_s.downcase == 'true' || false # rubocop:disable Performance/Casecmp
if use_timestamp
Time.now.strftime("%y%m%d%H%M") # rubocop:disable Style/StringLiterals
else
ENV['BUILD_NUMBER']
end
end
def _get_project_build_number
get_version_number(target: ENV['TAB_PRIMARY_TARGET'])
end
def _set_build_number
increment_build_number(build_number: _build_number)
end
def _build_ipa
update_app_identifier(xcodeproj: ENV['FL_UPDATE_PLIST_PROJECT_PATH'],
plist_path: ENV['FL_UPDATE_PLIST_PATH'],
app_identifier: ENV['FL_UPDATE_PLIST_APP_IDENTIFIER'])
update_info_plist
_build_with_gym
end
def _build_with_gym
install_provisioning_profiles
_update_team_id_if_necessary
export_method = _get_export_method
xcconfig_filename = Dir.pwd + '/TAB.release.xcconfig'
create_xcconfig(filename: xcconfig_filename)
gym(export_method: export_method, xcconfig: xcconfig_filename)
end
def _get_export_method
if ENV['GYM_EXPORT_OPTIONS'].nil?
_fallback_to_enterprise_export_method
else
get_info_plist_value(path: ENV['GYM_EXPORT_OPTIONS'], key: 'method')
end
end
def _fallback_to_enterprise_export_method
UI.message('Falling back to enterprise `export_method` since `GYM_EXPORT_OPTIONS` is not defined')
'enterprise'
end
def _update_team_id_if_necessary
project_path = ENV['FL_PROJECT_SIGNING_PROJECT_PATH']
team_id = _get_team_id
if !project_path.to_s.strip.empty? && !team_id.to_s.strip.empty?
UI.message("Updating project team with project path '#{project_path}' and team id '#{team_id}'.")
update_project_team(path: project_path, teamid: team_id)
else
UI.message('Unable to find project path or project team so skipping updating project team.')
end
end
def _get_team_id
team_id = ENV['FL_PROJECT_TEAM_ID']
unless team_id
UI.message('Attempting to extract team ID from `GYM_EXPORT_OPTIONS` since `FL_PROJECT_TEAM_ID` is not defined.')
team_id = get_info_plist_value(path: ENV['GYM_EXPORT_OPTIONS'],
key: 'teamID')
end
team_id
end
def _upload_to_app_center
custom_notes = ENV['TAB_HOCKEY_RELEASE_NOTES'] || ''
notes = custom_notes == '' ? _create_change_log : custom_notes
appcenter_upload(
release_notes: notes
)
end
def _create_change_log
cmd = "git log --after={1.day.ago} --pretty=format:'%an%x09%h%x09%cd%x09%s' --date=relative"
output = `#{cmd}`
output.to_s.empty? ? 'No Changes' : output
end
def _upload_to_test_flight
pilot(username: ENV['ITUNES_CONNECT_USERNAME'],
team_id: ENV['ITUNES_CONNECT_TEAM_ID'],
itc_provider: ENV['ITUNES_CONNECT_PROVIDER'],
skip_waiting_for_build_processing: true,
skip_submission: true)
end
def _notify_slack
return if ENV['FL_SLACK_CHANNEL'].to_s.strip.empty?
app_center_download_url = lane_context[SharedValues::APPCENTER_BUILD_INFORMATION]
build_number = _build_number
if !app_center_download_url.nil?
message_prefix = build_number.to_s.empty? ? 'A new build' : "Build #{build_number}"
new_build_message = "#{message_prefix} is available on <#{app_center_download_url}|app center>"
slack(message: new_build_message)
else
slack
end
end