了解如何使用 EAS Workflows 自动化你的 React Native CI/CD 开发和发布流程。
构建、提交、更新等都是向用户交付应用的一部分。EAS 工作流由一系列作业组成,可帮助你和你的团队完成工作。使用工作流程,你可以构建项目,运行端到端测试,将该构建提交到应用商店,然后在提交完成后运行自定义脚本。由于每个作业都可以有先决条件和条件,因此你可以为 React Native 项目自动化你和你的团队的 CI/CD。
¥Builds, submissions, updates, and more are all a part of delivering your app to users. EAS Workflows consist of a sequence of jobs, which help you and your team get things done. With workflows, you can build your project, run end-to-end tests, submit that build to the app stores, and then run custom scripts after the submission is complete. Since each job can have prerequisites and conditionals, you can automate your and your team's CI/CD for your React Native project.
Learn how to automate some of the most common processes that every app development team must tackle: creating development builds, publishing preview updates, and deploying to production.
EAS 工作流旨在帮助你和你的团队发布你的应用。它预先配置了预打包的作业类型,可以构建、提交、更新、运行 Maestro 测试等。所有作业类型都在 EAS 上运行,因此你只需管理一组 YAML 文件,并且作业运行的所有工件都将出现在 expo.dev 上。
¥EAS Workflows are designed to help you and your team release your app. It comes preconfigured with pre-packaged job types that can build, submit, update, run Maestro tests, and more. All job types run on EAS, so you'll only have to manage one set of YAML files, and all the artifacts from your job runs will appear on expo.dev.
其他 CI 服务(如 CircleCI 和 GitHub Actions)更加通用,并且能够执行比工作流更多的操作。但是,这些服务还要求你更多地了解每个作业的实现。虽然在某些情况下这是必要的,但工作流程通过预先打包应用开发者最基本的作业类型来帮助你快速完成常见任务。此外,工作流旨在为你提供最快的云机器来完成手头的任务,我们会不断为你更新这些。
¥Other CI services, like CircleCI and GitHub Actions, are more generalized and have the ability to do more than workflows. However, those services also require you to understand more about the implementation of each job. While that is necessary in some cases, workflows help you get common tasks done quickly by pre-packaging the most essential types of jobs for app developers. In addition, workflows are designed to provide you with the fastest possible cloud machine for the task at hand, and we're constantly updating those for you.
EAS 工作流非常适合与你的 Expo 应用相关的操作,而其他 CI/CD 服务将为其他类型的工作流提供更好的体验。
¥EAS Workflows are great for operations related to your Expo apps, while other CI/CD services will provide a better experience for other types of workflows.
¥Set up your project
如果你还没有,你需要创建一个项目并将其与 EAS 同步:
¥If you haven't already, you'll need to create a project and sync it with EAS:
你可以使用以下命令创建一个新项目:
¥You can create a new project with the following command:
-
npx create-expo-app@latest
创建项目后,使用你的账户登录:
¥Once you've created the project, login with your account:
-
npx eas-cli@latest login
最后,将你本地的项目与 EAS 链接:
¥Finally, link the project you have locally with EAS:
-
npx eas-cli@latest init
¥Configure your project
EAS 工作流需要链接到你的 EAS 项目的 GitHub 存储库才能运行。你可以使用以下步骤将 GitHub 存储库链接到你的 EAS 项目:
¥EAS Workflows require a GitHub repository that's linked to your EAS project to run. You can link a GitHub repo to your EAS project with the following steps:
导航到项目的 GitHub 设置。
¥Navigate to your project's GitHub settings.
按照 UI 安装 GitHub 应用。
¥Follow the UI to install the GitHub app.
选择与 Expo 项目匹配的 GitHub 存储库并连接它。
¥Select the GitHub repository that matches the Expo project and connect it.
¥Write a workflow
首先,在项目的根目录下创建一个名为 .eas/workflows 的目录,其中包含一个 YAML 文件。例如:.eas/workflows/hello-world.yml.
¥First, create a directory named .eas/workflows at the root of your project with a YAML file inside of it. For example: .eas/workflows/hello-world.yml.
现在我们已准备好编写 hello-world.yml 的内容。每个工作流程由三个顶层元素组成:
¥Now we're ready to write the contents of hello-world.yml. Each workflow consists of three top-level elements:
name
:定义工作流的名称。例如:"Hello World"
¥name
: defines the name of the workflow. For example: "Hello World"
on
:定义何时触发此工作流。例如,将新提交推送到 GitHub 分支时。
¥on
: defines when this workflow should be triggered. For example, when pushing a new commit to a GitHub branch.
jobs
:可以依赖和传递数据的作业序列彼此之间。例如:运行单元测试的作业,然后运行将你的项目构建到应用中的作业。
¥jobs
: a sequence of jobs which can depend on and pass data between each other. For example: a job that runs a unit test followed by a job that builds your project into an app.
以下是打印 "Hello, world" 的工作流程示例:
¥Here's an example of a workflow that prints "Hello, world":
name: Hello World
on:
push:
branches: ['*']
jobs:
Hello World:
steps:
- run: echo "Hello, World"
以下是另一个示例,它在每次推送到每个分支时创建并提交项目的 iOS 构建。这类似于运行 eas build --platform ios --profile production --auto-submit
:
¥Here's another example that creates and submits an iOS build of a project on every push to every branch. This is similar to running eas build --platform ios --profile production --auto-submit
:
name: Release iOS app
on:
push:
branches: ['*']
jobs:
build:
type: build
params:
platform: ios
profile: production
submit:
needs: [build]
type: submit
params:
build_id: ${{ needs.build.outputs.build_id }}
下载 Expo 工具 VS Code 扩展 以获取工作流文件的描述和自动补齐。
¥Run your workflow
一旦你有了工作流文件并且你的项目连接到 Expo 的 GitHub 应用,你就可以通过将提交推送到你的 GitHub 存储库来触发你的工作流程。要运行工作流,你需要确保满足你在工作流中定义的触发器(用 on
定义)。
¥Once you have a workflow file and your project is connected to Expo's GitHub app, you can trigger your workflow by pushing a commit to your GitHub repository. For the workflow to run, you'll need to make sure the trigger (defined with on
) you defined in your workflow is met.
或者,你可以通过运行以下命令手动触发工作流程:
¥Alternatively, you can trigger a workflow manually by running the following command:
-
npx eas-cli@latest workflow:run .eas/workflows/<your-workflow-file>.yml
完成后,你可以看到你的工作流程在项目的 工作流程页面 上运行。
¥Once you do, you can see your workflow running on your project's workflows page.
有反馈或功能请求吗?请发送电子邮件至 workflows@expo.dev。
¥Got feedback or feature requests? Send us an email at workflows@expo.dev.