add:flutter ci #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 这是GitHub Actions的工作流配置文件 | |
# 当你推送代码或者创建标签时,这个工作流就会被触发 | |
name: CI/CD with Flutter | |
on: | |
# 当代码被推送到任意分支时,或者有新的Pull Request时,触发工作流 | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
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: '3.19.2' # 指定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: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v1 | |
with: | |
flutter-version: '3.19.2' | |
- name: Install dependencies | |
run: flutter pub get | |
- name: Build iOS | |
run: flutter build ios --release --no-codesign # 构建iOS版本 | |
- 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: '3.19.2' | |
- name: Install dependencies | |
run: flutter pub get | |
- name: Build APK | |
run: flutter build apk | |
- name: Deploy to Release # 最后,部署到你的发布页面或者服务器 | |
# 这个部分取决于你使用什么方式来发布你的应用 | |
run: | | |
VERSION=${GITHUB_REF#refs/tags/} | |
echo "Deploying version $VERSION" | |
# 这里添加你的部署代码 |