This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
使用 Git 标签来触发生产部署
了解如何通过 Git 标签在 EAS 工作流中触发生产部署。
推送到发布分支会在每次提交时运行生产工作流,即使是那些我们根本不打算发布的提交也会运行。
🌐 Pushing to a release branch runs the production workflow on every commit, even ones we never meant as a release.
学习成果
🌐 Learning outcomes
- 把生产工作流的触发器从
release/*分支改成匹配v*.*.*的 Git 标签 - 通过从
main推送一个标签来发布版本,然后在 EAS 仪表板上查看工作流运行情况 - 把像
v1.0.0-rc.1这样的预发布标签从生产环境中排除,并在单独的工作流程中运行发布候选版本
标签作为发布事件
🌐 Tags as release events
EAS 工作流通过 on.push 支持基于标签的触发器,并使用 tags 列表。只有当推送到远程的标签匹配某个通配符模式时,工作流才会运行。Git 标签是一次性事件,绑定到特定的提交和版本,不像分支可以随时间更新。这使得标签非常适合用于标记发布版本。
🌐 EAS Workflows supports tag-based triggers through on.push with a tags list. The workflow runs only when a tag matching a glob pattern is pushed to the remote. A Git tag is a one-time event tied to a specific commit and version, unlike a branch that can be updated over time. That makes tags well-suited for marking releases.
基于标签的发布工作流程适合以下类型的团队:
🌐 A tag-based release workflow fits teams that:
- 想让 Git 中的版本号和他们发给应用用户的版本一致
- 直接从
main发布,而不是维护长期存在的发布分支 - 想要每个版本的每次发布提交都有清晰的审计跟踪
把 production.yml 切换到标签触发
🌐 Switch production.yml to a tag trigger
打开上一章中的 .eas/workflows/production.yml 工作流,并将 on.push.branches 触发器替换为 on.push.tags。工作流中的其他内容保持不变。
🌐 Open the .eas/workflows/production.yml workflow from the previous chapter and replace the on.push.branches trigger with on.push.tags. Everything else inside the workflow stays the same.
1
更改触发器
🌐 Change the trigger
将 branches 触发器替换为 tags 触发器。tags 通配符匹配像 v1.0.0、v2.3.7 和 v10.0.0-beta.1 这样的标签。
🌐 Replace the branches trigger with a tags trigger. The tags glob matches tags like v1.0.0, v2.3.7, and v10.0.0-beta.1.
为了让标签触发工作流,我们需要选择一个符合我们团队流程的模式。常见的模式包括:
🌐 For tags to trigger the workflow, we need to pick a pattern that matches our team's flow. Common patterns include:
['v*']匹配任何以v开头的标签['v*.*.*']匹配严格的三段式语义版本(推荐)
我们不需要更改其他任何作业。fingerprint、get-build、build 和 update 作业的工作方式是一样的,因为它们都是对提交操作的。
🌐 We don't need to change any other jobs. The fingerprint, get-build, build, and update jobs work identically because they operate on the commit.
2
3
创建一个标签来测试工作流程
🌐 Create a tag to test the workflow
要运行这个工作流,我们需要推一个与 production.yml 中定义的通配符模式匹配的标签。
🌐 To run the workflow, we need to push a tag that matches the glob pattern defined in production.yml.
在我们的示例项目中做一个 TypeScript/JavaScript 的修改,提交它,然后推送一个新标签:
🌐 Make a TypeScript/JavaScript change in our example project, commit it, and push a new tag:
该工作流在 v0.1.0 标签触发。打开 EAS 仪表板,在 工作流 下,会看到“部署到生产”正在以 refs/tags/v0.1.0 作为其分支运行:
🌐 The workflow triggers on the v0.1.0 tag. Open the EAS dashboard, and under Workflows, notice "Deploy to production" running with refs/tags/v0.1.0 as its branch:
由于这是使用为基于标签的发布生成的指纹进行的第一次生产运行,所以 Android 和 iOS 都会运行 build 任务。随后指向 TypeScript/JavaScript 改动的标签会跳过构建任务,直接进入 update 任务。
🌐 Since this is the first production run with the fingerprint generated for a tag-based release, the build jobs run for both Android and iOS. Subsequent tags that point to TypeScript/JavaScript changes skip the build jobs and go straight to update jobs.
发布候选版本的预发布标签
🌐 Pre-release tags for release candidates
v*.*.* 通配符也会匹配像 v1.0.0-rc.1 这样的预发布标签,这会将候选发布版本发送给应用用户。为了让候选发布版本不进入生产环境,需要在生产工作流的触发器中排除它们:
🌐 The v*.*.* glob also matches pre-release tags like v1.0.0-rc.1, which would ship a release candidate to app users. To keep release candidates out of production, exclude them from the production workflow's trigger:
在正式发布之前测试候选发布版本,可以创建一个单独的工作流,只匹配预发布标签(tags: ['v*.*.*-rc.*']),并重用 fingerprint、get-build 和 build 作业,同时不包含 update 和 submit 作业。使用同样的流水线运行,用户不会接触到任何东西。
🌐 To exercise a release candidate before the real release, create a separate workflow that matches only pre-release tags (tags: ['v*.*.*-rc.*']) and reuses the fingerprint, get-build, and build jobs without the update and submit jobs. The same pipeline runs, and nothing reaches app users.
概括
🌐 Summary
Chapter 6: Tag-based releases
We switched the production workflow trigger from a release branch to a Git tag, tested the change by pushing a versioned tag from main, and learned how to gate release candidates with a pre-release tag glob.
In the next chapter, learn how to deploy web builds to EAS Hosting from a workflow.