Advanced
Setting Up a CI/CD Pipeline for Flutter with GitHub Actions
· 9 min read
Why You Need CI/CD
If you want to be sure, every time a pull request opens, that the code compiles, passes analysis and doesn't break existing tests, checking that by hand every time is both slow and easy to forget. Continuous Integration (CI) is a system that runs these checks automatically on every push or PR; Continuous Deployment/Delivery (CD) adds the step of automatically building and shipping the app once tests pass. GitHub Actions is a CI/CD tool built into GitHub, with no separate service required.
Basic Workflow Structure
A workflow is a YAML file in the project's .github/workflows/ folder. The on key defines when the workflow triggers, while jobs defines which steps run in which environment.
name: Flutter CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
analiz-ve-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.41.6'
channel: 'stable'
- run: flutter pub get
- run: flutter analyze
- run: flutter testThis workflow runs on every push to the main branch and every pull request opened against main; it downloads dependencies, runs static analysis with flutter analyze, and runs the tests with flutter test. If any of these three steps fails, GitHub shows a red ❌ on the pull request screen and blocks the merge button (if a branch protection rule is set).
Adding a Build Step
If you want to produce an APK or a web build once tests pass, add a build step to the same job or to a separate one. For a web build, the output is generated in the build/web folder, and the next step can upload it to a hosting service.
build:
needs: analiz-ve-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.41.6'
channel: 'stable'
- run: flutter pub get
- run: flutter build web --release
- run: flutter build apk --releaseneeds: analiz-ve-test makes this job run only after the analysis and test job finishes successfully, so you don't waste time trying to build broken code.
Storing Signing Credentials with Secrets
Never put sensitive information like an Android signing key (keystore) or a Firebase service account into the YAML file or the repository as plain text. Instead, define a secret under the repo's Settings → Secrets and variables → Actions, and reference it in the workflow as ${{ secrets.ANAHTAR_ADI }}; the value never appears in the logs.
- name: Keystore dosyasını oluştur
run: echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > android/app/keystore.jksThings to Watch Out For
1. Use the Pub and Gradle Caches
subosito/flutter-action can cache pub packages automatically with the cache: true parameter; for Android builds, you can also cache the ~/.gradle/caches directory with actions/cache to avoid redownloading dependencies on every run. This can cut the pipeline duration by minutes.
2. Keep flutter-version in Sync with Your Project
The flutter-version value in the workflow should match the environment.sdk constraint in pubspec.yaml. A mismatch can make code that works locally fail in CI with a "version solving failed" error.
Conclusion
A simple .github/workflows/ci.yml file runs automatic analysis, tests and builds on every push and pull request, keeping broken code out of the main branch. Order your jobs with needs, speed up dependency downloads with actions/cache, and always manage sensitive data through GitHub Secrets — never as plain text in the repo or the YAML file.