-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
864555a
commit e317f21
Showing
5 changed files
with
107 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ concurrency: | |
|
||
env: | ||
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | ||
CI: true | ||
|
||
jobs: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
plugins { | ||
`kotlin-dsl` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import org.gradle.api.JavaVersion | ||
import org.gradle.api.Project | ||
import java.io.ByteArrayOutputStream | ||
import java.io.File | ||
|
||
object ProjectSettings { | ||
|
||
private const val MAYOR_VERSION = 0 | ||
private const val MINOR_VERSION = 0 | ||
|
||
// git rev-list --first-parent --count origin/master +1 | ||
private const val VERSION_DIF = 0 | ||
private const val BASE_VERSION_CODE = 0 | ||
|
||
const val PROJECT_ID = "com.oztechan.tracefit" | ||
|
||
const val COMPILE_SDK_VERSION = 34 | ||
const val MIN_SDK_VERSION = 24 | ||
const val TARGET_SDK_VERSION = 34 | ||
|
||
val JAVA_VERSION = JavaVersion.VERSION_1_8 | ||
|
||
@Suppress("TooGenericExceptionCaught", "SwallowedException") | ||
fun getVersionCode(project: Project) = try { | ||
gitCommitCount(project).toInt() + BASE_VERSION_CODE | ||
} catch (e: Exception) { | ||
1 | ||
} | ||
|
||
@Suppress("TooGenericExceptionCaught", "SwallowedException") | ||
fun getVersionName( | ||
project: Project | ||
): String = try { | ||
if (isMaster(project)) { | ||
"$MAYOR_VERSION.$MINOR_VERSION.${getVersionCode(project) - VERSION_DIF - BASE_VERSION_CODE}" | ||
} else { | ||
"0.0.${getVersionCode(project)}" // testing build | ||
}.also { | ||
if (isCI()) project.setIOSVersion(it) | ||
} | ||
} catch (e: Exception) { | ||
"0.0.1" | ||
} | ||
|
||
private fun gitCommitCount(project: Project): String { | ||
val os = ByteArrayOutputStream() | ||
project.exec { | ||
commandLine = "git rev-list --first-parent --count HEAD".split(" ") | ||
standardOutput = os | ||
} | ||
return String(os.toByteArray()).trim() | ||
} | ||
|
||
private fun isMaster(project: Project): Boolean { | ||
val os = ByteArrayOutputStream() | ||
project.exec { | ||
commandLine = "git rev-parse --abbrev-ref HEAD".split(" ") | ||
standardOutput = os | ||
} | ||
return String(os.toByteArray()).trim() == "master" | ||
} | ||
|
||
private fun isCI() = System.getenv("CI") == "true" | ||
|
||
@Suppress("TooGenericExceptionCaught") | ||
private fun Project.setIOSVersion(versionName: String) = try { | ||
exec { | ||
workingDir = File("${project.rootDir}/ios") | ||
commandLine = "agvtool new-version -all ${getVersionCode(project)}".split(" ") | ||
} | ||
exec { | ||
workingDir = File("${project.rootDir}/ios") | ||
commandLine = "agvtool new-marketing-version $versionName".split(" ") | ||
} | ||
} catch (e: Exception) { | ||
println("agvtool exist only mac environment") | ||
println(e.localizedMessage) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters