Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build Flutter in GitHub Actions CI/CD

I'm trying out GitHub Actions to build my Flutter app but I don't know which container image to choose from.

Is there a trusted container image that I can use for Flutter?

What are the adjustments I need to make so that the Flutter SDK is available during my build step?

Run flutter pub get


/__w/_temp/46389e95-36bc-464e-ab34-41715eb4dccb.sh: 1: /__w/_temp/46389e95-36bc-464e-ab34-41715eb4dccb.sh: flutter: not found
##[error]Process completed with exit code 127.

I adapted the dart.yml file generated by GitHub Actions to look like this:

name: Dart CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    container:
      image:  google/dart:latest

    steps:
    - uses: actions/checkout@v1
    - name: Install dependencies
      run: flutter pub get
    - name: Run tests
      run: flutter test
like image 469
Evandro Pomatti Avatar asked Sep 05 '19 14:09

Evandro Pomatti


2 Answers

You don't need to use a flutter specific container, there is a Flutter Action available that runs on the default Windows, Linux and macOS containers.

This means that building your flutter app is as simple as using the action (you will also need the Java action) and then running the flutter build command. The following example runs an aot build:

on: push
jobs: 
  build-and-test: 
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1 
    # The flutter action needs java so include it
    - uses: actions/setup-java@v1
      with:
        java-version: '12.x'
    # Include the flutter action
    - uses: subosito/flutter-action@v1
      with:
        channel: 'stable'  
    # Get flutter packages
    - run: flutter pub get
    # Build :D 
    - run: flutter build aot

I wrote a blog post about building and testing flutter using actions if you'd like to learn more.

like image 58
Adam Cooper Avatar answered Nov 19 '22 08:11

Adam Cooper


I let my one running without Docker.

You could try to install flutter and run flutter pub get. I used in my example subosito/flutter-action@v1

name: CI

on:
  pull_request:
    branches:
      - development
      - master

jobs:
  test:
    name: Flutter Tests
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-java@v1
        with:
          java-version: '12.x'
      - uses: subosito/flutter-action@v1
        with:
          flutter-version: '1.7.8+hotfix.4'
      - run: flutter doctor
      - run: flutter pub get
      - run: flutter test
like image 20
Max Weber Avatar answered Nov 19 '22 10:11

Max Weber