【问题标题】:How to build Flutter in GitHub Actions CI/CD如何在 GitHub Actions CI/CD 中构建 Flutter
【发布时间】:2020-01-08 12:19:43
【问题描述】:

我正在尝试使用 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

【问题讨论】:

标签: flutter github-actions


【解决方案1】:

@Rezwan 提供了我正在寻找的图片的链接。

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

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

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

【讨论】:

    【解决方案2】:

    我让我的一个在没有 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
    

    【讨论】:

    • 这是一个不错的选择。我将暂时保留该图像,但将在下一个项目中对其进行测试。
    【解决方案3】:

    您不需要使用特定于 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 关于使用动作构建和测试颤振的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-23
      • 2022-10-19
      • 2019-12-29
      • 2023-02-12
      • 1970-01-01
      • 2020-07-01
      • 2021-08-20
      • 2021-05-30
      相关资源
      最近更新 更多