Si vous souhaitez utiliser GitLabCI pour vos projet Flutter, voici la base du fichier .gitlab-ci.yml qu’il vous faudras:
Il faut commencer par spécifier une image docker a utiliser:
image: openjdk:8-jdk
Langage du code : YAML (yaml)
Nous déclarons ensuite des variables afin de pouvoir mettre a jour plus facilement:
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.2"
ANDROID_SDK_TOOLS: "4333796"
FLUTTER_VERSION: "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.12.13+hotfix.5-stable.tar.xz"
Langage du code : YAML (yaml)
Nous enchainons avec la description du test, les installtion de flutter, android sdk et autres
test:
before_script:
- apt-get -qq update --yes
- apt-get -qq install --yes wget tar unzip lib32stdc++6 lib32z1 lcov
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -q -d android-sdk-linux android-sdk.zip
- mkdir /root/.android
- touch /root/.android/repositories.cfg
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- export CI='true'
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
- wget --quiet --output-document=flutter-sdk.tar.xz $FLUTTER_VERSION
- tar -xf flutter-sdk.tar.xz
- export PATH=$PATH:$PWD/flutter/bin
- echo flutter.sdk=$PWD/flutter > android/local.properties
- flutter packages get
Langage du code : YAML (yaml)
Puis la partit test en elle même et la creation d’un artefact contenant les resultat de la couverture de code:
script:
- flutter test --coverage
- genhtml coverage/lcov.info --output=coverage
artifacts:
paths:
- coverage/
expire_in: 5 days
Langage du code : YAML (yaml)
Pour finir la partit publication de la couverture des tests dans les GitLab Pages:
pages:
stage: .post
script:
- mkdir public
- rm -Rf public/*
- mv README.md public/README.md
- mv -v coverage/* public/
artifacts:
paths:
- public
only:
- master
Langage du code : YAML (yaml)
Ce qui nous donne au final:
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.2"
ANDROID_SDK_TOOLS: "4333796"
FLUTTER_VERSION: "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.12.13+hotfix.5-stable.tar.xz"
test:
before_script:
- apt-get -qq update --yes
- apt-get -qq install --yes wget tar unzip lib32stdc++6 lib32z1 lcov
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -q -d android-sdk-linux android-sdk.zip
- mkdir /root/.android
- touch /root/.android/repositories.cfg
- echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
- echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
- export ANDROID_HOME=$PWD/android-sdk-linux
- export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
- export CI='true'
- set +o pipefail
- yes | android-sdk-linux/tools/bin/sdkmanager --licenses
- set -o pipefail
- wget --quiet --output-document=flutter-sdk.tar.xz $FLUTTER_VERSION
- tar -xf flutter-sdk.tar.xz
- export PATH=$PATH:$PWD/flutter/bin
- echo flutter.sdk=$PWD/flutter > android/local.properties
- flutter packages get
script:
- flutter test --coverage
- genhtml coverage/lcov.info --output=coverage
artifacts:
paths:
- coverage/
expire_in: 5 days
pages:
stage: .post
script:
- mkdir public
- rm -Rf public/*
- mv README.md public/README.md
- mv -v coverage/* public/
artifacts:
paths:
- public
only:
- master
Langage du code : YAML (yaml)
Un dépot git est disponible: https://gitlab.com/dayo/testgitlabciflutter/ et la couverture de code https://dayo.gitlab.io/testgitlabciflutter/