diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index e61c89f..2305e69 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -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: @@ -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 \ No newline at end of file + 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 }} \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 533e073..d2404dd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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 @@ -21,7 +22,7 @@ android { minSdk = 21 targetSdk = 34 versionCode = 1 - versionName = "1.0" + versionName = "0.1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { @@ -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 { @@ -58,9 +62,11 @@ android { signingConfig = signingConfigs["debug"] applicationIdSuffix = ".preview" + versionNameSuffix = "-${getCommitCount()}" } named("debug") { applicationIdSuffix = ".debug" + versionNameSuffix = "-${getCommitCount()}" } } compileOptions { @@ -153,3 +159,14 @@ tasks.withType().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() +} diff --git a/app/src/main/java/live/mehiz/mpvkt/presentation/crash/CrashActivity.kt b/app/src/main/java/live/mehiz/mpvkt/presentation/crash/CrashActivity.kt index 49fd6f9..5811c4e 100644 --- a/app/src/main/java/live/mehiz/mpvkt/presentation/crash/CrashActivity.kt +++ b/app/src/main/java/live/mehiz/mpvkt/presentation/crash/CrashActivity.kt @@ -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}