Skip to content

Commit

Permalink
chore(fdroid): add build-metadata.json containing build timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Aug 31, 2024
1 parent 8170fee commit 0048b64
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Build

on: [push]
on:
push:
branches:
- main

jobs:
build:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/nightlies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ permissions:
on:
workflow_dispatch:
push:
branches:
- main

jobs:
build:
Expand Down Expand Up @@ -48,7 +50,7 @@ jobs:
declare -a apks=("universal" "arm64-v8a" "armeabi-v7a" "x86" "x86_64")
printf "%s\n" "${apks[@]}" | xargs -n 1 -I {} sh -c '
cp app/build/outputs/apk/preview/app-{}-preview-signed.apk mpvKt-{}-r${{ env.COMMIT_COUNT }}.apk'
cp app/build/outputs/apk/preview/app-{}-preview-signed.apk mpvKt-{}.apk'
- name: Upload the universal artifact
uses: actions/upload-artifact@v4
Expand Down
29 changes: 13 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
name: Make release

permissions:
contents: write

on:
push:
tags:
- v*

jobs:
release-for-github:
name: "Release for GitHub and F-Droid"
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup JDK 17
uses: actions/setup-java@v4
with:
Expand All @@ -25,16 +19,22 @@ jobs:

- 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

- name: Get tag ame
if: startsWith(github.ref, 'refs/tags/')
run: |
set -x
echo "VERSION_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Sign apk
uses: r0adkll/sign-android-release@v1
with:
Expand All @@ -45,28 +45,24 @@ jobs:
keyPassword: ${{ secrets.KEY_PASSWORD }}
env:
BUILD_TOOLS_VERSION: "34.0.0"

- name: Copy build artifacts
run: |
set -e
declare -a apks=("universal" "arm64-v8a" "armeabi-v7a" "x86" "x86_64")
printf "%s\n" "${apks[@]}" | xargs -n 1 -I {} sh -c '
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": ${{ env.BUILD_TIMESTAMP }}}' | jq >> build-metadata.json
- name: Create release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.VERSION_TAG }}
name: mpvKt ${{ env.VERSION_TAG }}
body: |
---
### Checksums
| Variant | SHA-256 |
| ------- | ------- |
| arm64-v8a | ${{ env.apk-arm64-v8a-sha256 }}
Expand All @@ -75,6 +71,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 All @@ -83,4 +80,4 @@ jobs:
prerelease: false
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}}
9 changes: 7 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.apache.commons.io.output.ByteArrayOutputStream
import java.time.LocalDateTime
import java.time.Instant
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

Expand Down Expand Up @@ -29,11 +29,16 @@ android {
useSupportLibrary = true
}

val timestamp: Long = if (project.hasProperty("timestamp")) {
project.properties["timestamp"].toString().toLong()
} else {
Instant.now().epochSecond
}
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'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

0 comments on commit 0048b64

Please sign in to comment.