自动执行 EAS CLI 命令

了解如何使用 EAS 工作流自动执行一系列 EAS CLI 命令。


如果你使用 EAS CLI 来构建、提交和更新你的应用,你可以使用 EAS 工作流来自动化一系列命令。EAS 工作流可以构建、提交和更新你的应用,同时还可以运行其他任务,如 Maestro 测试、单元测试、自定义脚本等。

🌐 If you're using EAS CLI to build, submit, and update your app, you can automate sequences of commands with EAS Workflows. EAS Workflows can build, submit, and update your app, while also running other jobs like Maestro tests, unit tests, custom scripts, and more.

下面你将了解如何设置项目以使用 EAS 工作流,然后是 EAS CLI 命令的常用示例以及如何使用 EAS 工作流运行它们。

🌐 Below you'll find how to set up your project to use EAS Workflows, followed by common examples of EAS CLI commands and how you can run them using EAS Workflows.

配置你的项目

🌐 Configure your project

EAS 工作流可选择支持与你的 EAS 项目关联的 GitHub 仓库来运行。本指南假设已关联 GitHub 仓库,并演示了如何在推送到 GitHub 上的特定分支时触发工作流。你可以通过以下步骤将 GitHub 仓库关联到你的 EAS 项目:

🌐 EAS Workflows optionally supports a GitHub repository that's linked to your EAS project to run. This guide assumes a GitHub repository is linked, and shows how to trigger workflows when pushing to specific branches on GitHub. You can link a GitHub repo to your EAS project with the following steps:

  • 导航到你项目的 GitHub 设置
  • 按照 UI 安装 GitHub 应用。
  • 选择与 Expo 项目匹配的 GitHub 存储库并连接它。

创建构建

🌐 Creating builds

你可以使用 EAS CLI 的 eas build 命令来构建你的项目。要使用 production 构建配置生成 iOS 构建,可以运行以下 EAS CLI 命令:

🌐 You can make a build of your project using EAS CLI with the eas build command. To make an iOS build with the production build profile, you could run the following EAS CLI command:

Terminal
eas build --platform ios --profile production

要将此命令写成工作流,请在项目根目录下创建一个名为 .eas/workflows/build-ios-production.yml 的工作流文件。

🌐 To write this command as a workflow, create a workflow file named .eas/workflows/build-ios-production.yml at the root of your project.

build-ios-production.yml 中,你可以使用以下工作流程来启动一个使用 production 构建配置生成 iOS 构建的任务。

🌐 Inside build-ios-production.yml, you can use the following workflow to kick off a job that creates an iOS build with the production build profile.

.eas/workflows/build-ios-production.yml
name: iOS production build on: push: branches: ['main'] jobs: build_ios: name: Build iOS type: build params: platform: ios profile: production

一旦你有了这个工作流文件,你可以通过向 main 分支提交一个 commit 来启动它,或者通过运行以下 EAS CLI 命令来启动:

🌐 Once you have this workflow file, you can kick it off by pushing a commit to the main branch, or by running the following EAS CLI command:

Terminal
eas workflow:run build-ios-production.yml

你可以提供参数来进行 Android 构建,或使用其他构建配置文件。通过构建作业文档了解有关构建作业参数的更多信息。

🌐 You can provide parameters to make Android builds or use other build profiles. Learn more about build job parameters with the build job documentation.

提交构建

🌐 Submitting builds

你可以使用 EAS CLI 的 eas submit 命令将你的应用提交到应用商店。要提交 iOS 应用,你可以运行以下 EAS CLI 命令:

🌐 You can submit your app to the app stores using EAS CLI with the eas submit command. To submit an iOS app, you could run the following EAS CLI command:

Terminal
eas submit --platform ios

要将此命令写成工作流,请在项目根目录下创建一个名为 .eas/workflows/submit-ios.yml 的工作流文件。

🌐 To write this command as a workflow, create a workflow file named .eas/workflows/submit-ios.yml at the root of your project.

submit-ios.yml 中,你可以使用以下工作流来启动提交 iOS 应用的任务。

🌐 Inside submit-ios.yml, you can use the following workflow to kick off a job that submits an iOS app.

.eas/workflows/submit-ios.yml
name: Submit iOS app on: push: branches: ['main'] jobs: submit_ios: name: Submit iOS type: submit params: platform: ios

一旦你有了这个工作流文件,你可以通过向 main 分支提交一个 commit 来启动它,或者通过运行以下 EAS CLI 命令来启动:

🌐 Once you have this workflow file, you can kick it off by pushing a commit to the main branch, or by running the following EAS CLI command:

Terminal
eas workflow:run submit-ios.yml

你可以提供参数以提交到其他平台或使用其他提交配置文件。通过提交作业文档了解有关提交作业参数的更多信息。

🌐 You can provide parameters to submit other platforms or use other submit profiles. Learn more about submit job parameters with the submit job documentation.

发布更新

🌐 Publishing updates

你可以使用 EAS CLI 的 eas update 命令来更新你的应用。要更新你的应用,你可以运行以下 EAS CLI 命令:

🌐 You can update your app using EAS CLI with the eas update command. To update your app, you could run the following EAS CLI command:

Terminal
eas update --auto

要将此命令写成工作流,请在项目根目录下创建一个名为 .eas/workflows/publish-update.yml 的工作流文件。

🌐 To write this command as a workflow, create a workflow file named .eas/workflows/publish-update.yml at the root of your project.

publish-update.yml 中,你可以使用以下工作流程来启动一个发送空中更新的任务。

🌐 Inside publish-update.yml, you can use the following workflow to kick off a job that sends and over-the-air update.

.eas/workflows/publish-update.yml
name: Publish update on: push: branches: ['*'] jobs: update: name: Update type: update params: branch: ${{ github.ref_name || 'test'}}

获得此工作流文件后,你可以通过向任何分支推送提交或运行以下 EAS CLI 命令来启动它:

🌐 Once you have this workflow file, you can kick it off by pushing a commit to any branch, or by running the following EAS CLI command:

Terminal
eas workflow:run publish-update.yml

你可以提供参数来更新特定的分支或渠道,并配置更新消息。通过更新作业文档了解有关更新作业参数的更多信息。

🌐 You can provide parameters to update specific branches or channels, and configure the update's message. Learn more about update job parameters with the update job documentation.

下一步

🌐 Next step

工作流是自动化你的开发和发布流程的强大方式。了解如何使用工作流示例指南创建开发版本、发布预览更新以及创建生产版本:

🌐 Workflows are a powerful way to automate your development and release processes. Learn how to create development builds, publish preview updates, and create production builds with the workflows examples guide:

工作流示例

了解如何使用工作流创建开发版本、发布预览更新以及创建生产版本。