As a Flutter developer, you would obviously make an app on your local environment and make it as fully functional as possible on your environment, but what about other environments? We don’t know.
Okay, so imagine, we upload our Flutter app to GitHub and then clone the same repo on a different machine and run our app there. There is a chance that your app might not run/come up with multiple breakages and weak links, especially with Flutter, a cross-platform development framework. So, how do we make our apps run perfectly in all sorts of environments? That’s where CI/CD comes in.
Some of the best CI/CD tools are:
There are very many more tools out there, but the above are some of my favorites. Personally, for Flutter, I prefer Codemagic.
Travis CI is a simple CI/CD tool used to build apps hosted on GitHub and Bitbucket (just like the other CI/CD tools).
.travis.yml
file in your project root, add the following code, and push it to your git repo:os:
- linux
sudo: false
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- libstdc++6
- fonts-droid-fallback
before_script:
- git clone https://github.com/flutter/flutter.git -b beta
- ./flutter/bin/flutter doctor
script:
- ./flutter/bin/flutter test
cache:
directories:
- $HOME/.pub-cache
.yml
file is doing:We are choosing our Operating System as Linux and installing packages libstdc++6
and fonts-droid-fallback
because Flutter is dependent on these packages. In our sources, we need to mention ubuntu-toolchain-r-test
to get the correct version of libstdc++6. We have 2 types of scripts to run here once our environment is set up. These are before_script
and is script
.
As the name suggests, before_script
is executed before the flutter doctor
to test if Flutter runs fineflutter test
. If your project runs without any errors, then congrats, it works fine on all environments! However, if it fails, you can check your error and fix it on your local machine with the automated workflow. Any changes will be automatically triggered to run a fresh build.
Once Travis CI detects a .travis.yml
file in your repo, it begins the CI as per the .yml
file. Also, anytime you make a new commit to your repo, Travis CI automatically begins another CI test without you having to run it manually.
It’s that easy and simple to use Travis CI. You can also update your build status on your repo by adding the badge from Travis CI to your README file.
Free Resources