如何在 GitHub 操作中构建 Flutter CI/CD

How to build Flutter in GitHub Actions CI/CD

我正在尝试 GitHub 构建我的 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 操作生成的 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

@Rezwan 为我正在寻找的图像提供了 link。

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

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

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

我让我的运行宁没有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

您不需要使用特定于 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 关于使用动作构建和测试 flutter 的文章。