CI/CD in Flutter (Implementation and uses of Github Actions)
CI/CD tools experience refers to your familiarity with Continuous Integration (CI) and Continuous Delivery/Deployment (CD) processes. These are practices that help automate the building, testing, and deploying of applications, making development more efficient and reliable.
Continuous Integration (CI): This involves automating the process of integrating code changes into the main codebase. Every time new code is added (e.g., after a pull request), CI tools automatically run tests to ensure the new code doesn’t break anything.
Continuous Delivery/Deployment (CD):
- Continuous Delivery: Ensures that the code is always in a deployable state. After passing the tests, the app is prepared for release but requires a manual trigger to actually deploy.
- Continuous Deployment: Goes a step further by automatically deploying the app to production once the tests pass, with no manual intervention.
Note: Flutter Machine Learning & AI Courses
If you want to build Machine Learning and AI based smart Flutter apps then check our Mobile Machine Learning courses on udemy. Avail 92% off with coupon code “MOBILEMLAI” only for a limited time
- Flutter & ML : Train Tensorflow Lite models for Flutter Apps
- Face Recognition and Detection in Flutter — The 2024 Guide
- Flutter & OCR — Build Document Scanner Clone in Flutter
- FlutterFlow for Beginners: Build “No Code” Apps in 2024
- Flutter & Google Gemini — Build Chatbots and Assistants in Flutter
- Train Image Classification Models & Build Smart Flutter Apps
- Build Gallery App Clone in Flutter With Circle To Search Feature
- Machine Learning for Flutter- The Complete 2024 Guide
- Build Flutter Apps Effortlessly with ChatGPT — Zero Coding
- Flutter & AI: Build Image & Art Generation Flutter App
What is purpose to use CI/CD in flutter?
We use CI/CD tools in Flutter for a specific reason. For example, when we are working on a Flutter project and need to provide a build to the PQA team for testing, any changes we make require us to build the Flutter project and give the APK separately to them for testing. This is the usual process.
However, if we continue working this way and make 3–4 changes in a day, manually generating the build each time can become cumbersome. But if we use GitHub Actions or similar CI/CD tools to automatically create builds, it will automatically generate builds as changes are made. This way, the QA team will continuously receive the latest builds with the updates without you having to manually generate and provide builds separately. This makes things much easier.
Implementation of CI/CD in flutter for building and deploying Flutter apps.
Follow steps for complete understanding.
1. Link Github to your Flutter project
Make repository of your flutter project and link it to github just like the image below.
2. What are Github Actions
Github Actions is a continous integration and continous delivery (CI/CD) platform that allows you to automate your build, test and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged pull request to production.
We can configure github actions by going to action tab on github above bar and configure it for dart as you can see in image below.
For implementing, First make a directory (.github) in root of flutter project. Make a nested directory workflows inside .github directory. Make a new file main.yml inside workflows directory.
You have to write this code in main.yml file as you can see in above image.
There are five main things to discussed in this main.yml file:
Explanation:
As you can see the first line in main.yml file, (on:) represents events of workflow. There are two events mentioned here: pull_request and push event. There are mentioned branches on which these events will be triggered. e.g. pull_request event will be trigerred on main and master branch. And push event will be triggered on main, master and develop branch.
Secondly, you can see the (jobs:) section there after name of workflow. You can write multiple jobs inside jobs section. But right now you can see only one job is there to be done is build. This job named as (Build & Release). After this, it tells it will be run on macOS system.
On the third point,we have some steps of that job. There are some actions to be performed. There is a channel mentioned which is (stable) for us. There is architecture mentioned after this which is (x64).
Then there are steps of run (flutter build apk) for android and iOS also.
After this, we have to mentioned name of action which is (Push to Releases) and we have to focused on one thing if we mentioned release in uses, then we have to mentioned release in artifacts as well.
In the last, there is secret token which we have to add in our github repository.
Now, How to get and add this secret token in github repository. Follow my images below to understand.
Go to Settings then Actions and generate new Repository secret. Here, you can see two fileds, one is name of secret and other is secret field.
For getting secret go and click on profile picture, then settings and then developer settings. In developer settings, go to personal access tokens and then Token (classics). Click on Generate new secret button. Generate new secret classic and write name of secret, set expiration time of that secret and select repos in scopes option. You got your secret, put it back into secret field and you got your token.
Now all the steps are done.
You just have to commit and push your code on github repository. When you push your code, these events are triggered which you mentioned in main.yml file. All the steps you write in main.yml file are now running step by step and you can see in your repository that only by pushing your code you got new builds and releases of your flutter project.
When we see our workflow in github, we will see our job is in running phase as shown in below image.
When click on this, we can see steps are running.
After completion of job we can see our latest releases are ready.
After clicking on it.
Here we go with our latest android and iOS builds.
If you want to make a test job on workflow with github actions, then use the code below.
Note: Flutter Machine Learning & AI Courses
If you want to build Machine Learning and AI based smart Flutter apps then check our Mobile Machine Learning courses on udemy. Avail 92% off with coupon code “MOBILEMLAI” only for a limited time
- Flutter & ML : Train Tensorflow Lite models for Flutter Apps
- Face Recognition and Detection in Flutter — The 2024 Guide
- Flutter & OCR — Build Document Scanner Clone in Flutter
- FlutterFlow for Beginners: Build “No Code” Apps in 2024
- Flutter & Google Gemini — Build Chatbots and Assistants in Flutter
- Train Image Classification Models & Build Smart Flutter Apps
- Build Gallery App Clone in Flutter With Circle To Search Feature
- Machine Learning for Flutter- The Complete 2024 Guide
- Build Flutter Apps Effortlessly with ChatGPT — Zero Coding
- Flutter & AI: Build Image & Art Generation Flutter App