Automate build, test, and deployment pipelines with GitHub Actions and Codemagic.
CI/CD Overview
# GitHub Actions is free for public repos
# Codemagic offers generous free tier for mobileGitHub Actions for Flutter
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.19.0'
channel: 'stable'
- name: Get dependencies
run: flutter pub get
- name: Analyze
run: flutter analyze
- name: Run tests
run: flutter test --coverage
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: ./coverage/lcov.info
build-android:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.19.0'
- name: Get dependencies
run: flutter pub get
- name: Build APK
run: flutter build apk --release
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: app-release-apk
path: build/app/outputs/flutter-apk/app-release.apk
build-ios:
needs: test
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.19.0'
- name: Get dependencies
run: flutter pub get
- name: Build iOS
run: flutter build ios --release --no-codesign
- name: Upload IPA
uses: actions/upload-artifact@v4
with:
name: app-release-ipa
path: build/ios/ipa/*.ipaCodemagic Configuration
# codemagic.yaml
workflows:
android-workflow:
name: Android Build
max_build_duration: 60
instance_type: mac_mini_m1
environment:
flutter: stable
xcode: latest
scripts:
- name: Get dependencies
script: flutter pub get
- name: Run tests
script: flutter test
- name: Build APK
script: flutter build apk --release
- name: Build AAB
script: flutter build appbundle --release
artifacts:
- build/app/outputs/flutter-apk/app-release.apk
- build/app/outputs/bundle/release/app-release.aab
publishing:
email:
recipients:
- dev@example.com
google_play:
credentials: $GCLOUD_SERVICE_ACCOUNT
track: internal
ios-workflow:
name: iOS Build
max_build_duration: 60
instance_type: mac_mini_m1
environment:
flutter: stable
xcode: latest
scripts:
- name: Get dependencies
script: flutter pub get
- name: Run tests
script: flutter test
- name: Build iOS
script: |
flutter build ios --release
cd ios
xcodebuild -workspace Runner.xcworkspace -scheme Runner -configuration Release -archivePath build/Runner.xcarchive archive
xcodebuild -exportArchive -archivePath build/Runner.xcarchive -exportPath build/ipa -exportOptionsPlist ExportOptions.plist
artifacts:
- build/ios/ipa/*.ipa
publishing:
email:
recipients:
- dev@example.com
app_store_connect:
api_key: $APP_STORE_CONNECT_API_KEY
key_id: $APP_STORE_CONNECT_KEY_ID
issuer_id: $APP_STORE_CONNECT_ISSUER_ID
submit_to_testflight: trueFastlane Integration
# fastlane/Fastfile
default_platform(:android)
platform :android do
lane :internal do
gradle(task: 'clean')
gradle(task: 'bundle', build_type: 'Release')
upload_to_play_store(
track: 'internal',
aab: '../build/app/outputs/bundle/release/app-release.aab',
json_key_data: ENV['GCLOUD_SERVICE_ACCOUNT']
)
end
end
platform :ios do
lane :testflight do
setup_ci if ENV['CI']
sync_code_signing(type: 'appstore')
build_ios_app(
workspace: 'Runner.xcworkspace',
scheme: 'Runner',
export_method: 'app-store'
)
upload_to_testflight(
api_key_path: 'fastlane/app_store_connect.json'
)
end
endSecrets Management
# GitHub Repository Settings → Secrets and variables → Actions
# Add these secrets:
# GCLOUD_SERVICE_ACCOUNT - Base64 encoded service account JSON
# APP_STORE_CONNECT_API_KEY - Base64 encoded .p8 file
# APP_STORE_CONNECT_KEY_ID - Key ID from App Store Connect
# APP_STORE_CONNECT_ISSUER_ID - Issuer ID from App Store Connect
# CODEMAGIC_API_KEY - For Codemagic triggers# Use secrets in workflow
- name: Decode service account
run: echo "${{ secrets.GCLOUD_SERVICE_ACCOUNT }}" | base64 -d > gcloud.json
- name: Upload to Play Store
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJson: gcloud.json
packageName: com.example.app
releaseFiles: build/app/outputs/bundle/release/app-release.aab
track: internalBuild Matrix (Test Multiple Flutter Versions)
jobs:
test:
strategy:
matrix:
flutter-version: ['3.19.0', '3.16.0']
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ matrix.flutter-version }}Try It
Create GitHub Actions workflow. Add flutter-action. Run tests and build artifacts. Configure Codemagic for mobile builds.
mkdir -p .github/workflows
# Create ci.yml from examples aboveSet up CI/CD pipeline
- Create GitHub Actions workflow for test, build Android, build iOS
- Add Codemagic configuration (codemagic.yaml)
- Set up Fastlane for Play Store and TestFlight deployment
- Configure repository secrets
- Test pipeline on pull request
- Achieve green builds on all platforms
GitHub Actions for cross-platform testing. Codemagic for mobile-specific builds and store deployment. Fastlane automates screenshots, metadata, and uploads. Store secrets securely in CI settings, never in code.
Resources
- Flutter GitHub Actions: https://github.com/subosito/flutter-action
- Codemagic Docs: https://docs.codemagic.io/
- Fastlane: https://docs.fastlane.tools/
- Flutter CI/CD: https://docs.flutter.dev/deployment/cd