From 48d10cc937c22e94b3240ab33ede6b2523752c18 Mon Sep 17 00:00:00 2001
From: Jason Doan <doananhtuan22111996@gmail.com>
Date: Fri, 30 Aug 2024 22:50:54 +0700
Subject: [PATCH] feat: Add github actions

---
 .github/workflows/dev.yml      | 78 ++++++++++++++++++++++++++++++++++
 .github/workflows/notifier.yml | 24 +++++++++++
 app/pubspec.yaml               |  2 +-
 app/web/index.html             |  6 +++
 makefile                       | 26 +++++++++++-
 5 files changed, 134 insertions(+), 2 deletions(-)
 create mode 100644 .github/workflows/dev.yml
 create mode 100644 .github/workflows/notifier.yml

diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml
new file mode 100644
index 0000000..fb04246
--- /dev/null
+++ b/.github/workflows/dev.yml
@@ -0,0 +1,78 @@
+name: Dev CI
+
+on:
+  push:
+    branches: [ "main" ]
+  pull_request:
+    branches: [ "main" ]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+        # Note: This workflow uses the latest stable version of the Dart SDK.
+        # You can specify other versions if desired, see documentation here:
+        # https://github.com/dart-lang/setup-dart/blob/main/README.md
+        # - uses: dart-lang/setup-dart@v1
+      - uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603
+
+      - name: Set up JDK 17
+        uses: actions/setup-java@v3
+        with:
+          java-version: '17'
+          distribution: 'temurin'
+          cache: gradle
+
+      - name: Setup project
+        run: |
+          echo "Accept permision..."
+          make denied
+          echo "Install bootstrap..."
+          make pre-bootstrap
+          echo "Pub get..."
+          make gh-pub-get
+
+      - name: Download keystore
+        uses: timheuer/base64-to-file@v1.2
+        with:
+          fileName: 'root-keystore-dev.jks'
+          fileDir: './app/android/'
+          encodedString: ${{ secrets.ROOT_KEYSTORE_DEV }}
+
+      - name: Download env
+        uses: timheuer/base64-to-file@v1.2
+        with:
+          fileName: '.env.zip'
+          fileDir: './configs/'
+          encodedString: ${{ secrets.ENV }}
+        run: |
+          cd configs && jar xf .env.zip
+
+      - name: Build Release apk
+        run: make gh-build-android-apk flavor=dev
+
+      - name: Build Release bundle
+        run: make gh-build-android-aab flavor=dev
+
+      - name: Get release file aab path
+        id: releaseAab
+        run: echo "aabfile=$(find app/build/app/outputs/flutter-apk/app-dev-release.aab)" >> $GITHUB_OUTPUT
+
+      - name: Get release file apk path
+        id: releaseApk
+        run: echo "apkfile=$(find app/build/app/outputs/flutter-apk/app-dev-release.apk)" >> $GITHUB_OUTPUT
+
+      - name: Zip Files
+        uses: papeloto/action-zip@v1
+        with:
+          files: ${{ steps.releaseAab.outputs.aabfile }} ${{ steps.releaseApk.outputs.apkfile }}
+          dest: app-dev-release.zip
+
+      - name: Sending release build to Telegram
+        uses: appleboy/telegram-action@master
+        with:
+          to: ${{ secrets.TELEGRAM_TO }}
+          token: ${{ secrets.TELEGRAM_TOKEN }}
+          document: app-dev-release.zip
+          message: 🚀 New Release Published on DEV! >>> ${{github.head_ref}}.
\ No newline at end of file
diff --git a/.github/workflows/notifier.yml b/.github/workflows/notifier.yml
new file mode 100644
index 0000000..9c4f467
--- /dev/null
+++ b/.github/workflows/notifier.yml
@@ -0,0 +1,24 @@
+name: Notifier
+
+on:
+  push:
+    branches: [ "main" ]
+  pull_request:
+    branches: [ "main" ]
+
+jobs:
+  build:
+    name: Sent telegram message
+    runs-on: ubuntu-latest
+    steps:
+      - name: send telegram message on push
+        uses: appleboy/telegram-action@master
+        with:
+          to: ${{ secrets.TELEGRAM_TO }}
+          token: ${{ secrets.TELEGRAM_TOKEN }}
+          message: |
+            ${{ github.actor }} created commit:
+            Branch: ${{github.head_ref}}
+            Commit message: ${{ github.event.commits[0].message }}
+            Repository: ${{ github.repository }}
+            See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}
\ No newline at end of file
diff --git a/app/pubspec.yaml b/app/pubspec.yaml
index e507919..ab62e78 100644
--- a/app/pubspec.yaml
+++ b/app/pubspec.yaml
@@ -80,7 +80,7 @@ dev_dependencies:
   # rules and activating additional ones.
   flutter_lints: 4.0.0
   build_runner: 2.4.11
-  flutter_gen_runner: 5.6.0
+#  flutter_gen_runner: 5.6.0
 
   #flutter_gen:
   #  assets:
diff --git a/app/web/index.html b/app/web/index.html
index 5af3ac3..907d843 100644
--- a/app/web/index.html
+++ b/app/web/index.html
@@ -86,6 +86,10 @@
   
   
   
+  
+  
+  
+  
   
   
   
@@ -185,6 +189,8 @@
   
   
   
+  
+  
   
   
   
diff --git a/makefile b/makefile
index 6ce4b47..515dc30 100644
--- a/makefile
+++ b/makefile
@@ -3,7 +3,7 @@ denied:
 	cd scripts && chmod +x pre-bootstrap.sh
 
 pre-bootstrap:
-	cd scripts && ./pre-bootstrap.sh
+	cd scripts && sh pre-bootstrap.sh
 	fvm install 3.22.3
 	fvm use 3.22.3 --force
 	fvm flutter --version
@@ -40,3 +40,27 @@ build-android-aab:
 
 create-env:
 	@melos create-env
+
+############################################ Github Action #########################################
+
+gh-pub-get:
+	fvm flutter pub global run melos clean --sdk-path=.fvm/flutter_sdk
+	fvm flutter pub global run melos bootstrap --sdk-path=.fvm/flutter_sdk
+	fvm flutter pub global run melos gen-app-icon
+	fvm flutter pub global run melos gen-app-splash
+	fvm flutter pub global run melos build-domain
+	fvm flutter pub global run melos build-data
+	fvm flutter pub global run melos build-resources
+	fvm flutter pub global run melos gen-strings
+
+gh-build-ios:
+	fvm flutter pub global run melos gen-env $(flavor)
+	dart run scripts/build_app.dart $(flavor) ipa $(buildName) $(buildNumber)
+
+gh-build-android-apk:
+	fvm flutter pub global run melos gen-env $(flavor)
+	dart run scripts/build_app.dart $(flavor) apk $(buildName) $(buildNumber)
+
+gh-build-android-aab:
+	fvm flutter pub global run melos gen-env $(flavor)
+	dart run scripts/build_app.dart $(flavor) aab $(buildName) $(buildNumber)