Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Flutter CI - 2019

Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Continuous Integration

We are hiring!

grandcentrix.net +Pascal Welsch


@grandcentrix @passsy
Assumption:

Flutter apps have a


single codebase
Reality:

Flutter apps have


one codebase and
n platform wrappers (with
code)
Flutter Codebases

Flutter app
code

Android Fuchsia Windows


iOS embedder
embedder embedder embedder
Perfect Flutter Codebase

Flutter app code

Android Fuchsia Windows


iOS embedder
embedder embedder embedder
Real Flutter Codebase

Flutter app code

Android Fuchsia Windows


iOS embedder
embedder embedder embedder

Plugin Plugin Plugin Plugin


Plugin Plugin Plugin Plugin
Plugin Plugin Plugin Plugin
Assets

Dart Flutter Plugins


Code

Your app

Flutter Core

Platform code Core Plugins

Embedder
Responsibility

Embedder App

Flutter App code


Core (Dart) Flutter SDK

Assets

Plugins

Embedder SDK
Platform code
CI steps
- Build app
- Run unit tests
- Run UI tests
- Run static analysis
- Code coverage
- Lint
- Danger
Difficulties of CI in mobile
development
- Android Emulator required for Instrumentation Tests
- iOS Simulator required for iOS UI Tests
- iOS apps can’t be build on linux

Jenkins, one of the few solutions offering, runners on OSX


Flutter CI
- Tests (even UI tests) run headless on every OS

- Building/Testing embedder apps requires embedder SDK


tools
- For iOS/Mac apps you need macOS
- For Android you need the Android SDK
- For Windows you need new hardware every year
Which CI is good for Flutter?
- Travis CI
- CircleCi
- Jenkins
- GitLab CI
- GitHub Actions
- you name it...
Which CI?
Any CI, but I’ll focus on GitLab CI for today

Let’s assume the following is given:

$ echo “Let’s build”

$ git clone git@github.com:passsy/flutter-app.git


$ flutter build
$ flutter test
$ flutter analyze
$ flutter build
❌ command not found: flutter
Let’s install flutter
git clone
git@github.com:flutter/flutter.git

export PATH="$PATH:`pwd`/flutter/bin"
Let’s install flutter
What flutter doesn’t require
- Dart
- Flutter engine
- Java
- Android SDK *
- Xcode toolchain *

* Optional
Finally flutter is
installed
The flutter update
problem
Make your CI builds
reproducible!
Never use latest

Let all developers and CI use the same flutter version

Make flutter part of your project


Flutter wrapper
github.com/passsy/flutter_wrapper

- single executable flutterw which downloads the correct


version before executing flutter
- Version is part of your repository (submodule)
Live Demo
$ ./flutterw build
$ flutter build -h
Available subcommands:
aot Build an ahead-of-time compiled snapshot of your
app's Dart code.
apk Build an Android APK file from your app.
bundle Build the Flutter assets directory from your app.
ios Build an iOS application bundle (Mac OS X host
only).
Use a bash script to
prevent vendor lock-in
Build our build_android.sh
#!/bin/bash
set -e

flutter build apk


Execute it on GitlabCI
image: "passsy/flutterw:0.1.0"

before_script:
- ./flutterw doctor --verbose
pr:
script:
- ./ci/build_flutter.sh
Execute it on Jenkins
pipeline {
agent { docker "cirrusci/flutter"}
stages {
stage(“pr”) {
sh ‘ci/pr.sh’
}
}
}
Docker!
- Use Docker to build your flutter app
- Except for iOS builds
- Allows building it locally (gitlab-runner)
- Works on almost every modern CI
Improve our build_flutter.sh
#!/bin/bash
set -e

flutter format lib


flutter analyze
flutter test --coverage
flutter build android
Improve build script
./flutterw test --coverage

# parse and show code coverage (via lcov)


genhtml -o coverage/html coverage/lcov.info
Improve build script
# format with line width 120
./.flutter/bin/cache/dart-sdk/bin/dartfmt
--set-exit-if-changed -w -l 120 lib test
Build iOS on macOS
- Use gitlab-runner and make your MacBook a runner
-
Build android
- Create build_android.sh
- Works in docker container
Create releases
- Use existing tools of the embedder platform
-
-
Create releases (android)
- release_android.sh
- Use gradle plugin to publish to play store
github.com/Triple-T/gradle-play-publisher
- ./gradlew publishApk
Create releases (ios)
- Use what Sebastian suggested in his talk
- Fastlane
- xcbuild is your friend
Codemagic
- It works
- Runs tests, builds apps
- Easy way to get running for iOS without a Mac

- I don’t trust them


Thanks
Flutter Workshop
Hot Reload Hackathon

Tuesday, March 12, 2019


Cologne, grandcentrix

https://flutter.school

You might also like