Skip to content

Commit

Permalink
Return default values when no tag present
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylwester Zielinski committed Feb 14, 2023
1 parent 75b4e95 commit b0340cd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions fastlane/report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@



<testcase classname="fastlane.lanes" name="0: default_platform" time="0.000156046">
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.000148473">

</testcase>


<testcase classname="fastlane.lanes" name="1: publishToMavenLocal" time="7.550080403">
<testcase classname="fastlane.lanes" name="1: publishToMavenLocal" time="11.531691581">

</testcase>

Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ nordic-dfu = "2.3.0"
nordic-log = "2.3.0"
nordic-mcumgr = "1.5.2"
nordic-scanner = "1.6.0"
nordic-common = "1.4.2"
nordic-common = "1.4.3"
nordic-memfault = "1.0.2"
nordicPlugins = "1.2.2"
nordicPlugins = "1.3.0"
googleServicesPlugins = "4.3.15"
firebaseCrashlyticsPlugins = "4.5.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,22 @@ import java.io.ByteArrayOutputStream
import java.time.ZoneId
import java.time.ZonedDateTime

private const val DEFAULT_CODE = 0
private const val DEFAULT_NAME = "0.0.0"

/**
* This method returns the version code based on the current date (YYMM) and number of git revisions.
* The format is YYMMxxxxx where x is a number of git revisions.
*/
fun Project.getVersionCodeFromTags(): Int {
val code = ByteArrayOutputStream()
exec {
commandLine("git", "rev-list", "--all", "--count")
standardOutput = code
try {
exec {
commandLine("git", "rev-list", "--all", "--count")
standardOutput = code
}
} catch (e: Exception) {
return DEFAULT_CODE
}
val now = ZonedDateTime.now(ZoneId.of("UTC"))
val year = now.year % 100
Expand All @@ -58,9 +65,13 @@ fun Project.getVersionCodeFromTags(): Int {
*/
fun Project.getVersionNameFromTags(): String {
val code = ByteArrayOutputStream()
exec {
commandLine("git", "describe", "--tags", "--abbrev=0")
standardOutput = code
try {
exec {
commandLine("git", "describe", "--tags", "--abbrev=0")
standardOutput = code
}
} catch (e: Exception) {
return DEFAULT_NAME
}
return code.toString().trim().split("%")[0]
}

0 comments on commit b0340cd

Please sign in to comment.