GitHub Actions: CI/CD and Automate Beta Deployments for your Flutter iOS Apps

Sagar Patel
Mindful Engineering
5 min readJun 13, 2022

What Are the Github Actions?

Github Actions is automation software that helps in continuous integration and continuous delivery. It enables the developer to automate many different tasks like building, testing, analyzing, and deploying.

What is Continuous Integration (CI)?

Continuous Integration is a practice in which developers commit their code daily to the repository. Every commit is then automatically built which will make it easier to detect different errors that may occur from the commits.

What is Continuous Delivery (CD)?

Continuous Delivery is when the software is automatically built, tested, and ready for production. Therefore, continuous delivery helps in automating the release process, the only manual thing that has to be done is deciding when the release should occur.

Explaining Workflow File

To use Github Actions in your Github repository, then first you need to create the directory .github/workflows:

Now inside the workflows folder, you need to create yaml files or workflows that will contain different jobs which will be triggered in response to a specific event
Ex:

workflow basic steps

So the above is a basic workflow file, which we will explain before showing an example with Flutter:

  • on: This will contain the name of the event that will trigger this workflow, or it can contain a list of events, for example in the above file whenever we do a push or pull this workflow file will be triggered.
  • name: This represents the name of this workflow file, which will be shown in the actions tab title.
  • jobs: Each workflow run can contain one or more jobs. Here we used only one job.
  • runs-on: Each job needs to run on a virtual machine (runners) (in our case we used Github's hosted runner), in the above case we used macos-latest.
  • steps: Each job will contain multiple tasks which are encapsulated with steps.
  • run: Run the appropriate command, for example in the above file we use flutter cleanthat will delete the /build folder.
  • name: The name here is optional, but it can be used to identify the command in the log.
  • uses: Selects an action to run as part of a step in your job, for example in the above file we used actions/checkout@v1. Actions are basically a bunch of commands. You can find different actions from the actions page of GitHub.

The easiest way to build a signed Flutter iOS app using GitHub Actions

While I suggest you read the official documentation, I will still show you the easiest way (in my opinion) to build your Flutter iOS app. I will also show you the steps I took and my documentation. This way you can be inspired by this article and double-check the sources when you start implementing your own GitHub workflow.

For a first step, I assume:

  • You are familiar with the different iOS build types (development, ad-hoc, app store, and enterprise)
  • You are familiar with creating an iOS build certificate and provisioning a profile
  • You are familiar with exporting the certificate as .p12 file (password protected).

If not, read the official Apple documentation here.

The documentation of GitHub tells you to include your iOS distribution certificate and provisioning profile as base64 string to your GitHub secrets. However, I also added the other secrets in Actions secrets as below image.

Token, Username, and Password cases will see further.

Let’s do this step vice? ✨

1. Add a Workflow file to your GitHub Project

In the root folder of your Flutter project, create a new folder .github and create a subfolder workflows. This is where our workflow YAML files will be placed.
A project can have multiple workflow files like build, release, and test as per the requirement. To make this article easy to understand we used one here which is main.yaml.

2. Add GitHub Token

  • Go to the personal access tokens section in your GitHub settings.
  • Generate a new token that has scope for repository access and add this token in actions secrete of Github repo(settings/secrets/actions).

3. Create an app-specific password

Go to appleid.apple.com then click on App-specific-passwords and generate one.
Also, identify the username from the left corner below the profile pic (you can use the email as the username).
Now Add password and username in actions secrete of the Github repo(settings/secrets/actions).

If you don’t see the option to generate app-specific passwords, you’ll need to enable two-factor authentication,

4. Write Commands

Below is the whole craft of main.yaml

lines 1–10: To trigger the workflow when there is any pull or push request.

lines 17–28: Is for checkout the branch and setup the flutter and xcode versions in github’s runner.

line 30–47: Is for installing the p12 certificates and profiles with building the iOS release.

49–58: Is for cleaning the Xcode workspace and create the archive file.

60–90: Is for generating the plist on the air, which is used to export an IPA from created archive file.

92–109: Is for export the IPA, upload the artifacts to the specific path, delete the extra elements for the iOS folder(to overcome the conflict error when we upload IPA to testflight)

111–116: Is for push the IPA to GitHub releases dashboard by using the secret TOKEN of which we have stored in actions secrete of github repo.

118–119: Is for validate the IPA file by using the run script validate-app with params username and app specific password which also we have stored in actions secrete of github repo.

121–125: Is for upload ipa to the testflight.

That’s it. You can find the complete source code of the project on GitHub. If you face any issues please post them in the comments section.

--

--