Skip to content

Commit 5de1c58

Browse files
author
sm-deployer
authored
Merge pull request #377 from salemove/version-updater
2 parents 6a64b88 + ea1c6e6 commit 5de1c58

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

scripts/version-updater.gradle

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,66 @@ class UpdateCoreSdkVersion extends DefaultTask {
7272
/**
7373
* A task class for editing the Widget SDK version in version.properties
7474
* Example of usage from terminal:
75-
* ./gradlew saveWidgetsVersionName --versionCode=77 --versionName=0.77.2
75+
* ./gradlew saveWidgetsVersion --type=patch
7676
*/
7777
class UpdateProjectVersion extends DefaultTask {
78-
private String versionName
79-
private String versionCode
78+
private String versionUpdateType
8079

81-
@Option(option = "versionName", description = "Widget SDK version name that should be overriden in configuration files")
82-
UpdateProjectVersion setVersionName(String versionName) {
83-
this.versionName = versionName
84-
return this
85-
}
86-
87-
@Option(option = "versionCode", description = "Widget SDK version code that should be overriden in configuration files")
88-
UpdateProjectVersion setVersionCode(String versionCode) {
89-
this.versionCode = versionCode
80+
@Option(option = "type", description = "Type of version update. Can be 'patch', 'minor', or 'major'.")
81+
UpdateProjectVersion setVersionUpdateType(String versionUpdateType) {
82+
this.versionUpdateType = versionUpdateType
9083
return this
9184
}
9285

9386
@TaskAction
9487
void write() {
9588
Map<String, String> propertiesMap = new HashMap<>();
96-
propertiesMap.put(getProject().widgetsVersionNameTagInProperties, versionName)
97-
propertiesMap.put(getProject().widgetsVersionCodeTagInProperties, versionCode)
89+
propertiesMap.put(getProject().widgetsVersionCodeTagInProperties, updatedVersionCode())
90+
propertiesMap.put(getProject().widgetsVersionNameTagInProperties, updatedVersionName())
9891
getProject().saveProperties(propertiesMap)
9992
}
93+
94+
private String updatedVersionCode() {
95+
Integer currentVersionCode = getProject().widgetsVersionCode.toInteger()
96+
Integer updatedVersionCode = currentVersionCode + 1
97+
98+
return updatedVersionCode.toString()
99+
}
100+
101+
private String updatedVersionName() {
102+
String[] versionPartitioned = getProject().widgetsVersionName.split("\\.")
103+
104+
switch (this.versionUpdateType) {
105+
case "patch":
106+
int updatedPatchVersion = versionPartitioned[2].toInteger() + 1
107+
versionPartitioned[2] = updatedPatchVersion.toString()
108+
break;
109+
110+
case "minor":
111+
int updatedMinorVersion = versionPartitioned[1].toInteger() + 1
112+
versionPartitioned[1] = updatedMinorVersion.toString()
113+
versionPartitioned[2] = "0"
114+
break;
115+
116+
case "major":
117+
int updatedMajorVersion = versionPartitioned[0].toInteger() + 1
118+
versionPartitioned[0] = updatedMajorVersion.toString()
119+
versionPartitioned[1] = "0"
120+
versionPartitioned[2] = "0"
121+
break;
122+
123+
default:
124+
throw new Exception("Invalid version update type '$this.versionUpdateType'")
125+
}
126+
127+
String newVersionName = String.join(".", versionPartitioned)
128+
129+
return newVersionName
130+
}
100131
}
101132

102133
tasks.register('saveCoreSdkVersion', UpdateCoreSdkVersion)
103-
tasks.register('saveWidgetsVersionName', UpdateProjectVersion)
134+
tasks.register('saveWidgetsVersion', UpdateProjectVersion)
104135

105136
/**
106137
* This task is used by Bitrise release flow to dynamically increment the current Widgets SDK version

0 commit comments

Comments
 (0)