Skip to content

refactor: update API levels in GitHub Actions workflow and enhance RE… #230

refactor: update API levels in GitHub Actions workflow and enhance RE…

refactor: update API levels in GitHub Actions workflow and enhance RE… #230

Workflow file for this run

name: Flutter CI
# Trigger CI on (1) pull requests and (2) pushes to main branch
on:
pull_request:
push:
branches:
- main
# Cancel previous workflows for the same pull request to save resources
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
# Grant read-all permissions to this workflow
permissions: read-all
jobs:
# Job for linting and formatting Dart code
lint:
name: "Lint and Format Dart Code"
runs-on: ubuntu-latest
steps:
# Checkout the repository
- uses: actions/checkout@v4
# Install Flutter SDK
- uses: subosito/flutter-action@v2
with:
channel: "stable"
cache: true
# Setup Melos for workspace management
- uses: bluefireteam/melos-action@v3
with:
run-bootstrap: true
enforce-lockfile: true
# Format code and check for issues
- name: Run Dart format
run: dart format --set-exit-if-changed .
- name: Analyze Dart code
run: dart analyze
# Build the example application across all supported platforms
build-example:
name: 'Build example (${{ matrix.target }}, ${{ matrix.os }})'
runs-on: ${{ matrix.os }}-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- target: android
os: ubuntu
- target: ios
os: macos
- target: macos
os: macos
- target: linux
os: ubuntu
- target: windows
os: windows
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
# iOS and macOS specific setup
- name: Copy ZXing source files for iOS/macOS
if: matrix.target == 'ios' || matrix.target == 'macos'
run: ./scripts/update_ios_macos_src.sh
# Android-specific setup
- name: Setup Java for Android (${{ matrix.target }}, ${{ matrix.os }})'
if: matrix.target == 'android'
uses: actions/setup-java@v4
with:
java-version: 11
distribution: temurin
# Linux-specific setup
- name: Install dependencies for Flutter on Linux (${{ matrix.target }}, ${{ matrix.os }})'
if: matrix.target == 'linux' && matrix.os == 'ubuntu'
run: |
sudo apt update
sudo apt install -y \
cmake dbus libblkid-dev libgtk-3-dev liblzma-dev ninja-build \
pkg-config xvfb network-manager upower
# Install Flutter SDK
- uses: subosito/flutter-action@v2
with:
channel: "stable"
cache: true
# Setup Melos for workspace management
- uses: bluefireteam/melos-action@v3
with:
run-bootstrap: true
enforce-lockfile: true
- name: Build example for ${{ matrix.target }} on ${{ matrix.os }}
shell: bash
run: |
cd example
TARGET=${{ matrix.target }}
case $TARGET in
ios)
flutter build ios --debug --no-codesign
;;
macos)
flutter build macos --debug
;;
android)
flutter build appbundle --debug
;;
linux)
flutter build linux --debug
;;
windows)
flutter build windows --debug
;;
*)
echo "Unknown target: $TARGET"
exit 1
;;
esac
# Integration tests for all platforms except Android (handled separately)
test-example:
name: 'Test example (${{ matrix.target }}, ${{ matrix.os }})'
runs-on: ${{ matrix.os }}-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- target: ios
os: macos
device: iphone
- target: macos
os: macos
device: macos
- target: linux
os: ubuntu
device: linux
- target: windows
os: windows
device: windows
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
# iOS/macOS specific setup
- name: Copy ZXing source files for iOS/macOS
if: matrix.target == 'ios' || matrix.target == 'macos'
run: ./scripts/update_ios_macos_src.sh
# Install Flutter SDK
- uses: subosito/flutter-action@v2
with:
channel: "stable"
cache: true
# Setup Melos
- uses: bluefireteam/melos-action@v3
with:
run-bootstrap: true
enforce-lockfile: true
# Linux-specific dependencies
- name: Install dependencies for Flutter on Linux (${{ matrix.target }}, ${{ matrix.os }})'
if: matrix.target == 'linux' && matrix.os == 'ubuntu'
run: |
sudo apt update
sudo apt install -y \
cmake dbus libblkid-dev libgtk-3-dev liblzma-dev ninja-build \
pkg-config xvfb network-manager upower
# Launch iOS Simulator for iOS tests
- name: Launch iOS Simulator for ${{ matrix.target }}
if: matrix.target == 'ios'
run: |
simulator_id=$(xcrun simctl create iphone-zxing \
com.apple.CoreSimulator.SimDeviceType.iPhone-15 \
com.apple.CoreSimulator.SimRuntime.iOS-17-5)
xcrun simctl boot ${simulator_id}
# Run tests
- name: Run tests for ${{ matrix.target }} on ${{ matrix.os }}
shell: bash
run: |
cd ./example
if [ "${{ matrix.target }}" == "linux" ]; then
xvfb-run flutter test integration_test -d "${{ matrix.device }}" --verbose
else
flutter test integration_test -d "${{ matrix.device }}" --verbose
fi
# Integration tests on Android emulator
test-example-android:
name: 'Test example on Android API level ${{ matrix.api-level }} (${{ matrix.os }})'
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
api-level: [21, 29]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Java for Android (${{ matrix.target }}, ${{ matrix.os }})'
uses: actions/setup-java@v4
with:
java-version: 11
distribution: temurin
# Install Flutter SDK
- uses: subosito/flutter-action@v2
with:
channel: "stable"
cache: true
# Setup Melos
- uses: bluefireteam/melos-action@v3
with:
run-bootstrap: true
enforce-lockfile: true
# Enable KVM for Android emulators
- name: Enable KVM for Android emulators (${{ matrix.api-level }})'
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
# Gradle cache
- uses: gradle/actions/setup-gradle@v4
- name: Setup AVD actions/cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}
- name: Create and cache AVD snapshot
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
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."
# Create and run Android emulator
- name: Run tests on Android API level ${{ matrix.api-level }}
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
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: |
flutter devices
cd ./example && flutter test integration_test --verbose