使用 GitHub Actions 作 Flutter 項目的 CI/CD

GitHub 發佈了可以直接集成在 GitHub 倉庫的 CI/CD 工具, GitHub Actions。而且針對 Public 項目免費提供。java

我嘗試了在 Flutter 項目上使用,相比 travis-ci,目前看來除了方便(不用跳出 github 站外), 尚未其餘優勢發現。git

使用的已有的 Action: github.com/subosito/fl…github

運行截圖

Github Actions

配置文件

發生pull_request 時觸發 test

.github/workflows/check.ymlmacos

name: F4LabCI
on: pull_request

jobs:
  check:
    name: Test on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-java@v1
        with:
          java-version: "12.x"
      - uses: subosito/flutter-action@v1
        with:
          # same with pubspec.yaml
          flutter-version: "1.9.1+hotfix.2"
      - run: flutter pub get
      - run: flutter test --no-pub test/
複製代碼

新建 release-v* tag 時觸發打包, 並上傳到 release

.github/workflows/release.ymlubuntu

name: F4LabCIRelease
on:
  push:
    tags:
      - "release-v*"

jobs:
  release-to-gitHub:
    name: release
    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:
          # same with pubspec.yaml
          flutter-version: "1.9.1+hotfix.2"
      - run: flutter pub get
      - run: flutter analyze --no-pub --no-current-package lib/ test/
      - run: flutter test --no-pub test/
      - run: flutter build apk
      - uses: softprops/action-gh-release@v1
        with:
          files: build/app/outputs/apk/release/app-release.apk
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
複製代碼

總結

  • 總體構建思想和 GitLab-CI, Travis-CI 相似。只是關鍵字可能不同
  • 開源的方便和強大。能夠方便的複用別人提供的 actions
  • 一些功能仍是沒有 Travis-CI、GitLab-CI 方便
  • 本次實驗的倉庫: github.com/stefanJi/Fl…
相關文章
相關標籤/搜索