Setting up CI/CD for Flutter using GitHub Actions




Simply, a pipeline which builds, test, and maybe even release your app when you push code. That’s where CI/CD with GitHub Actions comes in.

In this article, i’ll walk you through how i setup CI/CD for a Flutter project using GitHub Actions. It’s not super complicated, but there are few things that can trip you if you are new.

Why CI/CD for Flutter?

Flutter is cross-platform. That means you probably want to build for Android, iOS, Web, maybe Desktop. Doing it manually is boring and error prone. CI/CD helps with:

  • Running unit/widget tests automatically.

  • Making sure your app builds on every push.

  • Generating release APKs or IPA files.

  • Catching bugs early instead of when client shouts at you.

Getting Started

All GitHub Actions needs is a workflow file inside .github/workflows/

Let’s create one:

.github/
 └── workflows/
     └── flutter_ci.yml

Inside flutter_ci.yml, we define jobs. Here is a simple example:

name: Flutter CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: subosito/flutter-action@v2
        with:
          flutter-version: "3.19.0"

      - name: Install dependencies
        run: flutter pub get

      - name: Analyze
        run: flutter analyze

      - name: Run tests
        run: flutter test

      - name: Build APK
        run: flutter build apk --release

iOS Builds

For Android, GitHub Actions is smooth. For iOS it’s tricky because you need a MacOS runner. You can change runs-on: macos-latest and then add:

- name: Build iOS
  run: flutter build ios --release --no-codesign

If you want to sign and upload to TestFlight, you’ll need to setup certificates, provisioning profiles and use fastlane.

Secrets & Keystores

Don’t push your keystore or API keys to GitHub repo. Use GitHub Secrets instead. Go to:

Repo Settings → Secrets → Actions → New repository secret

Then in workflow:

- name: Decode keystore
  run: echo "${{ secrets.ANDROID_KEYSTORE }}" | base64 --decode > android/app/key.jks

Deployments

You can go further and deploy automatically. Example:

  • Upload APK to Firebase App Distribution.
  • Push Web build to GitHub Pages.
  • Send IPA to TestFlight.

For Firebase distribution, add:

- name: Upload to Firebase
  uses: wzieba/Firebase-Distribution-Github-Action@v1
  with:
    appId: ${{ secrets.FIREBASE_APP_ID }}
    token: ${{ secrets.FIREBASE_TOKEN }}
    groups: testers
    file: build/app/outputs/flutter-apk/app-release.apk

Wrap Up

Setting up CI/CD for Flutter using GitHub Actions is not rocket science, but you need to play with configs until it works for your case. Start simple — just run tests and build. Then later add deployments.

Once setup, you never have to worry “did i forget to run tests?” or “is my build broken?” GitHub Actions will tell you before your client does.

Comments