1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Integrating Patrol with GitHub Actions for Automated Flutter Integration Tests

Discussão em 'Mobile' iniciado por Stack, Novembro 9, 2024 às 18:32.

  1. Stack

    Stack Membro Participativo

    I am working on setting up a continuous integration pipeline with automated integration tests for a Flutter application. My goal is to run the tests using Patrol and subsequently deploy to Firebase Test Lab. However, I'm encountering issues with building the test APK using Patrol in the GitHub Actions workflow.

    I have configured my workflow to set up the environment, install dependencies, and build the test APK for Android and iOS. Despite multiple attempts and different configurations, the build process fails, and I have not been able to efficiently run an emulator within the pipeline.

    on:
    push:
    branches: [ staging ]
    pull_request:
    branches: [ staging ]
    workflow_dispatch:

    jobs:
    setup:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repository
    uses: actions/checkout@v2

    - name: Set Git user info
    run: |

    - name: Install Google Cloud SDK
    run: |
    curl -sSL https://sdk.cloud.google.com | bash
    echo "$HOME/google-cloud-sdk/bin" >> $GITHUB_PATH
    - name: Decode and Write Service Account to File
    run: |
    echo "${{ secrets.KEY}}" | base64 -d > /tmp/temp.json
    echo "GOOGLE_APPLICATION_CREDENTIALS=/tmp/temp.json" >> $GITHUB_ENV
    - name: Extract Project ID from Service Account
    run: |
    PROJECT_ID=$(jq -r '.project_id' /tmp/temp.json)
    echo "PROJECT_ID=$PROJECT_ID" >> $GITHUB_ENV
    - name: Install Firebase CLI
    run: curl -sL firebase.tools | bash

    - name: Install Google Cloud SDK
    run: |
    curl -sSL https://sdk.cloud.google.com | bash
    echo "$HOME/google-cloud-sdk/bin" >> $GITHUB_PATH

    - name: Authenticate with Google Cloud
    run: |
    gcloud auth activate-service-account --key-file=/tmp/temp.json
    gcloud config set project "$PROJECT_ID"
    - name: Retrieve and Mask all GCP Secrets
    run: |
    secrets=$(gcloud secrets list --format='get(name)')
    for secret_full_name in $secrets; do
    secret_name=${secret_full_name##*/}
    secret_value=$(gcloud secrets versions access latest --secret="$secret_name" --project="$PROJECT_ID" --quiet)
    echo "::add-mask::***"
    echo "$secret_name"='***' >> $GITHUB_ENV
    done





    android-tests:
    needs: setup
    runs-on: ubuntu-latest
    steps:
    - name: Checkout Repository
    uses: actions/checkout@v2

    - name: Set up Flutter
    uses: subosito/flutter-action@v1
    with:
    flutter-version: '3.16.5'

    - name: Install Dependencies
    run: flutter pub get

    - name: Install Patrol
    run: flutter pub global activate patrol

    - name: Build Android App and Test APK with Patrol
    run: patrol build android -t integration_test/example_test.dart --flavor production

    - name: Run Tests on Firebase Test Lab (Android)
    run: |
    gcloud firebase test android run \
    --type instrumentation \
    --app build/app/outputs/apk/debug/app-debug.apk \
    --test build/app/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
    --device model="nexus6", version="30", locale=en, orientation=portrait \
    --timeout 10m \
    --results-bucket="patrol_runs" \
    --use-orchestrator \
    --environment-variables clearPackageData=true
    - name: Fastlane Android Deployment
    run: fastlane android deploy

    ios-tests:
    needs: setup
    runs-on: macos-latest
    steps:
    - name: Checkout Repository
    uses: actions/checkout@v2

    - name: Set up Flutter
    uses: subosito/flutter-action@v1
    with:
    flutter-version: '3.16.5'

    - name: Install Dependencies
    run: flutter pub get

    - name: Install Patrol
    run: flutter pub global activate patrol

    - name: Build iOS App for Testing
    run: patrol build ios --target integration_test/example_test.dart --release

    - name: Package iOS Tests
    run: |
    pushd build/ios_integ/Build/Products
    zip -r ios_tests.zip Release-iphoneos Runner_iphoneos16.2-arm64.xctestrun
    popd
    - name: Run Tests on Firebase Test Lab (iOS)
    run: |
    gcloud firebase test ios run \
    --test build/ios_integ/Build/Products/ios_tests.zip \
    --device model=iphone13, version=16.2, locale=en_US, orientation=portrait \
    --timeout 10m \
    --results-bucket="patrol_runs"
    - name: Fastlane iOS Deployment
    run: fastlane ios deploy


    I attempted to use an emulator build directly in the pipeline, but it proved to be inefficient. I'm now exploring how to best utilize Firebase Test Lab for running the tests.

    I would appreciate any guidance on the following points:

    How can I successfully build the test APK with Patrol in a GitHub Actions workflow?

    What is the most efficient way to run these tests on Firebase Test Lab?

    Are there best practices or recommended approaches for setting up this type of CI/CD pipeline for a Flutter app?

    Continue reading...

Compartilhe esta Página