From 6a57dd172b989190c418df1a406f09ebe7f3e502 Mon Sep 17 00:00:00 2001 From: yangliang Date: Wed, 6 Mar 2024 17:02:50 +0800 Subject: [PATCH] add:flutter ci --- .github/workflows/dart.yml | 103 +++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 27 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 23ad8ff..dc44c96 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -1,42 +1,91 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -name: Dart +# 这是GitHub Actions的工作流配置文件 +# 当你推送代码或者创建标签时,这个工作流就会被触发 +name: CI/CD with Flutter on: + # 当代码被推送到任意分支时,或者有新的Pull Request时,触发工作流 push: - branches: [ "main" ] + branches: [ main ] pull_request: - branches: [ "main" ] + branches: [ main ] -jobs: - build: + tags: + - 'v*' # 当推送的标签名以v开头时,触发工作流,这常用于发布新版本 + +jobs: # 定义了一系列的工作,这些工作可以并行执行,也可以按照依赖顺序执行 + build_and_test: # 这是第一个工作的名称,你可以自行定义 + # 工作运行的环境 runs-on: ubuntu-latest + # 工作中的步骤,步骤会按照从上到下的顺序执行 + steps: + - name: Checkout code # 第一步,检出代码 + uses: actions/checkout@v2 + + - name: Setup Flutter # 第二步,设置Flutter环境 + uses: subosito/flutter-action@v1 + with: + flutter-version: '2.2.3' # 指定Flutter版本号 + + - name: Install dependencies # 第三步,安装依赖 + run: flutter pub get + - name: Run tests # 第四步,运行测试 + run: flutter test + + - name: Build APK # 第五步,构建APK + run: flutter build apk + + - name: Archive production artifacts # 第六步,归档产物,你可以在Actions的界面下载到这个文件 + uses: actions/upload-artifact@v2 + with: + name: release-apk + path: build/app/outputs/flutter-apk/app-release.apk + build_ios: + runs-on: macos-latest # 注意这里选择了macOS环境 steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v2 - # Note: This workflow uses the latest stable version of the Dart SDK. - # You can specify other versions if desired, see documentation here: - # https://github.com/dart-lang/setup-dart/blob/main/README.md - # - uses: dart-lang/setup-dart@v1 - - uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603 + - name: Setup Flutter + uses: subosito/flutter-action@v1 + with: + flutter-version: '2.2.3' - name: Install dependencies - run: dart pub get + run: flutter pub get + + - name: Build iOS + run: flutter build ios --release --no-codesign # 构建iOS版本 - # Uncomment this step to verify the use of 'dart format' on each commit. - # - name: Verify formatting - # run: dart format --output=none --set-exit-if-changed . + - name: Archive iOS + uses: actions/upload-artifact@v2 + with: + name: release-ios + path: build/ios/iphoneos/Runner.app # iOS应用的路径 + + deploy: # 这是第二个工作的名称,你可以自行定义 + # 这个工作需要在build_and_test工作成功后才会运行 + needs: build_and_test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Flutter + uses: subosito/flutter-action@v1 + with: + flutter-version: '2.2.3' + + - name: Install dependencies + run: flutter pub get - # Consider passing '--fatal-infos' for slightly stricter analysis. - - name: Analyze project source - run: dart analyze + - name: Build APK + run: flutter build apk - # Your project will need to have tests in test/ and a dependency on - # package:test for this step to succeed. Note that Flutter projects will - # want to change this to 'flutter test'. - - name: Run tests - run: dart test + - name: Deploy to Release # 最后,部署到你的发布页面或者服务器 + # 这个部分取决于你使用什么方式来发布你的应用 + run: | + VERSION=${GITHUB_REF#refs/tags/} + echo "Deploying version $VERSION" + # 这里添加你的部署代码