For the past few days, I was working on automating the process of testing, analyzing, check the code formatting, building, and generating an Android APK for a flutter project using Github Actions. This process is the same for a typical flutter application since we are running terminal commands. I will skip all the annoying things that GitHub actions put me into and 😀 quickly tell you the steps to set up the GitHub actions for your Flutter apps.

Github Actions help you automate your software development workflows in the same place you store code and collaborate on pull requests and issues. You can write individual tasks, called actions, and combine them to create a custom workflow. It contains most features than other CI/CDs like Travis or CircleCI have. The speed of Github Actions is good, and its pricing is better than that of Travis.

Flutter 💙 is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. Please visit flutter.dev for more info about it.

Now, without stretching up the introduction, let’s proceed to the workflow.

Creating a Workflow File

The first thing you have to do is create a .yml file, which is a configuration file that Github Action can understand.

You must store workflow files in the .github/workflows/ directory in your repository. You can name the file whatever you want, for this tutorial name it flutter-ci.yml .

.github/workflows/flutter-ci.yml

#on

Github Actions will execute the workflow following the events under on key. In this example, we want to run it only when we push to master branch but you can add any of your preferred branches.

#job

A workflow run is made up of one or more jobs. For our example, we need only one job.

#runs-on

The type of virtual host machine to run the job on. For our case, we need ubuntu-latest .

Each ubuntu host machine contains different installed software. You can check a list of supported software, tools, and packages in each virtual environment here.

#steps

A job contains a sequence of tasks called steps.

You can have a granular step that runs only one command or a multi-line with a sequence of tasks pack together.

Let’s go through a series of steps in order to meet our requirements.

We have to set up the Flutter environment for the Github Actions and for that we will be using subosito/flutter-action .

2. Write the command to get the Flutter dependencies.

- run: flutter pub get

3. Check for any formatting issues in the code.

- run: flutter format --set-exit-if-changed .

4. Statically analyze the Dart code for any errors.

- run: flutter analyze .

5. Run widget tests for our flutter project.

- run: flutter test

6. Build an Android APK.

- run: flutter build apk

7. Finally, upload our generated app-release.apk for our workflow to the artifacts. For this, we will be using actions/upload-artifact .

#Final YAML file

We have completed all the steps to write the workflow file for your flutter apps.🤗 Here is the final flutter-ci.yml file which you directly copy and paste to your workflow.

Watch your builds on GitHub

Once you have pushed to your master branch, you can immediately see the build starting for your latest commit on GitHub under the Actions tab.

Watching the logs scroll up the window is a very satisfying feeling😎. You can see all the logs in realtime and see if there are any errors and debug them.

Now you are wondering where did I find the build APK for testing.

In the top right corner of a workflow run, once the run is successful, there will be a Artifacts dropdown and from that, you can download the build APK. Here's a screenshot of what it looks like

For the complete source code of an example flutter application, visit the following link.