Skip to content
Tutorials Center
My learning

Topics

Lesson 62 of 73 ยท Publishing

CI/CD and Releases

Automate Flutter builds and releases with GitHub Actions, Fastlane and Codemagic, and learn the tradeoffs of over-the-air updates and staged rollouts.

Releasing by hand works for the first version. By the tenth, you will have forgotten a step: the build number, the analyzer, the tests, the right flavor. Continuous integration (CI) runs your checks on every push. Continuous delivery (CD) goes further and builds, signs and uploads the app for you.

This lesson shows a CI pipeline in GitHub Actions, the Fastlane tool that automates store uploads, Codemagic (a CI service built for Flutter), the honest tradeoffs of over-the-air updates, and how to roll out a release safely. It builds on Publishing to Google Play and the App Store and Integration Tests and CI.

Real vs stand-in. The YAML and Ruby files are real and read-only, because the site cannot run a CI server or reach the stores. The live examples are JavaScript stand-ins: a pipeline runner that stops at the first failing stage and a staged rollout simulator.

A pipeline, step by step

Analyze Format and lint.
Test Unit and widget tests.
Build Signed release artifact.
Upload To TestFlight or Play.
1 / 2

A first pipeline with GitHub Actions

A workflow lives in .github/workflows/ci.yml. This one checks every pull request:

YAML
name: CI
on:
  pull_request:
  push:
    branches: [main]

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: subosito/flutter-action@v2
        with:
          channel: stable
          cache: true
      - run: flutter pub get
      - run: dart format --output=none --set-exit-if-changed .
      - run: flutter analyze
      - run: flutter test --coverage

subosito/flutter-action installs Flutter and, with cache: true, keeps the SDK between runs. Each run step must exit with code 0, otherwise the job stops and the pull request shows a red cross. Pin the Flutter version (flutter-version: 3.x.x) once your team wants identical builds everywhere.

Android builds run on Linux. iOS builds need macOS runners, which cost more minutes, so run them only on main or on release tags:

YAML
  build-ios:
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v4
      - uses: subosito/flutter-action@v2
        with: { channel: stable }
      - run: flutter build ipa --release --no-codesign

Secrets and signing

Store the keystore (base64 encoded), passwords and store API keys in repository secrets, never in the repo. A release step recreates the files from the secrets:

YAML
      - name: Restore Android keystore
        run: echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > android/upload-keystore.jks
      - name: Write key.properties
        run: |
          echo "storePassword=${{ secrets.STORE_PASSWORD }}" >> android/key.properties
          echo "keyPassword=${{ secrets.KEY_PASSWORD }}" >> android/key.properties
          echo "keyAlias=upload" >> android/key.properties
          echo "storeFile=upload-keystore.jks" >> android/key.properties
      - run: flutter build appbundle --release --build-number=${{ github.run_number }}

Using github.run_number as the build number gives you a number that always grows, which the stores require. Secrets are masked in logs, but a careless echo of a derived value can still leak them.

Fastlane: store uploads as code

Fastlane is a Ruby tool that wraps the store APIs in named "lanes". You run it from the android/ and ios/ folders. A tiny ios/fastlane/Fastfile:

Ruby
default_platform(:ios)

platform :ios do
  desc "Upload a build to TestFlight"
  lane :beta do
    build_app(workspace: "Runner.xcworkspace", scheme: "prod")
    upload_to_testflight(skip_waiting_for_build_processing: true)
  end
end

And for Android in android/fastlane/Fastfile:

Ruby
default_platform(:android)

platform :android do
  desc "Upload the bundle to the internal testing track"
  lane :internal do
    upload_to_play_store(
      track: "internal",
      aab: "../build/app/outputs/bundle/prodRelease/app-prod-release.aab"
    )
  end
end

Authenticate with an App Store Connect API key and a Google Play service account, both stored as CI secrets. For iOS signing, fastlane match keeps certificates and profiles in an encrypted private repo, so every machine uses the same ones. Flutter builds the app first (flutter build ipa), then Fastlane uploads the result.

Codemagic

Codemagic is a hosted CI/CD for Flutter. It has macOS machines, handles iOS code signing for you, and can publish straight to both stores. Its configuration is codemagic.yaml:

YAML
workflows:
  release:
    name: Release
    max_build_duration: 60
    instance_type: mac_mini_m2
    environment:
      flutter: stable
      groups:
        - store_credentials
    scripts:
      - flutter pub get
      - flutter test
      - flutter build ipa --release --build-number=$BUILD_NUMBER
    artifacts:
      - build/ios/ipa/*.ipa
    publishing:
      app_store_connect:
        auth: integration
        submit_to_testflight: true

The choice between GitHub Actions, Codemagic and others is mostly about cost, macOS access and how much signing work you want to manage yourself. Pick one, keep the config in the repo, and make the pipeline the only way releases are made.

Stand-in: a pipeline that fails fast

A pipeline is an ordered list of stages. When one fails, the later stages are skipped.

JS A fail-fast pipeline runner

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Over-the-air updates: the tradeoffs

Store review can take a day or more. Code push tools (the best known for Flutter is Shorebird) can deliver a patched Dart code to installed apps without a store release. That sounds like a free pass, but weigh it:

  • Good: you can fix a serious Dart bug in hours instead of days.
  • Limits: only Dart code can change. Native code, plugins, assets and permissions still need a store release.
  • Policy: both stores allow downloading interpreted or updated code only within rules. Changes must not alter the app's primary purpose or bypass review. Read the current policies, and treat code push as a way to fix, not a way to ship unreviewed features.
  • Risk: an unreviewed patch can break many devices at once, so it also needs staged rollouts and monitoring.

A forced update screen is the simple alternative: the app checks a minimum supported version from your server and asks the user to update from the store.

Staged rollouts

Release gradually and watch the numbers. On Google Play you choose a percentage of users; on Apple, phased release spreads an automatic update over seven days. You can pause either one. Pair this with crash reporting (see Error Handling, Logging and Crash Reporting) so you can see a problem before everybody has it.

JS Halt a rollout when the crash rate spikes

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why use github.run_number as the build number?

    Each workflow run gets a higher number than the one before, so uploads are always accepted as newer.
  2. 2. Where should keystores and API keys live in CI?

    Secrets are stored outside the repo and injected during the run.
  3. 3. What can a Dart code-push update NOT change?

    Only Dart code can be patched. Native changes need a normal store release.
  4. 4. What does fastlane add to a Flutter project?

    Fastlane wraps store uploads and signing in repeatable commands that CI can run.

Summary

  • CI runs format, analyze and test on every push; CD builds, signs and uploads the release.
  • GitHub Actions with subosito/flutter-action is a flexible start; iOS needs macOS runners.
  • Keep signing material in CI secrets and use an ever-growing build number.
  • Fastlane and Codemagic automate the store uploads and iOS signing.
  • Over-the-air patches fix Dart bugs fast but have limits and policy rules; staged rollouts limit the damage of any release.

Next: Project: Todo App with Persistence