如何在GitHub Actions CI / CD中构建Flutter

时间:2019-09-05 14:56:13

标签: flutter github-actions

我正在尝试使用GitHub Actions构建我的Flutter应用程序,但是我不知道要选择哪个容器映像。

是否有可用于Flutter的受信任的容器映像?

我需要进行哪些调整,才能在构建步骤中使用Flutter SDK?

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.

我修改了GitHub Actions生成的dart.yml文件,如下所示:

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

3 个答案:

答案 0 :(得分:1)

我让我的一个没有Docker运行。

您可以尝试安装flutter并运行flutter pub get。我在示例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

答案 1 :(得分:1)

您无需使用特定于flutter的容器,有一个Flutter Action可在默认Windows,Linux和macOS容器上运行。

这意味着构建flutter应用程序就像使用动作(您还将需要Java动作)然后运行flutter build命令一样简单。以下示例运行aot构建:

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

如果您想了解更多信息,我写了blog post,内容涉及使用动作来构建和测试抖动。

答案 2 :(得分:0)

@Rezwan提供了我想要的图像的链接。

由于以下问题,我仍然无法运行它:

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

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