Skip to content

Commit

Permalink
Frontend: Add APK generation workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamsinghshubham777 committed Oct 1, 2024
1 parent 595681a commit 78689df
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Deploy Flutter Web Frontend
name: Deploy Flutter Frontend Apps

on:
push:
branches:
- main
tags:
- 'v*'
paths:
- '.github/workflows/publish_frontend_web.yaml'
- '.github/workflows/publish_frontend.yaml'
- 'core/**'
- 'frontend/**'
workflow_dispatch:
Expand All @@ -20,10 +20,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'

- name: Cache Flutter packages
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.pub-cache
Expand Down Expand Up @@ -60,6 +66,27 @@ jobs:
working-directory: ./frontend
run: flutter pub run build_runner build --delete-conflicting-outputs

- name: Decode Keystore
uses: timheuer/[email protected]
with:
fileName: 'keystore.jks'
fileDir: './frontend/android/app/'
encodedString: ${{ secrets.KEYSTORE_BASE64 }}

- name: Build APK
working-directory: ./frontend
env:
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: flutter build apk --release

- name: Upload APK
uses: actions/upload-artifact@v3
with:
name: release-apk
path: frontend/build/app/outputs/flutter-apk/app-release.apk

- name: Build web app
working-directory: ./frontend
run: flutter build web --dart-define APP_ENV=production --base-href /down_the_aisle/
Expand All @@ -69,3 +96,11 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./frontend/build/web

- name: Create Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: frontend/build/app/outputs/flutter-apk/app-release.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 30 additions & 4 deletions frontend/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,27 @@ plugins {
id "dev.flutter.flutter-gradle-plugin"
}

def getKeyProperty(String propertyName, String defaultValue = null) {
def envValue = System.getenv(propertyName)
if (envValue != null && !envValue.isEmpty()) {
return envValue
}

def keyPropertiesFile = rootProject.file("key.properties")
if (keyPropertiesFile.exists()) {
Properties keyProperties = new Properties()
keyProperties.load(new FileInputStream(keyPropertiesFile))
def propValue = keyProperties[propertyName]
if (propValue != null && !propValue.isEmpty()) {
return propValue
}
}

return defaultValue
}

android {
namespace = "com.example.frontend"
namespace = "app.downtheaisle"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -29,11 +48,18 @@ android {
versionName = flutter.versionName
}

signingConfigs {
release {
keyAlias = getKeyProperty("KEY_ALIAS")
keyPassword = getKeyProperty("KEY_PASSWORD")
storeFile = file(getKeyProperty("STORE_FILE", "keystore.jks"))
storePassword = getKeyProperty("STORE_PASSWORD")
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
signingConfig = signingConfigs.release
}
}
}
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion frontend/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
34 changes: 19 additions & 15 deletions frontend/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:label="Down The Aisle"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/ic_launcher"
android:label="Down The Aisle">
<activity
android:name=".MainActivity"
android:name="app.downtheaisle.MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
tools:ignore="DiscouragedApi,LockedOrientationActivity">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand All @@ -39,8 +43,8 @@
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
<action android:name="android.intent.action.PROCESS_TEXT" />
<data android:mimeType="text/plain" />
</intent>
</queries>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.frontend
package app.downtheaisle

import io.flutter.embedding.android.FlutterActivity

Expand Down
2 changes: 1 addition & 1 deletion frontend/android/app/src/profile/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
4 changes: 3 additions & 1 deletion frontend/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
6 changes: 5 additions & 1 deletion frontend/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ Future<void> main() async {
}

void _setupDesktopWindow() {
if (!kIsWeb) {
final isLinux = defaultTargetPlatform == TargetPlatform.linux;
final isMacOS = defaultTargetPlatform == TargetPlatform.macOS;
final isWindows = defaultTargetPlatform == TargetPlatform.windows;
final isDesktop = !kIsWeb && (isLinux || isMacOS || isWindows);
if (isDesktop) {
windowManager
..ensureInitialized()
..waitUntilReadyToShow(
Expand Down

0 comments on commit 78689df

Please sign in to comment.