forked from classi/fastlane-example
/
Fastfile
245 lines (199 loc) · 6.3 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
fastlane_version "2.19.2"
default_platform :ios
import_from_git(
url: 'https://github.com/classi/fastlane-example',
path: 'Util/Fastfile'
)
platform :ios do
changelog = ""
default_payloads = [:lane, :test_result, :git_branch, :git_author]
keychain = {name: "name", password: "password"}
before_all do
# ENV['DELIVER_ITMSTRANSPORTER_ADDITIONAL_UPLOAD_PARAMETERS'] = '-t DAV'
changelog = changelog_from_git_commits_hs
if is_ci?
# sh("rm /Users/distiller/Library/Keychains/#{keychain[:name]}-db || echo")
setup_ci(
force: true,
provider: "travis",
)
# create_keychain(
# name: keychain[:name],
# password: keychain[:password],
# default_keychain: true,
# unlock: true,
# timeout: 3600,
# lock_when_sleeps: false
# )
end
end
desc "Runs all the tests"
lane :test do
scan
xcov(
workspace: ENV["XCOV_WORKSPACE"],
scheme: ENV["XCOV_SCHEME"],
exclude_targets: ENV["XCOV_EXCLUDE_TARGETS"]
)
danger
end
desc "Deploy a new version to the Crashlytics Beta"
lane :beta do
# Download and install certificate
if is_ci?
match(type: ENV["BETA_MATCH_TYPE"], force_for_new_devices: true, keychain_name: keychain[:name], keychain_password: keychain[:password])
else
match(type: ENV["BETA_MATCH_TYPE"], force_for_new_devices: true)
end
# Update build number
increment_build_number(build_number: "0.#{Time.now.strftime("%Y%m%d%H%M")}")
# Change application icon to beta version
badge(dark: true)
# Compile
gym(export_method: "development", configuration: "Debug", export_options: { compileBitcode: false })
# Save ipa and dSYM
if is_ci?
sh "cp #{lane_context[SharedValues::IPA_OUTPUT_PATH]} $CIRCLE_ARTIFACTS"
sh "cp #{lane_context[SharedValues::DSYM_OUTPUT_PATH]} $CIRCLE_ARTIFACTS"
end
# Upload ipa to crashslytics
crashlytics(
crashlytics_path: "Pods/Crashlytics/iOS/Crashlytics.framework",
api_token: ENV['CRASHLYTICS_API_TOKEN'],
build_secret: ENV['CRASHLYTICS_BUILD_SECRET'],
ipa_path: lane_context[SharedValues::IPA_OUTPUT_PATH],
notes: changelog,
groups: ENV["CRASHLYTICS_GROUPS"]
)
# Upload dSYM to crashslytics
upload_symbols_to_crashlytics(
binary_path: ENV['UPLOAD_SYMBOLS_PATH']
)
# notify slack
payload = {"Git Commit" => changelog}
payload["Circle Artifacts Url"] = ENV["CIRCLE_BUILD_URL"] + "#artifacts/containers/0" if is_ci?
slack(
channel: ENV["SLACK_CHANNEL"],
message: ":crashlytics: Beta App successfully released!",
payload: payload,
default_payloads: default_payloads
)
end
desc "Deploy a new version to the App Store"
lane :release do
api_key = app_store_connect_api_key(
key_id: ENV['ASC_KEY_ID'],
issuer_id: ENV['ASC_ISSUER_ID'],
key_content: ENV['ASC_KEY_CONTENT'],
)
# Download and install certificate
if is_ci?
match(type: "appstore", git_url: ENV["GITHUB_CERTIFICATES_REPO"])
else
match(type: "appstore")
end
# Update build number
increment_build_number(build_number: "#{Time.now.strftime("%Y%m%d%H%M")}")
# Compile
gym(scheme: ENV["RELEASE_GYM_SCHEME"])
# Save ipa and dSYM
if is_ci?
sh "cp #{lane_context[SharedValues::IPA_OUTPUT_PATH]} $CIRCLE_ARTIFACTS"
sh "cp #{lane_context[SharedValues::DSYM_OUTPUT_PATH]} $CIRCLE_ARTIFACTS"
end
# Upload ipa to iTunes Connect
deliver
# Upload dSYM to crashslytics
upload_symbols_to_crashlytics(
binary_path: ENV['UPLOAD_SYMBOLS_PATH']
)
# Upload dSYM to iTunesConnect
upload_latest_dsyms
# Get diff from the last tag
sh("git tag -d v#{get_version_number} || echo")
diff = git_tag_diff
# Create git tag
# Force pushing because it may create the same tag more than once.
add_git_tag(
tag: "v#{get_version_number}",
message: "build_number: #{get_build_number} by fastlane\n\n#{diff}",
force: true
)
push_git_tags(force: true)
# notify slack
payload = {"Git Commit" => changelog}
slack(
channel: ENV["SLACK_CHANNEL"],
message: ":itunesconnect: Successfully uploaded a new App Store build",
payload: payload,
default_payloads: default_payloads
)
end
lane :upload_latest_dsyms do
download_dsyms(version: "latest")
upload_symbols_to_crashlytics(
binary_path: ENV['UPLOAD_SYMBOLS_PATH']
)
clean_build_artifacts
end
desc "Download dSYMs from iTunesConnect and upload to crashylitics"
lane :refresh_dsyms do
download_dsyms
upload_symbols_to_crashlytics(
gsp_path: ENV['GOOGLE_SERVICES_INFO_PLIST_PATH'],
binary_path: ENV['UPLOAD_SYMBOLS_PATH']
)
clean_build_artifacts
slack(
message: "Successfully uploaded dSYMs to :crashlytics:",
payload: {
"Circle Build Url" => ENV["CIRCLE_BUILD_URL"]
}
)
end
desc "Update app_version and create release branch in GitHub"
desc "ex: fastlane release_branch version:1.0.0"
lane :release_branch do |options|
# Check arguments
UI.user_error!("Required release version. ex: fastlane release_branch version:1.0.0") unless options[:version]
branch = "release/#{options[:version]}"
# Create release branch
sh("git checkout master && git pull origin master")
sh("git checkout -b #{branch}")
# Update version_number and git commit
increment_version_number(version_number: options[:version])
commit_version_bump(
message: "Create #{branch} branch.",
xcodeproj: ENV["XCODEPROJ"]
)
# Push to GitHub and create Pull Reqeust
push_to_git_remote
create_pull_request(
repo: ENV["GITHUB_REPOSITORY"],
title: "#{branch}",
body: "release v#{options[:version]}"
)
end
desc "frameit"
lane :screenshots do
frameit(path: './fastlane/screenshots/', white: true)
Dir.glob('./fastlane/screenshots/**/*.png') do |png|
if !png.include?('framed')
File.delete(png)
end
end
end
error do |lane, exception|
slack(
channel: ENV["SLACK_CHANNEL"],
message: exception.message,
success: false,
payload: {
"Circle Build Url" => ENV["CIRCLE_BUILD_URL"]
}
)
end
after_all do
reset_diff
end
end