Skip to content

Commit

Permalink
chore: make preview workflow create pre-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Aug 2, 2024
1 parent 0dcfd63 commit a7497ec
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 9 deletions.
78 changes: 71 additions & 7 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: Preview
name: Build preview

on: [workflow_dispatch]
permissions:
contents: write

on:
workflow_dispatch:
inputs:
dry-run:
description: Creates a draft release
required: false

jobs:
build:
Expand All @@ -20,12 +28,68 @@ jobs:
- name: Make gradlew executable
run: chmod +x ./gradlew

- name: Decode Keystore
id: decode_keystore
uses: timheuer/base64-to-file@v1
with:
fileName: 'keystore.jks'
encodedString: ${{ secrets.SIGNING_KEYSTORE }}

- name: Build with Gradle
run: ./gradlew assemblePreview

- name: Upload the APK artifact
uses: actions/upload-artifact@v4
- name: Sign apk
uses: r0adkll/sign-android-release@v1
with:
path: ./app/build/outputs/apk/preview/*.apk
name: packages
retention-days: 14
releaseDirectory: app/build/outputs/apk/preview
signingKeyBase64: ${{ secrets.SIGNING_KEYSTORE }}
alias: ${{ secrets.SIGNING_KEY_ALIAS }}
keyStorePassword: ${{ secrets.SINGING_STORE_PASSWORD }}
keyPassword: ${{ secrets.KEY_PASSWORD }}
env:
BUILD_TOOLS_VERSION: "34.0.0"

- name: Prepare release
run: |
set -e
echo "COMMIT_COUNT=$(git rev-list --count HEAD)" >> $GITHUB_ENV
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- 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/preview/app-{}-preview-signed.apk mpvKt-{}-r${{ env.COMMIT_COUNT }}.apk
sha=$(sha256sum mpvKt-{}-r${{ env.COMMIT_COUNT }}.apk | awk '\''{ print $1 }'\'')
echo "apk-{}-sha256=$sha" >> $GITHUB_ENV'
- name: Create release
uses: softprops/action-gh-release@v1
with:
tag_name: r${{ env.COMMIT_COUNT }}
name: mpvKt Preview r${{ env.COMMIT_COUNT }}
body: |
### Checksums
| Variant | SHA-256 |
| ------- | ------- |
| Universal | ${{ env.APK_UNIVERSAL_SHA }}
| arm64-v8a | ${{ env.APK_ARM64_V8A_SHA }}
| armeabi-v7a | ${{ env.APK_ARMEABI_V7A_SHA }}
| x86 | ${{ env.APK_X86_SHA }}
| x86_64 | ${{ env.APK_X86_64_SHA }} |
files: |
mpvKt-r${{ env.COMMIT_COUNT }}.apk
mpvKt-arm64-v8a-r${{ env.COMMIT_COUNT }}.apk
mpvKt-armeabi-v7a-r${{ env.COMMIT_COUNT }}.apk
mpvKt-x86-r${{ env.COMMIT_COUNT }}.apk
mpvKt-x86_64-r${{ env.COMMIT_COUNT }}.apk
draft: ${{ github.event.inputs.dry-run != '' }}
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 18 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.apache.commons.io.output.ByteArrayOutputStream
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
Expand All @@ -21,7 +22,7 @@ android {
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionName = "0.1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -34,6 +35,9 @@ android {
"BUILD_TIME",
"\"${LocalDateTime.now(ZoneOffset.UTC).format(dateTimeFormatter)}\"",
)

buildConfigField("String", "GIT_SHA", getCommitSha())
buildConfigField("String", "GIT_COUNT", getCommitCount())
}
splits {
abi {
Expand All @@ -58,9 +62,11 @@ android {

signingConfig = signingConfigs["debug"]
applicationIdSuffix = ".preview"
versionNameSuffix = "-${getCommitCount()}"
}
named("debug") {
applicationIdSuffix = ".debug"
versionNameSuffix = "-${getCommitCount()}"
}
}
compileOptions {
Expand Down Expand Up @@ -153,3 +159,14 @@ tasks.withType<Detekt>().configureEach {
md.required.set(true)
}
}

fun getCommitCount(): String = runCommand("git rev-list --count HEAD")
fun getCommitSha(): String = runCommand("git rev-parse --short HEAD")
fun runCommand(command: String): String {
val stdOut = ByteArrayOutputStream()
exec {
commandLine = command.split(' ')
standardOutput = stdOut
}
return String(stdOut.toByteArray()).trim()
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CrashActivity : ComponentActivity() {

private fun createLogs(): String {
return """
App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.BUILD_TIME})
App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.GIT_SHA}/${BuildConfig.BUILD_TIME})
Android version: ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT})
Device brand: ${Build.BRAND}
Device manufacturer: ${Build.MANUFACTURER}
Expand Down

0 comments on commit a7497ec

Please sign in to comment.