Automate Your Flutter Builds: CI/CD Pipeline for Dev/Staging/Prod in 30 Minutes (GitHub Actions +… (Part 2)

Automate Your Flutter Builds: CI/CD Pipeline for Dev/Staging/Prod in 30 Minutes (GitHub Actions +… (Part 2)

FlutterPulse
Solution: Update the Flutter version in all workflow files to match your local version:
# Check your Flutter version
flutter --version

# Update in workflow files
flutter-version: '3.24.0' # Use your version

Issue 4: "Upload to Play Store failed — Invalid credentials"

Solution:

  • Make sure your service account JSON is valid
  • Check that the service account has proper permissions in Play Console
  • Verify the JSON is correctly saved as a secret (entire file content)

Issue 5: "TestFlight upload failed"

Solution:

  • Verify your App Store Connect API key is valid
  • Make sure the app is already created in App Store Connect
  • Check that your bundle ID matches exactly

Issue 6: "Match password incorrect"

Solution: The Match password should be the same as when you first set up Match. Reset if needed:

cd ios
fastlane match nuke development # WARNING: Deletes all certs
fastlane match nuke distribution
fastlane match development # Create new ones
fastlane match appstore

🎨 Pro Tips & Best Practices

1. Use Build Numbers Smartly

Add this to your workflow to auto-increment build numbers:

- name: Auto-increment build number
run: |
BUILD_NUMBER=$(($(grep 'version:' pubspec.yaml | sed 's/.*+//') + 1))
sed -i.bak "s/version: \(.*\)+.*/version: \1+$BUILD_NUMBER/" pubspec.yaml

2. Cache Dependencies for Faster Builds

Add caching to speed up your workflows:

- name: Cache Flutter dependencies
uses: actions/cache@v3
with:
path: /opt/hostedtoolcache/flutter
key: ${{ runner.OS }}-flutter-install-cache-${{ env.flutter_version }}

- name: Cache pub dependencies
uses: actions/cache@v3
with:
path: ${{ env.PUB_CACHE }}
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-pub-

3. Parallel Builds

Build Android and iOS simultaneously to save time! (Already in the workflows above)

4. Manual Approval for Production

Use GitHub Environments to require manual approval:

environment:
name: production
url: https://yourapp.com

Then set up approval in GitHub repo settings.

5. Rollback Strategy

Keep artifacts for at least 30 days:

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: production-builds
path: build/
retention-days: 30

6. Automated Changelog

Generate changelogs automatically from commits:

# Use conventional commits
git commit -m "feat: add user authentication"
git commit -m "fix: resolve login crash"
git commit -m "docs: update README"

Then generate changelog with your script before deploying!

7. Feature Flags Integration

Integrate with services like Firebase Remote Config or LaunchDarkly for feature flags in different environments.

8. Monitoring & Analytics

Add different tracking IDs for each environment:

final analyticsProvider = Provider<Analytics>((ref) {
final env = ref.watch(environmentProvider);
return Analytics(
trackingId: env.isDev
? 'DEV-TRACKING-ID'
: env.isStaging
? 'STAGING-TRACKING-ID'
: 'PROD-TRACKING-ID',
);
});

📈 Monitoring Your Pipeline

Key Metrics to Track:

  • Build success rate (aim for >95%)
  • Build time (optimize if >15 minutes)
  • Deploy frequency
  • Time to recover from failures
  • Test coverage (aim for >80%)

Set Up Status Badges

Add to your README.md:

![Dev Build](https://github.com/username/repo/workflows/Development%20Build/badge.svg?branch=develop)
![Staging Build](https://github.com/username/repo/workflows/Staging%20Build/badge.svg?branch=staging)
![Production Build](https://github.com/username/repo/workflows/Production%20Build/badge.svg?branch=main)

🎊 Wrapping Up

Congratulations! You've just built a professional CI/CD pipeline! 🎉

Here's what you achieved:

  • Automated testing on every push ✅
  • Multi-environment builds (dev, staging, production) ✅
  • Automatic deployment to Play Store and TestFlight ✅
  • Slack notifications for team awareness ✅
  • Branch protection for code quality ✅
  • Version management automation ✅
  • Code coverage tracking ✅

What happens now:

  1. Push to develop → Automatic dev builds for both platforms
  2. Push to staging → Automatic deploy to internal testers
  3. Push to main → Deploy to beta (with approval for production)

You literally just push code and everything else is automatic! How cool is that? 😎

🎯 Next Steps

Want to take it further? Consider adding:

  • Integration tests in the pipeline
  • Screenshot tests for UI validation
  • Performance benchmarks tracking
  • Dependency scanning for security
  • Automated rollback on critical failures
  • Blue-green deployments strategy
  • Canary releases for gradual rollouts
  • A/B testing infrastructure
  • Managing environment-specific Firebase configurations in CI/CD
  • Implementing feature flags with environment-based rollout
  • Setting up monitoring and crash reporting per environment
  • Creating release trains for continuous delivery
  • Implementing semantic versioning automation
  • Setting up PR previews with temporary test builds
  • Managing secrets rotation in CI/CD pipelines
  • Implementing zero-downtime deployments
  • Setting up smoke tests after deployment
  • Creating deployment dashboards with GitHub Actions

💬 Troubleshooting Help

Got stuck? Here's how to debug:

Check GitHub Actions Logs:

  • Click on any failed action
  • Expand the failed step
  • Look for error messages

Test Fastlane Locally:

cd android  # or ios
bundle exec fastlane build_dev # Test lanes locally

Verify Secrets:

# Make sure secrets are set correctly
# GitHub repo → Settings → Secrets and variables → Actions

🤝 Community & Resources

Useful Links:

Need Help?

Drop your questions in the comments below! I'm here to help! 💪

Found this helpful? Give it a clap! 👏

Building something awesome? Share your experience in the comments! I'd love to hear how this setup works for your team!

Happy automating! 🚀 May your builds always be green! ✅

#Flutter #CICD #GitHubActions #Fastlane #DevOps #FlutterDevelopment #MobileDevOps #TestFlight #PlayStore #AndroidDevelopment #iOSDevelopment #Automation #FlutterDeployment #ContinuousIntegration #ContinuousDeployment #MobileAppDevelopment #FlutterTips #AppDeployment #Riverpod #FlutterCI

Report Page