YTII Official Blog - Stories, Updates and Tips

How to Setup CI/CD for Flutter Apps with GitHub?

Written by Mangesh Gothankar | August 23, 2021 12:02:22 PM Z

Some programmers argue that there is always a trade-off between producing high-quality software and developing code rapidly to meet business objectives. Developers can write better software and build products faster with CI/CD (Continuous Integration/Continuous Delivery), which is a win-win situation for everyone.

This blog explains how to use Flutter to implement CI/CD (CI/CD implementation Guide) and why it's crucial to have it in your software development team. We'll set up a CI/CD (continuous integration and continuous deployment) pipeline for a Flutter-based mobile app in this blog. We'll put up automated build/test and establish release jobs with Github Actions.

  • We'll start by creating a flutter app, thus doing a Flutter app development and then uploading it to a Github repository. After that, we'll set up a workflow for the app's continuous integration.
  • We'll make two workflows: one for pull requests and the other for releasing Android apps.
  • At the end of it all, we'll have a streamlined process to build, test, and deliver Android applications to GitHub releases.

Why is CI/CD Important for Flutter?

CI/CD is a means of delivering apps to clients more frequently by incorporating automation into the app development process.

The three key principles associated with CI/CD are:-

  • Continuous integration,
  • continuous delivery, and
  • continuous deployment

It's always best to collect feedback as soon as possible and as frequently as feasible for any application. We can check that any new code merged into production/mainline code has been thoroughly tested and will not break any features. Additionally, automating release generation will save time and effort on repetitive chores, freeing you time to work on new features.

What are the Advantages of CI for a Company?

1. An efficient development team

The development team becomes more bankable as a result of CI, and the cost of your software projects reduces. To assist cut build costs and uncover flaws early in the software lifecycle, CI tries to refine the integration process by breaking it down into basic, everyday development tasks.

2. Quicker Software Development

The infrastructure, as well as the deployment, are both automated. Everyone, especially engineers, enjoys seeing the results of their labor, and the benefits of the code are immediately apparent to the business. When developers can use test automation and have less overhead and coordination with a QA team, deploying a smaller patch of code is less risky.

3. Concentrate on Resolving Business Issues

From the integration and testing phases to delivery and deployment, CI/CD brings continuous automation and monitoring across the lifecycle of apps. These approaches are referred to as a "CI/CD pipeline" when they are combined and supported by development and operations teams working together in an agile manner using either a DevOps or Site reliability engineering (SRE) strategy. Pipeline development requires the support of the dev-ops team, which allows developers to concentrate on solving business challenges rather than worrying about infrastructure deployment.

Using Github to Set Up a Flutter project

We'll start by creating a new Github repository. Make a copy of the repository on your computer. Open your chosen cli tool, navigate to the repository, and use “flutter create” to build a new flutter app. Now you may push this new app to your repository.

Using GitHub Actions to set up a Workflow

We can now start developing workflows in Github actions after we have the application code in the repository. Workflow might differ from project to project and on a requirement-by-requirement basis. We'll set up a workflow for generating a flutter application, running automated tests, and then creating apks/app bundles for GitHub releases.

So, let's get this workflow started.

Action workflow files in GitHub are created in YAML and saved in a designated location in your repository.

Make a Workflow File.

In the .github directory, create a new directory called workflows. In the workflows directory, create a new file called android-release.yml, and the .github/workflows/android-release.yml will be the file path.

In our workflow file, we'll define the name, trigger, jobs, and steps. The syntax for workflow files can be found here. There are many actions that we may use and customize to complete jobs.

Trigger For the Workflow

When new code is checked into the master branch, we want an automatic build to run. You can also utilize different triggers.

GitVersion can be Used to Determine the Version Number

The tool Gitversion will be used to calculate the release version. For additional details, look at gitversion and semantic versioning. We'll execute this in a different job and then utilize artifacts to tag releases in another job.

This job will calculate the version number and save it in the build artifacts in a file called version.txt.

Create a Release Job, Build it, and Test it

We'll set up flutter and java in the build agent, test the flutter app, make android APKs and app bundles, and then create a release using build artifacts in this job.

The first three steps are to check out the source and configure the build agent for flutter and java.

We'll retrieve the version number by downloading the version.txt file from the previous task. This is an optional feature that you may or may not require.

Flutter cli commands will be used to test and build apks and app bundles in the next steps.

flutter pub get flutter test flutter build apk --release --split-per-abi flutter build app bundle

We will have built APKs and an app bundle after following the procedures above. You might want them to be released so that you can download them and test them on physical devices.

We're making use of a secret value named GH TOKEN in this case. This is a personal access token used by the build agent to make a GitHub release.

To make releases in this workflow, generate a personal access token. Create a new token at https://github.com/settings/tokens . Then make it a secret in your repository's https:///settings/secrets.

Read our other post How to build web with Flutter 2.2.

Final Thoughts

In many circumstances, we believe that CI/CD enhances code quality and allows us to iterate on high-quality products faster than other approaches.
So to answer “When should CI/CD be used?” it's something we advocate using if you're starting from scratch. If you have monolithic IT systems and want to incorporate CI/CD into your development process, think carefully. You'll have to restructure the architecture to meet the new needs. You are more than likely not to gain from CI when making updates to your existing code, but you will undoubtedly benefit if you make use of it for a new project.

At Your Team In India, we have a pool of certified Flutter engineers. Need help setting up a dedicated team of Flutter developers in India? Connect with us our business head now and get a free consultation.