This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
运行你的第一个EAS工作流程任务
通过创建工作流文件、任务、触发器,并将它们串联起来,为 Expo 应用学习 EAS 工作流的基础知识。
在这一章里,我们创建第一个 EAS 工作流任务。
🌐 In this chapter, we create our first EAS Workflows job.
学习成果
🌐 Learning outcomes
- 创建并运行一个自定义工作流,在 EAS 仪表板上打印消息
- 设置一个自动触发器,这样每次推送到
main都会运行工作流 - 将多个任务串联起来,让一个任务的输出成为下一个任务的输入
- 在EAS仪表板中查看工作流日志和任务图
工作流文件是如何运作的
🌐 How workflow files work
工作流文件是存储在我们项目的 .eas/workflows/ 目录下的 YAML 文件。每个文件定义了要运行的任务以及每个任务的步骤。
🌐 Workflow files are YAML files stored in our project's .eas/workflows/ directory. Each file defines the jobs to run and the steps each job follows.
一个工作流文件包含一个或多个任务以及一个可选的触发器。运行时,EAS 会读取该文件,配置环境,并在该环境中执行这些任务。
🌐 A workflow file contains one or more jobs and an optional trigger. When it runs, EAS reads the file, provisions the environment, and executes the jobs in that environment.
EAS 工作流程中的工作类型
🌐 Types of jobs in EAS Workflows
EAS 工作流程有两种类型的任务:
🌐 EAS Workflows has two types of jobs:
- 预打包工作: 这个工作使用
type字段。它告诉 EAS 要运行哪个操作,比如build、submit或update。然后 EAS 就会运行为该操作预先配置的步骤。 - 自定义任务: 这种类型的任务使用
steps而不是type字段。我们用run为每一步编写自己的命令。自定义任务让我们可以控制工作流运行时的操作,以及什么时候运行特定命令。
创建我们的第一个工作流程
🌐 Create our first workflow
让我们使用自定义任务创建我们的第一个工作流,并在 EAS 上运行它。
🌐 Let's create our first workflow using a custom job and run it on EAS.
1
2
添加一个 hello.yml 文件
🌐 Add a hello.yml file
在 .eas/workflows/ 里面,创建一个名为 hello.yml 的文件。这个文件使用一个自定义作业定义了我们的第一个工作流。这个作业运行一个打印 "Hello, Workflows" 的 shell 命令:
🌐 Inside .eas/workflows/, create a file named hello.yml. This file defines our first workflow using a single custom job. The job runs a shell command that prints "Hello, Workflows":
上面的工作流程使用了以下语法:
🌐 The above workflow uses the following syntax:
name是 EAS 仪表板上显示的工作流名称。jobs包含一个或多个要运行的任务。每个任务都有一个唯一的 ID(在本例中为greet)。steps是作业按顺序执行的一系列任务。拥有steps但没有type字段的作业是自定义作业。run是在一个步骤中执行的 shell 命令。这里,它运行echo来打印一条消息。任何 shell 命令都可以用。
3
手动运行工作流
🌐 Manually run the workflow
要在 EAS 仪表板上运行工作流,请在终端窗口中运行以下命令:
🌐 To run the workflow on the EAS dashboard, run the following command from a terminal window:
eas workflow:run 命令会把工作流文件上传到 EAS。然后它会运行文件中定义的任何任务,EAS CLI 会打印一个 URL,带你去 EAS 仪表板观看任务的执行情况。
🌐 The eas workflow:run command uploads the workflow file to EAS. It then runs any job defined inside the file and the EAS CLI prints a URL to the EAS dashboard where we can watch the job.
4
查看作业日志
🌐 View the job logs
在浏览器窗口中打开上一步的 URL。在工作流页面上,我们可以看到 greet 任务及其状态。任务完成后,展开步骤输出以查看记录的消息:Hello, Workflows。
🌐 Open the URL from the previous step in a browser window. On the workflow page, we can see the greet job and its status. Once the job completes, expand the step output to see the logged message: Hello, Workflows.
EAS 仪表板是我们查看和调试任何工作流任务的地方。工作流图显示了是什么触发了我们的任务以及任务的唯一 ID。
🌐 The EAS dashboard is where we view and debug any workflow job. The Workflow graph shows what triggered our job and the job's unique ID.
切换到 Workflow file 标签。这就是我们在第2步写的工作流文件,它会随运行一起保存。
🌐 Switch to the Workflow file tab. This is the workflow file we wrote in Step 2, preserved with the run.
信息 提示: 在 工作流页面 查看我们项目的所有工作流,并按状态或类型进行筛选。
自动运行工作流
🌐 Automatically run a workflow
在终端运行 eas workflow:run 可以一次性使用,但大多数团队希望有在 GitHub 事件触发时自动执行的工作流。自动触发意味着没人需要记得去运行工作流。工作流的配置和它构建的代码一起存放在仓库里。
🌐 Running eas workflow:run from the terminal works for a one-off, but most teams want workflows that fire automatically on GitHub events. Automatic triggers mean no one has to remember to run a workflow. The workflow's configuration lives in the repository alongside the code it builds.
信息 注意: 触发器是一个规则,用来告诉 CI/CD 流水线什么时候启动。它定义了触发流水线自动运行的事件(比如代码推送或拉取请求),而不需要手动执行。
我们在工作流文件中用 on 键定义触发器。EAS 会监控匹配的 GitHub 事件,并自动运行工作流。
🌐 We define a trigger with the on key in the workflow file. EAS watches for the matching GitHub event and runs the workflow automatically.
1
添加自动触发器
🌐 Add an automatic trigger
让我们在现有的工作流文件中添加一个 on.push.branches 触发器。
🌐 Let's add an on.push.branches trigger to our existing workflow file.
on键定义了哪个 GitHub 事件会触发工作流push字段定义何时触发branches字段允许我们指定,每当代码推送到main分支时,工作流程应该自动运行
branches 字段可以包含 GitHub 仓库中存在的任何分支名称。我们可以指定多个分支,比如 ['main', 'develop', 'staging'],当我们推送到这些分支中的任意一个时,就会触发该工作流。
🌐 The branches field can include any branch name that exists in a GitHub repository. We can specify multiple branches such as ['main', 'develop', 'staging'] to trigger the workflow when we push to any of those branches.
2
3
验证自动触发
🌐 Verify the automatic trigger
信息 小贴士: 这一步取决于我们的本地 Expo 项目已经推送到 GitHub,并且 GitHub 仓库已连接到 EAS。要确认:运行
git remote -v以验证本地仓库是否指向 GitHub URL,并打开项目的 EAS 上的 GitHub 设置 检查是否已连接仓库。
让我们在 EAS 仪表板上打开我们项目的 工作流页面 来看看新的任务。
🌐 Let's open our project's Workflows page on the EAS dashboard to see the new job.
在 EAS 仪表板中,注意 Workflow graph 标签显示了此次推送的提交信息和分支引用。在工作流标题下的状态中,Trigger 和 Triggered by 也反映了相同的信息。
🌐 In the EAS dashboard, notice that the Workflow graph tab shows the commit message and branch reference for this push. In the status under the workflow header, the Trigger and Triggered by reflect the same information.
其他触发类型
🌐 Other trigger types
在本教程后面我们会使用的其他触发类型:
🌐 Other trigger types we use later in this tutorial:
on.pull_request:当针对匹配分支打开或更新拉取请求时运行on.push与tags:当匹配的标签模式推送到 GitHub 仓库时运行on.pull_request_labeled:当给拉取请求添加特定标签时运行
把工作串起来
🌐 Chain jobs together
到目前为止,我们在工作流文件中只实现了一个作业。一个工作流文件可以包含多个作业。一个作业的输入可以依赖于前一个作业的输出。让我们在工作流文件中将多个作业串联起来。
🌐 So far, we have implemented a single job in our workflow file. A workflow file can have multiple jobs. A job's input can depend on the output of the previous job. Let's chain multiple jobs together in a workflow file.
1
更新 hello.yml
🌐 Update hello.yml
让我们更新 hello.yml 文件,添加一个自定义作业和一个预打包作业。这个预打包作业叫做 doc,它会在 EAS 仪表板上渲染 Markdown:
🌐 Let's update the hello.yml file to add a custom job and a pre-packaged job. This pre-packaged job is called doc and it renders Markdown on the EAS dashboard:
上面的工作流文件做了以下事情:
🌐 The above workflow file does the following:
- 定义了一个
greet作业,它是一个自定义作业。它使用set-outputshell 函数来设置一个叫做greeting的值。作业级别的outputs字段会暴露步骤输出,以便其他作业可以引用它。 - 定义一个
show_info任务,它使用needs: [greet]来等待greet任务完成并获取其输出。然后,它使用预打包的doc任务类型在 EAS 仪表板中渲染一个 Markdown 文档。Markdown 内容包含在前一个任务中设置的greeting的值。
信息 提示: 在 EAS 工作流中,默认情况下作业是并行运行的。
needs字段是让作业等待的关键:它列出了必须先成功完成的作业 ID,然后needs才能开始运行。如果needs列表中的某个作业失败,依赖的作业将被跳过。
2
运行链式工作流
🌐 Run the chained workflow
在终端窗口中运行以下命令来查看连锁作业的运行效果:
🌐 Run the following command from a terminal window to see the chained jobs in action:
从 EAS CLI 打开 EAS 仪表板链接。在 Logs 下,注意 greet 任务先运行。它完成后,show_info 任务会运行,并使用上一个任务的输出渲染 Markdown 内容。
🌐 Open the EAS dashboard link from the EAS CLI. Under Logs, notice that the greet job runs first. Once it completes, the show_info job runs and renders the Markdown content using the output from the previous job.
清理一下
🌐 Clean up
在本章之后,删除 hello.yml 文件,因为在接下来的章节中我们不会使用它。如果我们想保留它,移除 on.push 触发器,这样它就不会在每次推送到 main 时触发。
🌐 After this chapter, delete the hello.yml file because we do not use it in the next chapters. If we prefer to keep it, remove the on.push trigger so it does not fire on every push to main.
概括
🌐 Summary
Chapter 1: First EAS Workflows job
We created a custom job workflow, triggered it manually and automatically, chained jobs using needs and outputs, and used the EAS dashboard to verify job execution.
In the next chapter, learn how to automate development builds with fingerprinting to skip unnecessary rebuilds.