Skip to content

Flutter CI

Flutter CI #3348

Workflow file for this run

name: Flutter CI
on:
pull_request:
branches:
- main
paths:
- "mobile-app/**"
push:
branches:
- main
schedule:
- cron: "0 0 * * *"
jobs:
flutter_test:
name: flutter test
defaults:
run:
working-directory: ./mobile-app
runs-on: macos-latest
steps:
- name: Checkout files
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- name: Setup Java 11
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3
with:
distribution: "temurin"
java-version: "11"
cache: "gradle"
- name: AVD cache
uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-31
- name: Ceate AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # v2
with:
api-level: 31
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.16.x
uses: subosito/flutter-action@1c5eb12d812966ca84680edc38353a0851c8fd56 # v2
with:
flutter-version: "3.16.x"
channel: "stable"
cache: true
cache-key: flutter-3.16.x
cache-path: ${{ runner.tool_cache }}/flutter
- name: Create .env file
run: |
echo "NEWSURL=https://www.freecodecamp.org/news/ghost/api/v3/content/" > .env
echo "NEWSKEY=$GHOST_NEWSKEY" >> .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:
GHOST_NEWSKEY: ${{ secrets.GHOST_NEWSKEY }}
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@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # v2
with:
api-level: 31
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@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
if: always()
with:
name: screenshots
path: mobile-app/screenshots/
if-no-files-found: error
retention-days: 7