I am trying to setup CI for my flutter project on gitlab but I don't understand where to start or what I have to do. Can anyone help me? Thanks
I suggest to setup your GitLab CI integration for flutter treating the android
and ios
project folder by their own in order to build your APK
or IPA
or doing test with your GitLab CI.
To start having a clue on how to setup a CI for Android
and iOS
projects on GitLab
I'll suggest you these readings:
Android:
iOS
- https://about.gitlab.com/2016/03/10/setting-up-gitlab-ci-for-ios-projects/
- https://medium.com/flawless-app-stories/how-to-set-up-gitlab-continuous-integration-for-ios-projects-without-a-hustle-53c2b642c90f
UPDATE: using Fastlane
I've the above solutions running on my apps and so I know they work. But I've found these interesting official docs for flutter using Fastlane
(they seem quite easier):
- https://flutter.io/docs/deployment/fastlane-cd
- https://docs.fastlane.tools/best-practices/continuous-integration/gitlab/
So I suggest to give them a try too.
.gitlab-ci.yml in your repo root:
stages:
- test
tests:
image: cirrusci/flutter
stage: test
script:
- flutter test
cirrcusci/flutter
is deprecated, but you could use instead: https://hub.docker.com/r/mobiledevops/flutter-sdk-image
stages:
- lint
Flutter analyze:
image: mobiledevops/flutter-sdk-image:3.10.1
stage: lint
script:
- flutter analyze
To start with GitLab CI, a great starting point is the official documentation of GitLab: https://docs.gitlab.com/ee/ci/pipelines/index.html
The main idea is to have a file named .gitlab-ci.yml
at the root of your repository. It has to specify at least one stage. In the following example, I have two stages: test and deploy. The different stages are executed sequentially, meaning that one stage will only start if the previous one has finished and has not fail.
The different stages are composed of jobs. Each job has to be linked to a stage and describe an action that has to be performed during a stage. The different jobs of the same stage are executed in parallel. So if your different tasks depend on each other, you will need to put them in different stages, while you can put them all in the same stage if they are not dependent.
As an example, I will reuse the pipeline available in the documentation of the Odevio (https://odevio.com/) tool that allows to generate iOS flutter apps without owning a Mac: https://github.com/Odevio/Odevio-CICD/blob/master/doc_gitlab_cicd/.gitlab-ci.yml
stages:
- test
- deploy
.flutter_docker_image:
image: "ghcr.io/cirruslabs/flutter:3.16.0"
code_quality-job:
extends: .flutter_docker_image
stage: test
before_script:
- export PATH="$PATH:$HOME/.pub-cache/bin"
- flutter pub global activate dart_code_metrics
script:
- metrics lib -r codeclimate > gl-code-quality-report.json
artifacts:
reports:
codequality: gl-code-quality-report.json
flutter-test-job:
extends: .flutter_docker_image
stage: test
before_script:
- export PATH="$PATH:$HOME/.pub-cache/bin"
script:
- flutter test --coverage
# - lcov --summary coverage/lcov.info
- genhtml coverage/lcov.info --output=coverage
#coverage: '/lines\.*: \d+\.\d+\%/'
artifacts:
name: coverage
paths:
- $CI_PROJECT_DIR/coverage
expire_in: 4 days
deploy-odevio-job:
stage: deploy
image: "ruby:3.1"
environment: production
before_script:
- apt-get update -qy
- apt-get -y install zip unzip
script:
- >
wget -qO - https://raw.githubusercontent.com/Odevio/Odevio-CICD/master/script_cicd.sh |
bash /dev/stdin $ODEVIO_API_KEY -d ./ -t ad-hoc -k AAAA -fv 3.16.0
artifacts:
name: "odevio_ipa_url"
paths:
- ./odevio_ipa_url.txt
expire_in: 30 day
only:
# Depends on your git
- main
- master
Here, we have two stages: test and deploy. The stage test is composed of two jobs: code_quality-job and flutter-test-job. These jobs aims to check the quality of your code before going to the next stage. They use the image "ghcr.io/cirruslabs/flutter:3.16.0".
The next stage is deploy and is composed of only one job: deploy-odevio-job. This job use the image "ruby:3.1" and is launched only when you add changes to your branch master or main. The goal of this job is to use the Odevio tool generate an IPA file, or to publish your app directly to the app store connect. You can see a usage of a repository variable with $ODEVIO_API_KEY
. Such variables can be set in the repository settings or in a team settings.
Hope this helps !
© 2022 - 2024 — McMap. All rights reserved.