This article will guide you on how you can automate the CI/CD workflow of your Flutter’s iOS app.
If you are not familiar with the concept behind CI/CD, Github Actions, or Fastlane, you can read this article I wrote to help you get started.
Before continuing reading this,
You should have at least tried building your Flutter app locally, and released it manually to TestFlight.
Make sure you have Fastlane installed on your development machine.
a. Initialize Fastlane for iOS
Select option number #2 (Distribution to TestFlight).
[01:00:00]: What would you like to use fastlane for?
1. 📸 Automate screenshots
2. 👩✈️ Automate beta distribution to TestFlight
3. 🚀 Automate App Store distribution
4. 🛠 Manual setup - manually setup your project to automate your tasks
Next, enter your Apple Developer account credentials.
[13:03:04]: Please enter your Apple ID developer credentials
[13:03:04]: Apple ID Username:
[13:04:36]: Logging in...
Finally, select the team that manages the app.
b. Install fastlane plugin to retrieve version code from Flutter
For the CI/CD to import the certificates and provisioning profiles, it needs to have access to the certificates repository. You can do this by generating a personal access token that has the scope to access or read private repositories.
In Github, go to Settings -> Developer Settings -> Personal access tokens -> click Generate New Token -> tick the repo scope -> then click Generate token.
In Github Actions, you are billed based on the minutes you have used for running your CI/CD workflow. From experience, it takes about 15-30 minutes before a build can be processed in App Store Connect.
For private projects, the estimated cost per build can go up to $0.08/min x 30 mins = $2.4, or more, depending on the configuration or dependencies of your project.
If you share the same concerns for the pricing as I do for private projects, you can set the skip_waiting_for_build_processing to false.
subosito/flutter-action is a Github Action that helps you set up your Flutter app by running commands that are required by your project, eg. building an app or running code generation tools.
An example command is flutter build --release. This creates a release build (.app) of your iOS app in preparation for archiving it for release (in Fastlane).
flutter build ios --release --no-codesign
Environment variables and secrets
In the example, the environment variables are retrieved from your project’s secrets.
Ideally, this should always be the case, but no one’s stopping you to set environment variables directly on the workflow file or in the code itself.
That’s it! Now for the moment of truth, test the workflow on Github Actions.
1. Create a branch
Create a branch, eg. v1.0.2.
git checkout -b v1.0.2
2. Trigger the workflow
Push the new commits to the newly created branch to trigger the workflow.
git push origin v1.0.2
After a few minutes, the build should be available in your App Store Connect dashboard.
That’s it for your Flutter’s iOS app.
Take note, that the setup of jobs may vary depending on the tools or dependencies your project requires. Feel free to comment on any issues you encountered while setting up the CI/CD workflow for your project.
ChatGPT has stormed the internet in the last four months with its capabilities to understand and generate natural language with remarkable fluency and accuracy. This article outlines how you can take advantage of these powerful AI models and create apps using Flutter and Dart.
It's a challenge to maintain Circle CI commands, jobs, workflows, and everything else in a single config.yml or config file. Luckily, there's an alternative way to make it more human-readable for the developer teams.