Repository navigation
feat: Add version code and version name as a config - #507
farhaanbukhsh wants to merge 5 commits into
Conversation
Signed-off-by: Farhaan Bukhsh <farhaan@opencraft.com>
|
Thanks for the pull request, @farhaanbukhsh! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
| def appVersionCode = config.getOrDefault("VERSION_CODE", 1)?.toString() | ||
| def appVersionName = config.getOrDefault("VERSION_NAME", "1.0.0") | ||
|
|
||
| if (!(appVersionCode ==~ /[0-9]+/) || !appVersionCode.isInteger() || | ||
| appVersionCode.toInteger() < 1 || appVersionCode.toInteger() > 2100000000) { | ||
| throw new GradleException("VERSION_CODE must be an integer between 1 and 2100000000 in the YAML config.") | ||
| } |
There was a problem hiding this comment.
@farhaanbukhsh I am very confused here. Why are we converting VERSION_CODE to string, compare against a regex, check !isInt, to cast toInt and then validate the range?
Why can't we simply do?
def appVersionCode = config.getOrDefault("VERSION_CODE", 1)
if (!appVersionCode.isInteger() || appVersion < 1 || appVersion > 2100000000) {
throw...
}
Is it something with the way Gradle parses the YAML? Does it not preserve integers?
There was a problem hiding this comment.
The regex change came from the fact that it's possible people inter change version_code and version_name, hence I wanted to catch it at the right place and through an error which can be traced. But now that I think of it the regex check looks redundant.
There was a problem hiding this comment.
Ah! I see. I think just reducing it to the following should be sufficient. If by mistake the VERSION_CODE is set to a string like "1.0.0", the isInteger() check should be sufficient to catch it.
def appVersionCode = config.getOrDefault("VERSION_CODE", 1)
if (!appVersionCode.isInteger() || appVersion < 1 || appVersion > 2100000000)
Since this will catch it, we can drop the appVersionCode.toInteger() to just appVersionCode as well.
| targetSdk target_sdk_version | ||
| versionCode 1 | ||
| versionName "1.0.0" | ||
| versionCode appVersionCode.toInteger() |
There was a problem hiding this comment.
Related to above comment, why do we need to keep it as a string and cast to int every time we need this value?
There was a problem hiding this comment.
This in my mind is more of a safety check.
| def appVersionCode = config.getOrDefault("VERSION_CODE", 1)?.toString() | ||
| def appVersionName = config.getOrDefault("VERSION_NAME", "1.0.0") | ||
|
|
||
| if (!(appVersionCode ==~ /[0-9]+/) || !appVersionCode.isInteger() || | ||
| appVersionCode.toInteger() < 1 || appVersionCode.toInteger() > 2100000000) { |
There was a problem hiding this comment.
| def appVersionCode = config.getOrDefault("VERSION_CODE", 1)?.toString() | |
| def appVersionName = config.getOrDefault("VERSION_NAME", "1.0.0") | |
| if (!(appVersionCode ==~ /[0-9]+/) || !appVersionCode.isInteger() || | |
| appVersionCode.toInteger() < 1 || appVersionCode.toInteger() > 2100000000) { | |
| def appVersionCode = config.getOrDefault("VERSION_CODE", 1) | |
| def appVersionName = config.getOrDefault("VERSION_NAME", "1.0.0") | |
| if (!appVersionCode.isInteger() || appVersionCode < 1 || appVersionCode > 2100000000) { |
There was a problem hiding this comment.
!appVersionCode.isInteger() this wouldn't be needed if we don't convert it to string.
| targetSdk target_sdk_version | ||
| versionCode 1 | ||
| versionName "1.0.0" | ||
| versionCode appVersionCode.toInteger() |
There was a problem hiding this comment.
| versionCode appVersionCode.toInteger() | |
| versionCode appVersionCode |
| def appVersionCode = config.getOrDefault("VERSION_CODE", 1) | ||
| def appVersionName = config.getOrDefault("VERSION_NAME", "1.0.0") | ||
|
|
||
| if (appVersionCode.toInteger() < 1 || appVersionCode.toInteger() > 2100000000) { |
There was a problem hiding this comment.
@farhaanbukhsh I am really sorry for being pedantic about this. Can we have either:
toInteger()be at thedef appVersionCodeOR- fail the
ifcheck whenappVersionCodeis not an integer
Because, currently, this line treats it as a string and the rest of the file treats it as an Int. It would be best to make it consistent.
There was a problem hiding this comment.
I have removed toInteger() from the codebase since the getOrDefault can infer the type, the intention of toInteger was to just put an additional check on the data type.
| VERSION_NAME: '1.0.1' | ||
| ``` | ||
|
|
||
| - `VERSION_CODE` sets Android's `versionCode`. It must be an integer from `1` to `2100000000`; invalid values fail during Gradle configuration. Integer values and quoted integer strings are supported. |
There was a problem hiding this comment.
| - `VERSION_CODE` sets Android's `versionCode`. It must be an integer from `1` to `2100000000`; invalid values fail during Gradle configuration. Integer values and quoted integer strings are supported. | |
| - `VERSION_CODE` sets Android's `versionCode`. It must be an integer from `1` to `2100000000`; invalid values fail during Gradle configuration. |
tecoholic
left a comment
There was a problem hiding this comment.
@farhaanbukhsh LGTM. 👍
Unfortunately, I didn't test this and I don't have the full Android SDK setup of a phone to properly test this.
kaustavb12
left a comment
There was a problem hiding this comment.
👍
- I tested this: As described in the testing instructions
- I read through the code
- I checked for accessibility issues
- Includes documentation
|
@PavloNetrebchuk @volodymyr-chekyrta gentle ping for review here :) thank you in advance. |
Description
The PR helps to configure the version code and version name through config files since releasing the app always changing the code is cumbersome while doing that with a config variables makes life easier.
Testing instructions
Private Ref: https://tasks.opencraft.com/browse/BB-10453