@@ -72,35 +72,66 @@ class UpdateCoreSdkVersion extends DefaultTask {
72
72
/**
73
73
* A task class for editing the Widget SDK version in version.properties
74
74
* Example of usage from terminal:
75
- * ./gradlew saveWidgetsVersionName --versionCode=77 --versionName=0.77.2
75
+ * ./gradlew saveWidgetsVersion --type=patch
76
76
*/
77
77
class UpdateProjectVersion extends DefaultTask {
78
- private String versionName
79
- private String versionCode
78
+ private String versionUpdateType
80
79
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
90
83
return this
91
84
}
92
85
93
86
@TaskAction
94
87
void write () {
95
88
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() )
98
91
getProject(). saveProperties(propertiesMap)
99
92
}
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
+ }
100
131
}
101
132
102
133
tasks. register(' saveCoreSdkVersion' , UpdateCoreSdkVersion )
103
- tasks. register(' saveWidgetsVersionName ' , UpdateProjectVersion )
134
+ tasks. register(' saveWidgetsVersion ' , UpdateProjectVersion )
104
135
105
136
/**
106
137
* This task is used by Bitrise release flow to dynamically increment the current Widgets SDK version
0 commit comments