Skip to content

Commit

Permalink
refactor: implement timestamps metadata in release for fdroid
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Aug 31, 2024
1 parent 8170fee commit c62aaab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ jobs:
distribution: 'adopt'
java-version: 17

- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Pre-build
run: |
set -e
timestamp=`date +%s`
echo "timestamp=$timestamp" >> local.properties
echo "BUILD_TIMESTAMP=$timestamp" >> $GITHUB_ENV
chmod +x ./gradlew
- name: Build release with Gradle
run: ./gradlew assembleRelease
Expand Down Expand Up @@ -56,6 +63,8 @@ jobs:
cp app/build/outputs/apk/release/app-{}-release-unsigned-signed.apk mpvKt-{}-${{ env.VERSION_TAG }}.apk
sha=$(sha256sum mpvKt-{}-${{ env.VERSION_TAG }}.apk | awk '\''{ print $1 }'\'')
echo "apk-{}-sha256=$sha" >> $GITHUB_ENV'
echo '{"timestamp": $timestamp}' | jq >> build-metadata.json
- name: Create release
uses: softprops/action-gh-release@v1
Expand All @@ -75,6 +84,7 @@ jobs:
| x86 | ${{ env.apk-x86-sha256 }}
| x86_64 | ${{ env.apk-x86_64-sha256 }} |
files: |
build-metadata.json
mpvKt-universal-${{ env.VERSION_TAG }}.apk
mpvKt-arm64-v8a-${{ env.VERSION_TAG }}.apk
mpvKt-armeabi-v7a-${{ env.VERSION_TAG }}.apk
Expand Down
24 changes: 20 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.apache.commons.io.output.ByteArrayOutputStream
import java.time.LocalDateTime
import java.io.FileInputStream
import java.io.InputStreamReader
import java.time.Instant
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.util.Properties

plugins {
alias(libs.plugins.ksp)
Expand All @@ -28,12 +31,12 @@ android {
vectorDrawables {
useSupportLibrary = true
}

val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
val timestamp: Long = getLocalProperty("timestamp").toLong()
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
buildConfigField(
"String",
"BUILD_TIME",
"\"${LocalDateTime.now(ZoneOffset.UTC).format(dateTimeFormatter)}\"",
"\"${Instant.ofEpochSecond(timestamp).atOffset(ZoneOffset.UTC).format(dateTimeFormatter)}\"",
)

buildConfigField("String", "GIT_SHA", "\"${getCommitSha()}\"")
Expand Down Expand Up @@ -163,3 +166,16 @@ fun runCommand(command: String): String {
}
return String(stdOut.toByteArray()).trim()
}

// https://stackoverflow.com/questions/60474010/read-value-from-local-properties-via-kotlin-dsl
fun getLocalProperty(key: String, file: String = "local.properties"): String {
val properties = Properties()
val localProperties = File(file)
if (localProperties.isFile) {
InputStreamReader(FileInputStream(localProperties), Charsets.UTF_8).use { reader ->
properties.load(reader)
}
} else error("File from not found")

return properties.getProperty(key)
}

0 comments on commit c62aaab

Please sign in to comment.