Evandro Pomatti
Evandro Pomatti

Reputation: 15144

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

Upvotes: 14

Views: 6311

Answers (4)

Adam Cooper
Adam Cooper

Reputation: 8687

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 and then running the flutter build command. The following example runs an Android apk build:

on: push
jobs: 
  build-and-test: 
    runs-on: ubuntu-latest
    steps:
    - name: Clone repository
      uses: actions/checkout@v4
    - name: Set up Flutter
      uses: subosito/flutter-action@v2
      with:
        channel: stable
    # Get flutter packages
    - run: flutter pub get
    # Build :D 
    - run: flutter build apk

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

Upvotes: 16

awaik
awaik

Reputation: 12335

I leave here a link to the production project with the app in the stores.

Maybe it saves time for somebody, I would be glad to have it when I implement it.

  1. Uses secret keys for signing releases.
  2. Create .apks for different flavors.
  3. Add the build number to the files.
  4. Create a GitHub release.

https://github.com/AgoraDesk-LocalMonero/agoradesk-app-foss/blob/main/.github/workflows/build_from_tags_ci.yml

Upvotes: 0

Max Weber
Max Weber

Reputation: 1088

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

Upvotes: 3

Evandro Pomatti
Evandro Pomatti

Reputation: 15144

@Rezwan provided the link to the image I was looking for.

I'm still not able to run it due to the following issues:

https://github.com/cirruslabs/docker-images-flutter/issues/27

GitHub Actions workflow error: Cannot create file, path = '/github/home/.flutter'

Upvotes: 0

Related Questions