Skip to content

Commit

Permalink
Use build distribution (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
chromy authored Oct 22, 2024
1 parent eb9a26c commit 2574824
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 40 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/android_emerge_upload.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Emerge Android size analysis
name: Emerge Android Size & Distribution

on:
push:
Expand All @@ -17,17 +17,13 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
- name: Emerge size analysis
- name: Emerge analysis
run: ./gradlew :app:emergeUploadReleaseAab
env:
EMERGE_API_TOKEN: ${{ secrets.EMERGE_API_KEY }}
ANDROID_DISTRIBUTION_API_KEY: ${{ secrets.ANDROID_DISTRIBUTION_API_KEY}}
PR_SHA: ${{ github.event.pull_request.head.sha }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
55 changes: 23 additions & 32 deletions .github/workflows/android_release_build.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
name: Android Release Build

on:
push:
branches: [ main ]
tags: [ '*' ]
pull_request:
branches: [ main ]
paths: [ android/** ]
release:
types: [ published ]

Expand All @@ -28,71 +22,68 @@ jobs:
java-version: '17'
distribution: 'adopt'

- name: Install Bundletool
run: |
wget https://github.com/google/bundletool/releases/download/1.17.0/bundletool-all-1.17.0.jar -O /usr/local/bin/bundletool.jar
- name: Decode Keystore
env:
ENCODED_KEYSTORE: ${{ secrets.ANDROID_RELEASE_KEYSTORE_BASE64 }}
DECODED_KEYSTORE_PATH: ${{ secrets.ANDROID_RELEASE_KEYSTORE_PATH }}
run: |
echo $ENCODED_KEYSTORE > keystore_base64.txt
base64 -d keystore_base64.txt > ./app/$DECODED_KEYSTORE_PATH
base64 -d keystore_base64.txt > ${{ runner.temp }}/keystore.jks
- name: Build AAB
env:
RUNNING_ENV: release_workflow
DECODED_KEYSTORE_PATH: ${{ secrets.ANDROID_RELEASE_KEYSTORE_PATH }}
DECODED_KEYSTORE_PATH: ${{ runner.temp }}/keystore.jks
RELEASE_KEY_ALIAS: ${{ secrets.ANDROID_RELEASE_KEY_ALIAS }}
RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
RELEASE_STORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
EMERGE_API_TOKEN: ${{ secrets.EMERGE_API_KEY }}
REAPER_API_KEY: ${{ secrets.REAPER_API_KEY }}
ANDROID_DISTRIBUTION_API_KEY: ${{ secrets.ANDROID_DISTRIBUTION_API_KEY}}
ANDROID_DISTRIBUTION_API_KEY: ${{ secrets.ANDROID_DISTRIBUTION_API_KEY }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: ./gradlew :app:bundleRelease

- name: Debug path issues
run: find .

- name: Convert AAB to APK
uses: mukeshsolanki/bundletool-action@v1.0.2
with:
aabFile: android/app/build/outputs/bundle/release/app-release.aab
base64Keystore: ${{ secrets.ANDROID_RELEASE_KEYSTORE_BASE64 }}
keystoreAlias: ${{ secrets.ANDROID_RELEASE_KEY_ALIAS }}
keyPassword: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
keystorePassword: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
bundletoolVersion: '1.9.0'
run: |
java -jar /usr/local/bin/bundletool.jar build-apks \
--mode=universal \
--bundle=./app/build/outputs/bundle/release/app-release.aab \
--output=${{ runner.temp }}/app-release.apks \
--ks=${{ runner.temp }}/keystore.jks \
--ks-pass=pass:${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }} \
--ks-key-alias=${{ secrets.ANDROID_RELEASE_KEY_ALIAS }} \
--key-pass=pass:${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
unzip ${{ runner.temp }}/app-release.apks -d ${{ runner.temp }}/apks
- uses: actions/upload-artifact@v3
- name: Upload .apk
uses: actions/upload-artifact@v4
with:
name: release-apk
path: ${{ steps.convert_aab.outputs.apkPath }}

# All the below should only run if we are doing a release.
path: ${{ runner.temp }}/apks/universal.apk
name: hackernews-universal-${{github.sha}}.apk
if-no-files-found: error

- name: Add APK to GitHub release
uses: softprops/action-gh-release@v2
if: ${{ startsWith(github.event.release.tag_name, 'android-') }}
with:
name: ${{ github.ref_name }}
fail_on_unmatched_files: true
# see https://github.com/softprops/action-gh-release/issues/158
files: |
${{ steps.convert_aab.outputs.apkPath }}
${{ runner.temp }}/apks/universal.apk
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
if: ${{ startsWith(github.event.release.tag_name, 'android-') }}
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-1

- name: Extract version from tag
if: ${{ startsWith(github.event.release.tag_name, 'android-') }}
run: echo "VERSION_NAME=$(echo ${{ github.event.release.tag_name }} | sed 's/android-//')" >> $GITHUB_ENV

- name: Upload AAB to S3
if: ${{ startsWith(github.event.release.tag_name, 'android-') }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
12 changes: 10 additions & 2 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ android {
versionCode = 10
versionName = "1.0.1"

manifestPlaceholders["emerge.distribution.apiKey"] = ""

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
Expand Down Expand Up @@ -55,8 +57,13 @@ android {
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
)
val signingConfigName = if (runningEnv == "release_workflow") "release" else "debug"
signingConfig = signingConfigs.getByName(signingConfigName)
if (runningEnv == "release_workflow") {
manifestPlaceholders["emerge.distribution.apiKey"] = ""
signingConfig = signingConfigs.getByName("release")
} else {
manifestPlaceholders["emerge.distribution.apiKey"] = System.getenv("ANDROID_DISTRIBUTION_API_KEY") ?: ""
signingConfig = signingConfigs.getByName("debug")
}
}
}
buildFeatures {
Expand Down Expand Up @@ -151,4 +158,5 @@ dependencies {
debugImplementation(libs.androidx.ui.test.manifest)

implementation(libs.emerge.reaper)
implementation(libs.emerge.distribution)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.emergetools.hackernews.features.settings

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -23,11 +25,20 @@ import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat.startActivity
import com.emergetools.distribution.Distribution
import com.emergetools.distribution.UpdateStatus
import com.emergetools.hackernews.R
import com.emergetools.hackernews.features.settings.components.BuiltByCard
import com.emergetools.hackernews.features.settings.components.LoginCard
Expand All @@ -40,6 +51,7 @@ import com.emergetools.hackernews.ui.theme.HackerNewsTheme
import com.emergetools.hackernews.ui.theme.HackerOrange
import com.emergetools.hackernews.ui.theme.HackerRed
import com.emergetools.snapshots.annotations.EmergeAppStoreSnapshot
import kotlinx.coroutines.launch

@Composable
fun SettingsScreen(
Expand Down Expand Up @@ -79,6 +91,11 @@ fun SettingsScreen(
}
)
Spacer(modifier = Modifier.height(8.dp))
if (Distribution.isEnabled(LocalContext.current)) {
SettingsSectionLabel("Version")
VersionCard()
Spacer(modifier = Modifier.height(8.dp))
}
SettingsSectionLabel("About")
BuiltByCard {
navigation(SettingsNavigation.GoToSettingsLink("https://www.emergetools.com"))
Expand Down Expand Up @@ -171,6 +188,52 @@ fun SettingsScreen(
}
}

@Composable
private fun VersionCard() {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var isLoading by remember { mutableStateOf(false) }
var status by remember { mutableStateOf<UpdateStatus?>(null) }
return SettingsCard(
leadingIcon = {
Icon(
modifier = Modifier.width(12.dp),
painter = painterResource(R.drawable.ic_settings),
contentDescription = null // Purely decorative
)
},
trailingIcon = {
Icon(
modifier = Modifier.width(12.dp),
painter = painterResource(R.drawable.ic_arrow_up_right),
tint = MaterialTheme.colorScheme.onSurface,
contentDescription = "Link"
)
},
label = when (isLoading) {
true -> "Loading..."
else -> when (status) {
is UpdateStatus.UpToDate -> "Up to date!"
is UpdateStatus.Error -> (status as UpdateStatus.Error).message
is UpdateStatus.NewRelease -> "New release!"
else -> "Check for updates"
}
}
) {
scope.launch {
isLoading = true
status = null
status = Distribution.checkForUpdate(context)
val theStatus = status
if (theStatus is UpdateStatus.NewRelease) {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(theStatus.info.downloadUrl))
context.startActivity(browserIntent)
}
isLoading = false
}
}
}

@OptIn(EmergeAppStoreSnapshot::class)
@SnapshotPreview
@AppStoreSnapshot
Expand Down
2 changes: 2 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ browser = "1.8.0"
emergePlugin = "4.0.1"
emergeSnapshots = "1.2.0"
emergeReaper = "1.0.0-rc02"
emergeDistribution = "0.0.1"
sentry = "4.11.0"
shapes = "1.0.1"
datastore = "1.1.1"
Expand Down Expand Up @@ -58,6 +59,7 @@ jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoup" }
emerge-snapshots = { group = "com.emergetools.snapshots", name = "snapshots", version.ref = "emergeSnapshots" }
emerge-snapshots-annotations = { group = "com.emergetools.snapshots", name = "snapshots-annotations", version.ref = "emergeSnapshots" }
emerge-reaper = { group = "com.emergetools.reaper", name = "reaper", version.ref = "emergeReaper" }
emerge-distribution = { group = "com.emergetools.distribution", name = "distribution", version.ref = "emergeDistribution" }

junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
Expand Down

0 comments on commit 2574824

Please sign in to comment.