Use current time as build time for preview builds (mihonapp/mihon#1876)
(cherry picked from commit 935f1fcf3f8e4f9da4774d932b65ae77b44cc773)
This commit is contained in:
parent
0df53a5125
commit
bc9843e637
2 changed files with 9 additions and 2 deletions
|
|
@ -30,7 +30,7 @@ android {
|
||||||
|
|
||||||
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
|
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
|
||||||
buildConfigField("String", "COMMIT_SHA", "\"${getGitSha()}\"")
|
buildConfigField("String", "COMMIT_SHA", "\"${getGitSha()}\"")
|
||||||
buildConfigField("String", "BUILD_TIME", "\"${getBuildTime()}\"")
|
buildConfigField("String", "BUILD_TIME", "\"${getBuildTime(useLastCommitTime = false)}\"")
|
||||||
buildConfigField("boolean", "TELEMETRY_INCLUDED", "${Config.includeTelemetry}")
|
buildConfigField("boolean", "TELEMETRY_INCLUDED", "${Config.includeTelemetry}")
|
||||||
buildConfigField("boolean", "UPDATER_ENABLED", "${Config.enableUpdater}")
|
buildConfigField("boolean", "UPDATER_ENABLED", "${Config.enableUpdater}")
|
||||||
|
|
||||||
|
|
@ -79,6 +79,8 @@ android {
|
||||||
signingConfig = debug.signingConfig
|
signingConfig = debug.signingConfig
|
||||||
|
|
||||||
matchingFallbacks.addAll(commonMatchingFallbacks)
|
matchingFallbacks.addAll(commonMatchingFallbacks)
|
||||||
|
|
||||||
|
buildConfigField("String", "BUILD_TIME", "\"${getBuildTime(useLastCommitTime = false)}\"")
|
||||||
}
|
}
|
||||||
create("benchmark") {
|
create("benchmark") {
|
||||||
initWith(release)
|
initWith(release)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,12 @@ fun Project.getGitSha(): String {
|
||||||
|
|
||||||
private val BUILD_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
private val BUILD_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
||||||
|
|
||||||
fun Project.getBuildTime(useLastCommitTime: Boolean = false): String {
|
/**
|
||||||
|
* @param useLastCommitTime If `true`, the build time is based on the timestamp of the last Git commit;
|
||||||
|
* otherwise, the current time is used. Both are in UTC.
|
||||||
|
* @return A formatted string representing the build time. The format used is defined by [BUILD_TIME_FORMATTER].
|
||||||
|
*/
|
||||||
|
fun Project.getBuildTime(useLastCommitTime: Boolean): String {
|
||||||
return if (useLastCommitTime) {
|
return if (useLastCommitTime) {
|
||||||
val epoch = runCommand("git log -1 --format=%ct").toLong()
|
val epoch = runCommand("git log -1 --format=%ct").toLong()
|
||||||
Instant.ofEpochSecond(epoch).atOffset(ZoneOffset.UTC).format(BUILD_TIME_FORMATTER)
|
Instant.ofEpochSecond(epoch).atOffset(ZoneOffset.UTC).format(BUILD_TIME_FORMATTER)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue