Optimizing Workflow for Flutter Add to App Module Setup

ios
android
flutter
#1

Bitrise Build Issue Report template

Description of the issue

Greetings. I’m working on an Add to App Flutter project (https://flutter.dev/docs/development/add-to-app) that has a repo with a flutter module, iOS app, and an android app in the same parent directory. The flutter module needs to be build and then pulled into the host iOS app and host android app. My primary workflow needs to run through the flutter code (analyze and test steps), build the flutter project for iOS, run cocoa pods to install the flutter build in the iOS project, run through the iOS tests, build the flutter project for android, and run through the android tests. Currently this all encompassing workflow takes ~25 minutes.

My thought was to break out this workflow into multiple workflows, one to test flutter, another to build flutter for iOS and test the iOS app, and another to build flutter for android and test the android app. It seems like there’s a limitation where a single trigger can only have one workflow attached to it. I then went down the route of adding new Bitrise apps that point to the same Github repo but from what I’m seeing it appears that multiple Bitrise apps pointed at the same Github only fire off one of the app’s triggers and ignore the other apps’ triggers.

I have also gone back and used “utility workflows” (https://devcenter.bitrise.io/bitrise-cli/workflows/) to chain my three (flutter + iOS + android) workflows together and attach them to a single trigger but it is still taking over 20 minutes.

Is there a way that you can suggest to optimize my build times or improve the process that I’m trying to achieve? Even if the best solution is just to upgrade to a more expensive plans, it would be helpful to get an answer. Optimizing this build time issue so it doesn’t hinder development is high priority for my client and could mean the difference between staying with Bitrise or switching CI providers completely.

Thanks in advance.

Environment:

Where did the issue happen?

bitrise.io

Which build Step causes the issue and which version of the step?

Flutter Build 0.12.0 (which is needed by the host apps in order to run their tests) is the step that is taking the longest time.

Reproducibility

  • Does a “Rebuild” help? (You can trigger a rebuild from the Build’s page, by clicking the “Rebuild” button in the top right corner of a finished build) : NO
  • Does a rebuild without caches help? (You can remove the Cache:Pull and Cache:Push steps temporarily to not to use the cache, or you can delete all the caches on the Settings tab of the app. : NO
  • Does the issue happen sporadically, or every time? : Every time
  • Does upgrading the build Step to the latest version help? : NO
  • When did the issue start? : As soon as I set up the workflow around last week 2/5/2020

Local reproduction

_Can it be reproduced on your own Mac/PC by following our local debug guide? Please follow at least the first section (“Testing with a full clean git clone”) to make sure to test the state of the code what bitrise.io will get when it does a git clone in the clean environment! We have reproduced this locally with a clean git clone on several different computers but none take as long to run through these steps as the Bitrise workflow does.

Local reproduction: Linux / Android (docker based) stack builds

Can it be reproduced by running the build locally, after doing a new git clone of the repository into the /tmp directory and running the build from there with the Bitrise CLI ( https://www.bitrise.io/cli )? If no, can it be reproduced with Docker (using the same docker images / environment we use on bitrise.io)? Related guide: http://devcenter.bitrise.io/docker/run-your-build-locally-in-docker/ . Haven’t tried

Build log

Please copy paste the build’s bitrise.io URL here (or if the issue happens somewhere else then the full logs), or if you can’t share the url / log here then send the url or full log through a private channel (e.g. email - https://www.bitrise.io/contact ), with a link to the related Discuss issue.

Log summary:

+------------------------------------------------------------------------------+
|                               bitrise summary                                |
+---+---------------------------------------------------------------+----------+
|   | title                                                         | time (s) |
+---+---------------------------------------------------------------+----------+
| ✓ | activate-ssh-key                                              | 9.48 sec |
+---+---------------------------------------------------------------+----------+
| ✓ | git-clone                                                     | 8.18 sec |
+---+---------------------------------------------------------------+----------+
| ✓ | Do anything with Script step                                  | 3.45 sec |
+---+---------------------------------------------------------------+----------+
| ✓ | flutter-installer                                             | 1.3 min  |
+---+---------------------------------------------------------------+----------+
| ✓ | flutter-analyze                                               | 40.12 sec|
+---+---------------------------------------------------------------+----------+
| ✓ | flutter-test                                                  | 20.98 sec|
+---+---------------------------------------------------------------+----------+
| ✓ | deploy-to-bitrise-io                                          | 7.57 sec |
+---+---------------------------------------------------------------+----------+
| ✓ | flutter-build                                                 | 9.1 min  |
+---+---------------------------------------------------------------+----------+
| ✓ | cocoapods-install                                             | 15.17 sec|
+---+---------------------------------------------------------------+----------+
| ✓ | xcode-test                                                    | 3.3 min  |
+---+---------------------------------------------------------------+----------+
| ✓ | flutter                                                       | 1.4 min  |
+---+---------------------------------------------------------------+----------+
| ✓ | Do anything with Script step                                  | 3.61 sec |
+---+---------------------------------------------------------------+----------+
| ✓ | flutter-build                                                 | 3.5 min  |
+---+---------------------------------------------------------------+----------+
| ✓ | android-lint                                                  | 2.1 min  |
+---+---------------------------------------------------------------+----------+
| ✓ | android-unit-test@1.0.0                                       | 26.15 sec|
+---+---------------------------------------------------------------+----------+
| ✓ | deploy-to-bitrise-io                                          | 27.95 sec|
+---+---------------------------------------------------------------+----------+
| Total runtime: 23.3 min                                                      |
+------------------------------------------------------------------------------+

Workflow setup from the bitrise.yaml file:

---
format_version: '7'
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: flutter
trigger_map:
- push_branch: master
  workflow: primary-flutter-ios-android
- push_branch: "*"
  workflow: primary-flutter
- pull_request_source_branch: "*"
  workflow: primary-flutter
- tag: v*.*.*
  workflow: deploy
workflows:
  deploy:
    steps:
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone: {}
    - script:
        title: Do anything with Script step
    - flutter-installer: {}
    - flutter-analyze:
        inputs:
        - project_location: flutter_module/
    - flutter-test:
        inputs:
        - project_location: flutter_module/
    - ios-auto-provision:
        inputs:
        - generate_profiles: 'yes'
        - project_path: iOS/Generic.xcworkspace
        - scheme: Generic
        - team_id: TEAMID
    - recreate-user-schemes:
        inputs:
        - project_path: iOS/Generic.xcworkspace
    - flutter-build:
        inputs:
        - project_location: flutter_module/
        - ios_additional_params: "--release --no-codesign --build-name=$BITRISE_GIT_TAG
            --build-number=$BITRISE_BUILD_NUMBER"
        - android_additional_params: "--release --build-name=$BITRISE_GIT_TAG --build-number=$BITRISE_BUILD_NUMBER"
        - android_output_pattern: |-
            *build/host/outputs/apk/*/*.apk
            *build/host/outputs/bundle/*/*.aab
        - platform: ios
        - ios_codesign_identity: ''
    - cocoapods-install:
        inputs:
        - source_root_path: iOS/
    - xcode-archive:
        inputs:
        - project_path: iOS/Generic.xcworkspace
        - scheme: Generic
        - export_method: "$BITRISE_EXPORT_METHOD"
        - team_id: TEAMID
        - configuration: Release
    - script:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/usr/bin/env bash
            echo 'Generating local.properties ...'
            cat > "./android/local.properties" <<- FILE_CONTENT
            flutter.sdk=/Users/vagrant/flutter-sdk
            FILE_CONTENT
    - flutter:
        inputs:
        - working_dir: flutter_module
        - commands: clean
        - version: stable
    - flutter-build:
        inputs:
        - project_location: flutter_module/
        - ios_additional_params: "--release --no-codesign --build-name=$BITRISE_GIT_TAG
            --build-number=$BITRISE_BUILD_NUMBER"
        - android_additional_params: "--release --build-name=$BITRISE_GIT_TAG --build-number=$BITRISE_BUILD_NUMBER"
        - android_output_pattern: |-
            *build/host/outputs/apk/*/*.apk
            *build/host/outputs/bundle/*/*.aab
        - platform: android
        - ios_codesign_identity: ''
    - android-lint:
        inputs:
        - module: app
        - variant: release
        - project_location: android/
    - android-unit-test:
        inputs:
        - module: app
        - variant: release
        - project_location: android/
    - android-build:
        inputs:
        - module: app
        - variant: release
        - project_location: android/
    - deploy-to-bitrise-io:
        inputs:
        - notify_email_list: "$NOTIFY_EMAILS"
        - notify_user_groups: none
  primary-ios:
    steps:
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone: {}
    - script:
        title: Do anything with Script step
    - flutter-installer: {}
    - flutter-build:
        inputs:
        - platform: ios
        - android_output_pattern: |-
            *build/host/outputs/apk/*/*.apk
            *build/host/outputs/bundle/*/*.aab
        - project_location: flutter_module/
    - cocoapods-install:
        inputs:
        - source_root_path: iOS/
    - xcode-test:
        inputs:
        - scheme: Generic
        - project_path: iOS/Generic.xcworkspace
    - deploy-to-bitrise-io:
        inputs:
        - notify_user_groups: none
  primary-android:
    steps:
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone: {}
    - flutter-installer: {}
    - script:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/usr/bin/env bash
            echo 'Generating local.properties ...'
            cat > "./android/local.properties" <<- FILE_CONTENT
            flutter.sdk=/Users/vagrant/flutter-sdk
            FILE_CONTENT
    - flutter-build:
        inputs:
        - platform: android
        - is_debug_mode: 'true'
        - android_output_pattern: |-
            *build/host/outputs/apk/*/*.apk
            *build/host/outputs/bundle/*/*.aab
        - project_location: flutter_module/
    - android-lint:
        inputs:
        - module: app
        - variant: debug
        - project_location: android/
    - android-unit-test@1.0.0:
        inputs:
        - module: app
        - variant: debug
        - project_location: android/
    - deploy-to-bitrise-io:
        inputs:
        - notify_user_groups: none
  primary-flutter:
    steps:
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone: {}
    - script:
        title: Do anything with Script step
    - flutter-installer: {}
    - flutter-analyze:
        inputs:
        - project_location: flutter_module/
    - flutter-test:
        inputs:
        - project_location: flutter_module/
    - deploy-to-bitrise-io:
        inputs:
        - notify_user_groups: none
  primary-flutter-ios:
    before_run:
    - primary-flutter
    steps:
    - flutter-build:
        inputs:
        - platform: ios
        - android_output_pattern: |-
            *build/host/outputs/apk/*/*.apk
            *build/host/outputs/bundle/*/*.aab
        - project_location: flutter_module/
    - cocoapods-install:
        inputs:
        - source_root_path: iOS/
    - xcode-test:
        inputs:
        - scheme: Generic
        - project_path: iOS/Generic.xcworkspace
  primary-flutter-ios-android:
    before_run:
    - primary-flutter-ios
    steps:
    - flutter:
        inputs:
        - working_dir: flutter_module
        - commands: clean
        - version: stable
    - script:
        title: Do anything with Script step
        inputs:
        - content: |-
            #!/usr/bin/env bash
            echo 'Generating local.properties ...'
            cat > "./android/local.properties" <<- FILE_CONTENT
            flutter.sdk=/Users/vagrant/flutter-sdk
            FILE_CONTENT
    - flutter-build:
        inputs:
        - platform: android
        - is_debug_mode: 'true'
        - android_output_pattern: |-
            *build/host/outputs/apk/*/*.apk
            *build/host/outputs/bundle/*/*.aab
        - project_location: flutter_module/
    - android-lint:
        inputs:
        - module: app
        - variant: debug
        - project_location: android/
    - android-unit-test@1.0.0:
        inputs:
        - module: app
        - variant: debug
        - project_location: android/
    - deploy-to-bitrise-io:
        inputs:
        - notify_user_groups: none
app:
  envs:
  - opts:
      is_expand: false
    BITRISE_FLUTTER_PROJECT_LOCATION: "."
  - opts:
      is_expand: false
    BITRISE_PROJECT_PATH: ios/Runner.xcworkspace
  - opts:
      is_expand: false
    BITRISE_SCHEME: Runner
  - opts:
      is_expand: false
    BITRISE_EXPORT_METHOD: development
meta:
  bitrise.io:
    machine_type: elite_xl
0 Likes