If you already use github for version control, then you can always go a notch higher and integrate a Continous Integration and Continous Deployment(CI & CD) pipeline for your mobile apps. This can be achieved by using the github actions feature that github offers for free.
Pre-requisites
Have github as the version control for your app`s codebase.
Before we kick off lets look at some definitions first:
Continous Integration ( CI )
It is an automation process for developers where new code changes to an app are regularly built, tested, and merged to a shared repository. Itβs a solution to the problem of having too many branches of an app in development at once that might conflict with each other.
Continous Delivery/Deployment ( CD )
It automates the release of the validated code to a repository. It makes sure the codebase is always ready for deployment to a production environment at minimal effort.
Setting up Github Actions
To use github actions, you need to create this folder .github/workflows in your projects root folder. Then create a file_name.yml file which will contain the commands to run our CI/CD pipeline.
The created file will contain the following contents:
name: Android CI
# This workflow is triggered on pushes to the repository.
on: [push, pull_request]
jobs:
build:
# This job will run on windows virtual machine.
#others include ubuntu-latest and macos-latest
runs-on: windows-latest
steps:
# The branch or tag ref that triggered the workflow will be checked out.
# https://github.com/actions/checkout
- uses: actions/checkout@v1
# Setup the flutter environment.
- uses: subosito/flutter-action@v1
with:
channel: 'stable' # 'dev', 'alpha', default to: 'stable'
# flutter-version: '1.12.x' # you can also specify exact version of flutter
#set up java environment
- uses: actions/setup-java@v2
with:
distribution: 'zulu' # Mandatory
java-version: '11' # Mandatory
- run: flutter doctor -v
- run: flutter clean
- run: flutter pub get
- run: flutter format .
- run: flutter analyze
- run: flutter test
- run: flutter build apk --release
- uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/flutter-apk/*.apk"
allowUpdates: true
tag: release
token: $
This action checks-out your repository , so your workflow can access it and work with the code base.
Sets up the flutter environment for use in GitHub Actions.
Downloads and sets up the requested version of Java. The inputs java-version and distribution are mandatory.
This action will create a GitHub release and upload an artifact to it. You must provide a tag or the action will fail.
You can create multiple .yml files in the folder to cater for different scenarios and environment. In our case we can add an IOS platform deployment file.
Build for IOS
name: IOS CI
# This workflow is triggered on pushes to the repository.
on: [push, pull_request]
jobs:
build:
runs-on: macos-latest
steps:
# The branch or tag ref that triggered the workflow will be checked out.
# https://github.com/actions/checkout
- uses: actions/checkout@v1
# Setup the flutter environment.
- uses: subosito/flutter-action@v1
with:
channel: 'stable' # 'dev', 'alpha', default to: 'stable'
architecture: x64
- run: flutter doctor -v
- run: flutter clean
- run: flutter pub get
- run: flutter pub run build_runner build --delete-conflicting-outputs
- run: flutter format .
- run: flutter analyze
- run: flutter test
Build for Windows
name: Windows CI
# This workflow is triggered on pushes to the repository.
on: [push, pull_request]
jobs:
build:
# This job will run on windows virtual machine
runs-on: windows-latest
steps:
# The branch or tag ref that triggered the workflow will be checked out.
# https://github.com/actions/checkout
- uses: actions/checkout@v1
# Setup the flutter environment.
- uses: subosito/flutter-action@v1
with:
channel: 'stable' # 'dev', 'alpha', default to: 'stable'
- run: flutter doctor -v
- run: flutter config --enable-windows-desktop
- run: flutter clean
- run: flutter pub get
- run: flutter pub run build_runner build --delete-conflicting-outputs
- run: flutter format .
- run: flutter analyze
- run: flutter test
- run: flutter build windows --release
With that you have a fully fledged seamless Continous Integration and Continous Deployment environment for your flutter project.
Bye Bye Folks..πππ Happy Codingππ