From c62aaab0f37a163bcdc5f8dae7e975e21fdefd61 Mon Sep 17 00:00:00 2001 From: AbdallahMehiz Date: Sat, 31 Aug 2024 03:53:38 +0100 Subject: [PATCH] refactor: implement timestamps metadata in release for fdroid --- .github/workflows/release.yml | 14 ++++++++++++-- app/build.gradle.kts | 24 ++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c930a6..7203655 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 @@ -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 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 06385fa..15351d9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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) @@ -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()}\"") @@ -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) +}