How to build Flutter in GitHub Actions CI/CD

蓝咒 提交于 2019-12-24 03:52:09

问题


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

回答1:


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.




回答2:


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



回答3:


@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'



来源:https://stackoverflow.com/questions/57808152/how-to-build-flutter-in-github-actions-ci-cd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!