首页指南参考教程

从 GitHub 存储库触发构建

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


Expo GitHub 应用 使用 EAS 自动触发我们的 GitHub 项目的构建。我们可以根据我们的开发团队的偏好触发任何构建配置文件的构建。它还允许触发直接提交到存储库或拉取请求的 git 推送的构建。

¥Expo GitHub App automatically triggers builds from our GitHub projects with EAS. We can trigger builds for any build profile based on our development team's preferences. It also allows triggering builds for git push committed directly to a repository or a pull request.

在本章中,我们将配置此功能。我们已经为示例应用提供了一个 GitHub 存储库来演示这一点。

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

1

配置 Expo GitHub 应用

¥Configure Expo GitHub app

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

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

  • 在 Expo 仪表板导航菜单中的账户设置下,单击 GitHub。这将打开连接 GitHub 账户页面。

    ¥In the Expo dashboard navigation menu, under Account settings, click GitHub. This opens the Connect GitHub accounts page.

  • 单击“开始”按钮,将打开一个弹出窗口以授权 Expo GitHub 应用。单击安装并授权。

    ¥Click the Get started button which opens a popup to authorize the Expo GitHub app. Click Install and Authorize.

  • 将应用安装到我们的 GitHub 账户后,我们需要将其链接到我们的 Expo 账户。在下一个弹出窗口中,单击“链接安装”。

    ¥Once the app is installed on our GitHub account, we need to link it to our Expo account. In the next popup, click Link installation.

  • 账户链接后,它将显示在 GitHub 账户下。

    ¥Once the account is linked, it will show under GitHub accounts.

2

连接 GitHub 存储库

¥Connect the GitHub repository

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

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

  • 从项目设置下的导航菜单打开项目,然后单击 GitHub。

    ¥Open the project from the navigation menu under Project settings, and click GitHub.

  • 在连接 GitHub 存储库下,我们将看到 GitHub 存储库的列表。我们需要连接正确的一个。在示例中,我们正在搜索我们的存储库贴纸粉碎。

    ¥Under Connect a GitHub repository, we'll see a list of our GitHub repos. We need to connect the right one. In the example, we're searching for our repo sticker-smash.

  • 单击项目存储库的“连接”。

    ¥Click Connect for the project repository.

3

使用默认存储库设置

¥Use default repository settings

Expo GitHub 应用需要知道在哪里可以找到我们项目的源代码。默认情况下,它使用 / 选择根目录。在我们的示例项目中,源代码也可以在根存储库中找到。我们可以在 Expo 仪表板中将其保留为默认值。

¥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 Expo 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:

  • 从特定平台的“构建”页面手动

    ¥Manually from the Builds page for a specific platform

  • 当新代码推送到存储库时自动

    ¥Automatically when new code is pushed to the repository

  • 自动使用 GitHub PR 标签

    ¥Automatically using GitHub PR labels

要使用 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

    ¥We need to specify the build image that we will be using. Open eas.json, and under the development profile, add android.image and ios.image properties and set their value to latest.

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

    ¥Next, let's create a new branch called dev, and make a change in our app's JavaScript code. Then, commit the change, push the branch, and create a PR from that branch.

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

    ¥In the PR link, under Labels, create a label called eas-build-all:development.

  • 单击“创建拉取请求”按钮以创建 PR。Expo GitHub 应用将开始创建开发版本的过程。

    ¥Click Create pull request button to create the PR. The Expo GitHub app will start the process of creating a development build.

  • 在 Expo 仪表板的“构建”页面上,我们可以验证 Android 和 iOS 的构建是否已触发。

    ¥In the Expo dashboard, on the Builds page, we can verify that the builds for both Android and iOS are triggered.

  • 如果我们检查单个构建的详细信息,我们可以在“创建者”下看到该构建是由 GitHub 应用创建的。

    ¥If we check the details of an individual build, we can see under Created by that the build is created by the GitHub app.

概括

¥Summary

Chapter 11: Trigger builds from a GitHub repository

We successfully linked our GitHub account with Expo, connected our repository to our EAS project, and learned about automated development build creation using GitHub PR labels.

Learn about the next steps to use EAS.

Next: Next steps in your journey with EAS
Expo 中文网 - 粤ICP备13048890号