From c475a5d960c51056e13276b40a59ddbc5890c36a Mon Sep 17 00:00:00 2001
From: Richard Shiue <71320345+richardshiue@users.noreply.github.com>
Date: Fri, 24 Nov 2023 16:20:25 +0800
Subject: [PATCH] ci: use linux vm for dart unit test (#3991)

* chore: use the faster linux vm

* chore: download artifact

* chore: make it work

---------

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
---
 .github/workflows/flutter_ci.yaml      | 66 ++++++++++++++++----------
 frontend/scripts/makefile/flutter.toml | 22 ++++++---
 2 files changed, 56 insertions(+), 32 deletions(-)

diff --git a/.github/workflows/flutter_ci.yaml b/.github/workflows/flutter_ci.yaml
index b64a51a00e..8e15ba9779 100644
--- a/.github/workflows/flutter_ci.yaml
+++ b/.github/workflows/flutter_ci.yaml
@@ -108,18 +108,15 @@ jobs:
 
       - name: Build AppFlowy
         working-directory: frontend
-        run: |
-          cargo make --profile ${{ matrix.flutter_profile }} appflowy-core-dev
+        run: cargo make --profile ${{ matrix.flutter_profile }} appflowy-core-dev
 
       - name: Run code generation
         working-directory: frontend
-        run: |
-          cargo make code_generation
+        run: cargo make code_generation
 
       - name: Flutter Analyzer
         working-directory: frontend/appflowy_flutter
-        run: |
-          flutter analyze .
+        run: flutter analyze .
 
       - name: Compress appflowy_flutter
         run: tar -czf appflowy_flutter.tar.gz frontend/appflowy_flutter
@@ -135,11 +132,11 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        os: [macos-latest]
+        os: [ubuntu-latest]
         include:
-          - os: macos-latest
-            flutter_profile: development-mac-x86_64
-            target: x86_64-apple-darwin
+          - os: ubuntu-latest
+            flutter_profile: development-linux-x86_64
+            target: x86_64-unknown-linux-gnu
     runs-on: ${{ matrix.os }}
 
     steps:
@@ -176,19 +173,45 @@ jobs:
       - name: Install prerequisites
         working-directory: frontend
         run: |
-          if [ "$RUNNER_OS" == "macOS" ]; then
-            cargo make appflowy-flutter-deps-tools
+          if [ "$RUNNER_OS" == "Linux" ]; then
+            sudo wget -qO /etc/apt/trusted.gpg.d/dart_linux_signing_key.asc https://dl-ssl.google.com/linux/linux_signing_key.pub
+            sudo wget -qO /etc/apt/sources.list.d/dart_stable.list https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list
+            sudo apt-get update
+            sudo apt-get install -y dart curl build-essential libssl-dev clang cmake ninja-build pkg-config libgtk-3-dev keybinder-3.0 libnotify-dev
           fi
         shell: bash
 
+      - name: Enable Flutter Desktop
+        run: |
+          if [ "$RUNNER_OS" == "Linux" ]; then
+            flutter config --enable-linux-desktop
+          elif [ "$RUNNER_OS" == "macOS" ]; then
+            flutter config --enable-macos-desktop
+          elif [ "$RUNNER_OS" == "Windows" ]; then
+            git config --system core.longpaths true
+            flutter config --enable-windows-desktop
+          fi
+        shell: bash
+
+      - uses: actions/download-artifact@v3
+        with:
+          name: ${{ github.run_id }}-${{ matrix.os }}
+
+      - name: Uncompress appflowy_flutter
+        run: tar -xf appflowy_flutter.tar.gz
+
+      - name: Run flutter pub get
+        working-directory: frontend
+        run: cargo make pub_get
+
       - name: Run Flutter unit tests
         working-directory: frontend
         run: |
           if [ "$RUNNER_OS" == "macOS" ]; then
-            flutter config --enable-macos-desktop
-            cargo make --profile ${{ matrix.flutter_profile }} appflowy-dev
             cargo make dart_unit_test
-          else
+          elif [ "$RUNNER_OS" == "Linux" ]; then
+            cargo make dart_unit_test_no_build
+          elif [ "$RUNNER_OS" == "Windows" ]; then
             cargo make dart_unit_test_no_build
           fi
         shell: bash
@@ -213,7 +236,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        os: [ubuntu-latest,windows-latest]
+        os: [ubuntu-latest, windows-latest]
         include:
           - os: ubuntu-latest
             flutter_profile: development-linux-x86_64
@@ -277,10 +300,9 @@ jobs:
       - name: Uncompress appflowy_flutter
         run: tar -xf appflowy_flutter.tar.gz
 
-      - name: Run code generation
+      - name: Run flutter pub get
         working-directory: frontend
-        run: |
-          cargo make code_generation
+        run: cargo make pub_get
 
       - name: Run Flutter integration tests
         working-directory: frontend/appflowy_flutter
@@ -384,12 +406,6 @@ jobs:
       - name: Uncompress appflowy_flutter
         run: tar -xf appflowy_flutter.tar.gz
 
-      - name: Run code generation
-        if: matrix.os == 'windows-latest'
-        working-directory: frontend
-        run: |
-          cargo make code_generation
-
       - name: Build flutter product
         working-directory: frontend
         run: |
diff --git a/frontend/scripts/makefile/flutter.toml b/frontend/scripts/makefile/flutter.toml
index df57636baf..3ccac1f58f 100644
--- a/frontend/scripts/makefile/flutter.toml
+++ b/frontend/scripts/makefile/flutter.toml
@@ -263,25 +263,33 @@ script = [
 ]
 script_runner = "@duckscript"
 
-[tasks.code_generation]
+[tasks.pub_get]
 script_runner = "@shell"
 script = ["""
   cd appflowy_flutter
   flutter clean
   flutter pub get
-  flutter packages pub get
   cd ../
+  """]
+
+[tasks.pub_get.windows]
+script_runner = "@duckscript"
+script = ["""
+  cd ./appflowy_flutter/
+  exec cmd.exe /c flutter clean
+  exec cmd.exe /c flutter pub get
+  cd ../
+  """]
+
+[tasks.code_generation]
+script_runner = "@shell"
+script = ["""
   sh scripts/code_generation/generate.sh
   """]
 
 [tasks.code_generation.windows]
 script_runner = "@duckscript"
 script = ["""
-  cd ./appflowy_flutter/
-  exec cmd.exe /c flutter clean
-  exec cmd.exe /c flutter pub get
-  exec cmd.exe /c flutter packages pub get
-  cd ../
   exec scripts/code_generation/generate.cmd
   """]