从 GitHub 存储库触发构建

了解从 GitHub 存储库触发构建的过程。


Expo GitHub 应用 会自动使用 EAS 从我们的 GitHub 项目触发构建。我们可以根据开发团队的偏好触发任何构建配置文件的构建。它还支持触发对直接提交到仓库的 git push 或拉取请求的构建。

在本章中,我们将配置此功能。我们已经有一个示例应用的 GitHub 仓库来演示这一点。

🌐 In this chapter, we'll configure this functionality. We already have a GitHub repository for our example app to demonstrate this.

观看:如何从 GitHub 仓库触发构建
观看:如何从 GitHub 仓库触发构建

1

配置 Expo GitHub 应用

🌐 Configure Expo GitHub app

要使用此功能,我们需要连接我们的 GitHub 账户:

🌐 To use this functionality, we need to connect our GitHub account:

  • 在 EAS 仪表板中,前往 expo.dev/settings,在 Connections > GitHub 下,点击 Connect。这将打开 Connect GitHub 账户页面。
  • 点击 开始使用 按钮,将弹出一个窗口以授权 Expo GitHub 应用。点击 安装并授权
  • 一旦应用安装在我们的 GitHub 账户上,我们需要将其链接到我们的 Expo 账户。在下一个弹出窗口中,点击 链接安装
  • 一旦账户关联成功,它将显示在 GitHub 下。

2

连接 GitHub 仓库

🌐 Connect the GitHub repository

要启用从 GitHub 仓库触发构建,我们需要在 EAS 仪表板中将其连接到我们的项目:

🌐 To enable triggering builds from a GitHub repository, we need to connect it to our project in the EAS dashboard:

  • 在 EAS 仪表板中,转到 Projects > 选择你的项目 > Project settings > GitHub
  • 连接 GitHub 仓库 下,我们会看到我们的 GitHub 仓库列表。我们需要连接正确的仓库。在示例中,我们正在搜索我们的仓库 sticker-smash
  • 点击 连接 以访问项目仓库。

3

使用默认仓库设置

🌐 Use default repository settings

Expo GitHub 应用需要知道在哪里可以找到我们项目的源代码。默认情况下,它会使用 / 选择根目录。在我们的示例项目中,源代码也位于根仓库中。我们可以在 EAS 仪表板中保持默认设置。

🌐 The Expo GitHub app needs to know where to find the source code of our project. By default, it selects the root directory using /. In our example project, the source code is also available in the root repository. We can leave this to default in the EAS dashboard.

4

使用 GitHub PR 标签触发构建

🌐 Trigger a build using a GitHub PR label

Expo GitHub 应用为我们提供了多种选项来触发构建,例如:

🌐 The Expo GitHub app provides us multiple options to trigger a build, such as:

  • 针对特定平台从构建页面手动操作
  • 当新代码推送到仓库时会自动执行
  • 自动使用 GitHub PR 标签

要使用 GitHub PR 标签自动触发构建,我们将使用上面列表中的第三个选项:

🌐 To automatically trigger a build using a GitHub PR label, we're going to utilize the third option from the list above:

  • 我们需要指定将要使用的构建镜像。打开 eas.json,在 development 配置下,添加 android.imageios.image 属性,并将它们的值设置为 latest

    eas.json
    { "build": { "development": { %%placeholder-start%%... %%placeholder-end%% "android": { "image": "latest" }, "ios": { "image": "latest" } } } %%placeholder-start%%... %%placeholder-end%% }
  • 接下来,让我们创建一个名为 dev 的新分支,并在我们应用的 JavaScript 代码中进行修改。然后,提交更改,推送分支,并从该分支创建一个拉取请求。

  • 在 PR 链接下的 标签 中,创建一个名为 eas-build-all:development 的标签。

  • 点击 创建拉取请求 按钮以创建 PR。Expo GitHub 应用将开始创建开发版本的流程。
  • 在 EAS 仪表板的 Builds 页面上,我们可以确认已触发 Android 和 iOS 的构建。
  • 如果我们查看单个构建的详细信息,可以在 Created by 下看到该构建是由 GitHub 应用创建的。

概括

🌐 Summary

Chapter 11: Trigger builds from a GitHub repository

我们成功地将 GitHub 账户与 Expo 关联,将我们的代码库连接到 EAS 项目,并了解了如何通过 GitHub PR 标签自动创建开发构建。

了解使用 EAS 的下一步操作。

Next: 你在 EAS 旅程中的下一步