Skip to content

Flutter CI

Flutter CI #4022

Workflow file for this run

name: Flutter CI
on:
pull_request:
branches:
- main
paths:
- "mobile-app/**"
- ".github/**"
push:
branches:
- main
schedule:
- cron: "0 0 * * *"
jobs:
flutter_test:
name: flutter test
defaults:
run:
working-directory: ./mobile-app
runs-on: ubuntu-latest
steps:
- name: Remove unused software
working-directory: /
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
echo "Free space:"
df -h /
- name: Checkout files
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Gradle cache
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3
with:
gradle-version: 7.6.3
- name: Setup Java 17
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4
with:
distribution: "temurin"
java-version: "17"
- name: AVD cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-33
- name: Ceate AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@77986be26589807b8ebab3fde7bbf5c60dabec32 # v2
with:
api-level: 33
target: google_apis
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- name: Setup Flutter 3.24.x
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # v2
with:
flutter-version: "3.24.x"
channel: "stable"
cache: true
cache-key: flutter-3.24.x
cache-path: ${{ runner.tool_cache }}/flutter
- name: Create .env file
run: |
echo "HASHNODE_PUBLICATION_ID=$HASHNODE_PUBLICATION_ID" > .env
echo "ALGOLIAAPPID=$ALGOLIA_APP_ID" >> .env
echo "ALGOLIAKEY=$ALGOLIA_KEY" >> .env
echo "AUTH0_DOMAIN=$AUTH0_DOMAIN" >> .env
echo "AUTH0_CLIENT_ID=$AUTH0_CLIENT_ID" >> .env
env:
HASHNODE_PUBLICATION_ID: ${{ secrets.HASHNODE_PUBLICATION_ID }}
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_KEY: ${{ secrets.ALGOLIA_KEY }}
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
AUTH0_CLIENT_ID: ${{ secrets.AUTH0_CLIENT_ID }}
- name: Install packages
run: flutter pub get
- name: Analyze code
run: flutter analyze
- name: Run unit tests
run: |
cd test
flutter test unit
flutter test services
- name: Run tests in emulator
uses: reactivecircus/android-emulator-runner@77986be26589807b8ebab3fde7bbf5c60dabec32 # v2
with:
api-level: 33
target: google_apis
arch: x86_64
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: cd mobile-app && if adb shell pm list packages | grep -q org.freecodecamp; then adb uninstall org.freecodecamp; fi && dart integration_test_runner.dart
- name: Upload screenshots
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
if: always()
with:
name: screenshots
path: mobile-app/screenshots/
if-no-files-found: error
retention-days: 7