Skip to content

Commit 0825988

Browse files
committed
fastlane: Add utilities to increment version numbers and allow uploading RCs to beta
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
1 parent 5a8bad3 commit 0825988

2 files changed

Lines changed: 107 additions & 38 deletions

File tree

fastlane/Fastfile

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,37 @@ default_platform(:android)
2828

2929
BUNDLE_PATH = "app/build/outputs/bundle/playRelease/app-play-release.aab"
3030

31-
import("./utils.Fastfile")
31+
import("./common.Fastfile")
3232

3333
platform :android do
3434
desc "Build app bundle"
3535

36+
desc "Run tests and build app"
3637
lane :releasePhase1 do
3738
test()
3839
buildBundle()
3940
end
4041

42+
desc "Release previously built app to Google Play and create tag"
43+
lane :releasePhase2 do
44+
versionInfo = getVersionInfo()
45+
versionComponents = parseVersionCode(versionInfo)
46+
checkReleasable(versionComponents)
47+
storeTrack = getPlayStoreTrack(versionComponents)
48+
tagName = getTagName(versionComponents)
49+
preReleaseChecks(versionInfo: versionInfo, tagName: tagName, type: versionComponents["type"], track: storeTrack)
50+
checkArtifactsExist()
51+
tag(tagName)
52+
uploadToPlayStore()
53+
end
54+
55+
desc "Run tests"
4156
lane :test do
4257
gradle(task: "clean testPlayReleaseUnitTest testFdroidReleaseUnitTest")
4358
end
4459

45-
lane :buildBundle do
60+
desc "Build app bundle"
61+
lane :buildBundle do
4662
gradle(
4763
task: 'bundle',
4864
flavor: 'play',
@@ -57,29 +73,24 @@ desc "Build app bundle"
5773
)
5874
end
5975

60-
lane :releasePhase2 do
61-
versionInfo = getVersionInfo()
62-
promptVersion(versionInfo)
63-
checkArtifactsExist()
64-
tag(versionInfo)
65-
uploadToPlayStore()
66-
end
67-
6876
desc "Show versions and prompt for confirmation"
69-
private_lane :promptVersion do |versionInfo|
77+
private_lane :preReleaseChecks do |options|
78+
versionInfo = options[:versionInfo]
79+
tagName = options[:tagName]
7080
currentBranch = git_branch()
71-
print "Version code: #{versionInfo["versionCode"]}\n"
72-
print "Version name: #{versionInfo["versionName"]}\n"
73-
print "Current branch: #{currentBranch}\n"
74-
print "Tag (to be created): #{versionInfo["versionName"]}\n"
75-
promptYesNo()
81+
text = "Version code: #{versionInfo["versionCode"]}\n" +
82+
"Version name: #{versionInfo["versionName"]}\n" +
83+
"Current branch: #{currentBranch}\n" +
84+
"Version type: #{options[:type]}\n" +
85+
"Tag: #{tagName}\n" +
86+
"Track: #{options[:track]}"
87+
promptYesNo(text: text)
7688
end
7789

7890
desc "Check if release artifacts exist"
7991
private_lane :checkArtifactsExist do
8092
if !File.exist?("../#{BUNDLE_PATH}")
81-
print "Bundle not found at #{BUNDLE_PATH}\n"
82-
exit
93+
UI.user_error!("Bundle not found at #{BUNDLE_PATH}")
8394
end
8495
end
8596

@@ -95,11 +106,12 @@ desc "Build app bundle"
95106
end
96107

97108
desc "Upload release artifacts to Google Play"
98-
private_lane :uploadToPlayStore do
109+
private_lane :uploadToPlayStore do |options|
99110
upload_to_play_store(
100111
skip_upload_images: true,
101112
skip_upload_apk: true,
102-
aab: BUNDLE_PATH,
113+
track: options[:track],
114+
aab: BUNDLE_PATH
103115
)
104116
end
105117

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ MAJOR_MULTIPLIER = 10000000
55
MINOR_MULTIPLIER = 10000
66
PATCH_MULTIPLIER = 100
77

8+
TYPE_ALPHA = "alpha"
9+
TYPE_RC = "rc"
10+
TYPE_FINAL = "final"
11+
812
platform :android do
913
desc "Print version info"
1014
lane :printVersionInfo do
@@ -18,7 +22,7 @@ platform :android do
1822
print "Build: #{versionComponents["build"]}\n"
1923
end
2024

21-
# Usage: fastlane incrementVersion [type:major|minor|patch|rc|final]
25+
# Usage: fastlane incrementVersion type:(major|minor|patch|rc|final)
2226
# For major, minor, and patch: will increment that version number by 1 and set the smaller ones to 0
2327
# For rc, final: will set build number to first rc/first final or increment it by 1
2428
desc "Increment version code and version name"
@@ -29,9 +33,9 @@ platform :android do
2933
versionNameGenerated = generateVersionName(newVersionComponents)
3034
versionCodeGenerated = generateVersionCode(newVersionComponents)
3135

32-
print "Version code: #{versionInfo["versionCode"]} -> #{versionCodeGenerated}\n"
33-
print "Version name: #{versionInfo["versionName"]} -> #{versionNameGenerated}\n"
34-
promptYesNo()
36+
promptYesNo(text: "Version code: #{versionInfo["versionCode"]} -> #{versionCodeGenerated}\n" +
37+
"Version name: #{versionInfo["versionName"]} -> #{versionNameGenerated}"
38+
)
3539
writeVersions(versionCode: versionCodeGenerated, versionName: versionNameGenerated)
3640
end
3741

@@ -44,12 +48,30 @@ platform :android do
4448
minor = (versionCode / MINOR_MULTIPLIER) % 100
4549
major = (versionCode / MAJOR_MULTIPLIER) % 100
4650

47-
{ "major" => major, "minor" => minor, "patch" => patch, "build" => build }
51+
type = getVersionType(build: build)
52+
53+
54+
{ "major" => major, "minor" => minor, "patch" => patch, "build" => build, "type" => type }
4855
end
4956

57+
desc "Get version type from build number"
58+
private_lane :getVersionType do |options|
59+
build = options[:build]
60+
if build < BUILD_NUMBER_RC_START
61+
type = TYPE_ALPHA
62+
elsif build < BUILD_NUMBER_FINAL_START
63+
type = TYPE_RC
64+
else
65+
type = TYPE_FINAL
66+
end
67+
type
68+
end
69+
70+
71+
5072
desc "Generate versionCode from version components"
5173
private_lane :generateVersionCode do |versionComponents|
52-
print "Generating version code from #{versionComponents}\n"
74+
puts "Generating version code from #{versionComponents}"
5375
major = versionComponents["major"]
5476
minor = versionComponents["minor"]
5577
patch = versionComponents["patch"]
@@ -62,12 +84,13 @@ platform :android do
6284
private_lane :generateVersionName do |versionComponents|
6385
suffix = ""
6486
buildNumber = versionComponents["build"]
87+
puts "Generating version name from #{versionComponents}\n"
6588
case
66-
when buildNumber >= BUILD_NUMBER_RC_START && buildNumber < BUILD_NUMBER_FINAL_START
89+
when versionComponents["type"] == TYPE_RC
6790
rcNumber = (buildNumber - BUILD_NUMBER_RC_START) + 1
68-
suffix = " RC #{rcNumber}"
69-
when buildNumber < BUILD_NUMBER_RC_START
70-
suffix = " Alpha #{buildNumber + 1}"
91+
suffix = " RC#{rcNumber}"
92+
when versionComponents["type"] == TYPE_ALPHA
93+
suffix = " Alpha#{buildNumber + 1}"
7194
end
7295
"#{versionComponents["major"]}.#{versionComponents["minor"]}.#{versionComponents["patch"]}#{suffix}"
7396
end
@@ -111,28 +134,62 @@ platform :android do
111134
versionComponents["patch"] = versionComponents["patch"] + 1
112135
versionComponents["build"] = 0
113136
when "rc"
114-
if versionComponents["build"] < BUILD_NUMBER_RC_START || versionComponents["build"] >= BUILD_NUMBER_FINAL_START
137+
if versionComponents["type"] != TYPE_RC
115138
versionComponents["build"] = BUILD_NUMBER_RC_START
116139
else
117140
versionComponents["build"] = versionComponents["build"] + 1
118141
end
119142
when "final"
120-
if versionComponents["build"] < BUILD_NUMBER_FINAL_START
143+
if versionComponents["type"] != TYPE_FINAL
121144
versionComponents["build"] = BUILD_NUMBER_FINAL_START
122145
else
123146
versionComponents["build"] = versionComponents["build"] + 1
124147
end
125148
else
126-
print "Unknown or missing version type: #{options[:type]}\n"
127-
exit
149+
UI.user_error!("Unknown or missing version increment type #{options[:type]}. Usage: incrementVersion type:(major|minor|patch|rc|final)")
128150
end
151+
versionComponents["type"] = getVersionType(build: versionComponents["build"])
129152
versionComponents
130153
end
131154

132-
private_lane :promptYesNo do
133-
answer = prompt(text: "is this okay?", boolean: true)
134-
if !answer
135-
exit
155+
desc "Get tag name from version components"
156+
private_lane :getTagName do |versionComponents|
157+
if versionComponents["type"] == TYPE_FINAL
158+
tag = "#{versionComponents["major"]}.#{versionComponents["minor"]}.#{versionComponents["patch"]}"
159+
elsif versionComponents["type"] == TYPE_RC
160+
rcNumber = (versionComponents["build"] - BUILD_NUMBER_RC_START) + 1
161+
rcNumberPadded = "%02d" % rcNumber
162+
tag = "rc-#{versionComponents["major"]}.#{versionComponents["minor"]}.#{versionComponents["patch"]}-#{rcNumberPadded}"
163+
else
164+
UI.user_error!("Build number cannot be tagged: #{versionComponents["build"]}")
136165
end
137166
end
167+
168+
desc "Check if version is releasable"
169+
private_lane :checkReleasable do |versionComponents|
170+
if versionComponents["type"] != TYPE_FINAL && versionComponents["type"] != TYPE_RC
171+
UI.user_error!("Version is not releasable: #{versionComponents["type"]}")
172+
end
173+
end
174+
175+
desc "Get play store track from version type"
176+
private_lane :getPlayStoreTrack do |versionComponents|
177+
case versionComponents["type"]
178+
when TYPE_RC
179+
track = "beta"
180+
when TYPE_FINAL
181+
track = "production"
182+
else
183+
UI.user_error!("Version is not releasable: #{versionComponents["type"]}")
184+
end
185+
end
186+
187+
end
188+
189+
private_lane :promptYesNo do |options|
190+
puts "\n" + options[:text]
191+
answer = prompt(text: "is this okay?", boolean: true)
192+
if !answer
193+
UI.user_error!("Aborting")
194+
end
138195
end

0 commit comments

Comments
 (0)