首页指南参考教程

从 Expo GitHub 应用触发构建

了解如何使用 Expo GitHub 应用在 EAS 上触发应用的构建。


本指南介绍了如何使用 Expo GitHub 应用直接从 GitHub 存储库触发构建。

¥This guide explains how to trigger builds directly from your GitHub repository using the Expo GitHub App.

先决条件

¥Prerequisites

在 eas.json 中设置 image 字段

¥Set the image field in your eas.json

对于要与 GitHub 一起使用的构建配置文件,请在 eas.json 中指定用于原生平台的 image

¥For the build profiles you want to use with GitHub, specify an image to use for the native platform in eas.json.

如果你的项目配置不依赖于特定的 建立形象,请使用 latest 映像。例如:

¥Use the latest image if your project's configuration does not rely on a specific build image. For example:

eas.json
{
  %%placeholder-start%%... %%placeholder-end%%
  "build": {
    "production": {
      "android": {
        "image": "latest"
      },
      "ios": {
        "image": "latest"
      }
    }
  }
}

从本地计算机运行成功的构建

¥Run a successful build from your local machine

要从 GitHub 存储库触发 EAS 构建,你需要为 EAS 构建配置项目,并从你的计算机为你希望在 GitHub 上支持的每个平台成功运行构建。

¥To trigger EAS builds from a GitHub repo, you'll need to configure your project for EAS Build and successfully run a build from your computer for each platform that you'd like to support on GitHub.

如果你尚未成功运行 eas build -p [all|ios|android],请参阅 创建你的第一个版本 了解更多信息。一旦完成,请继续执行本指南中的步骤。

¥If you haven't successfully run eas build -p [all|ios|android] yet, see Create your first build for more information. Once you have, continue with the steps in this guide.

以下也必须为真:

¥The following must also be true:

  • 组织中的 Expo 用户必须拥有有权访问目标存储库的链接的 GitHub 用户。检查 用户设置 > 连接 并验证你的 GitHub 用户账户是否已链接。

    ¥An Expo user in the organization must have a linked GitHub user with access to the target repository. Check User settings > Connections and verify that your GitHub user account is linked.

  • 你必须接受 Expo GitHub 应用 请求的权限。

    ¥You must accept the permissions requested by the Expo GitHub app.

为 GitHub 配置你的应用

¥Configure your app for GitHub

将你的 GitHub 存储库链接到你的 Expo 项目

¥Link your GitHub repository to your Expo project

访问你项目的 GitHub 设置页面

¥Visit your project's GitHub settings page.

在你的 GitHub 账户上安装 Expo GitHub 应用。

¥Install the Expo GitHub App on your GitHub account.

注意:你必须拥有 Expo 账户的 所有者或管理员访问权限 才能安装应用。

¥Note: You must have Owner or Admin access of the Expo account to install the app.

然后,将 GitHub 存储库链接到你的 Expo 项目。

¥Then, link the GitHub repository to your Expo project.

注意:你只能将 GitHub 组织存储库 链接到 Expo 组织。

¥Note: You can only link GitHub organization repositories to Expo organizations.

要从其他 GitHub 账户添加存储库,请单击账户选择器下拉菜单中的添加新账户选项。

¥To add a repository from a different GitHub account, click the Add new account option in the account selector dropdown.

配置你的存储库设置

¥Configure your repository settings

在运行构建之前,Expo GitHub 应用需要知道在哪里可以找到项目的源代码。如果你的 Expo 项目源代码位于存储库的根目录中,那么你不需要执行任何操作。如果你的 Expo 项目源代码位于子目录中,那么你需要在项目的 GitHub 设置页面 上为存储库配置 "基目录" 设置。

¥Before you run a build, the Expo GitHub App needs to know where to find the source code for your project. If your Expo project source code is in the root of your repository, then you don't need to do anything. If your Expo project source code is in a subdirectory, then you'll need to configure "Base directory" settings for your repository on your project's GitHub settings page.

从 GitHub 触发构建

¥Trigger a build from GitHub

为 GitHub 配置应用后,你可以使用项目构建列表页面上的 UI 或 GitHub PR 上的标签从 GitHub 触发构建。

¥Once you have configured your app for GitHub, you can trigger a build from GitHub by using the UI on your project's build list page or by labels on your GitHub PRs.

使用 Expo 网站进行构建

¥Build using the Expo website

访问你项目的 构建列表页面 并单击 "从 GitHub 构建" 按钮。系统将提示你选择 Git 引用(分支/提交/标签)、要构建的平台以及要应用到的构建配置文件。

¥Visit your project's build list page and click the "Build from GitHub" button. You'll be prompted to select a Git ref (branch/commit/tag), a platform to build for, and the build profile to apply to it.

你还可以为此特定构建指定基目录。这不会更改该项目的全局设置。

¥You can also specify a base directory for this specific build. That will not change the global settings for this project.

使用 GitHub PR 标签进行构建

¥Build using GitHub PR labels

你可以通过向 PR 添加标签来从 GitHub PR 触发构建。标签必须采用 eas-build-[platform]:[profile] 的形式,其中 [platform]androidiosall[profile] 是 eas.json 文件中指定的构建配置文件的名称。如果不指定构建平台,则默认为 all。如果你不指定构建配置文件,它将默认为 production

¥You can trigger a build from a GitHub PR by adding a label to the PR. The label must be in the form of eas-build-[platform]:[profile] where [platform] is either android, ios, or all and [profile] is the name of a build profile specified in your eas.json file. If you don't specify a build platform, it will default to all. If you don't specify a build profile, it will default to production.

例如,如果你想触发 Android 的生产版本,请将标签 eas-build-android 添加到 PR。

¥For example, if you want to trigger a production build for Android, add the label eas-build-android to the PR.

PR 基础分支上的最新提交将触发构建。你可以在 PR 的检查中查看构建的状态。检查详细信息中将提供指向构建的链接。

¥The build will be triggered for the latest commit on the PR's base branch. You can view the status of the build in the PR's checks. A link to the build will be available in the check's details.

当代码推送到存储库时自动构建

¥Build automatically when code is pushed to repository

当你将代码推送到 GitHub 时,你可以通过自动构建 Expo 项目来进一步实现构建自动化。

¥You can take your build automation further by automatically building your Expo project when you push code to GitHub.

设置构建触发器

¥Set up build triggers

你可以设置构建触发器来配置 EAS 从 GitHub 构建应用的时间。我们允许你在推送到分支、拉取请求和 Git 标签时进行构建。

¥You can set up build triggers to configure when EAS builds your app from GitHub. We allow you to build when pushing to a branch, pull request, and Git tag.

在仪表板中打开你的 Expo 项目。要创建构建触发器,请向下滚动到项目 GitHub 设置页面的构建触发器部分,然后单击新建构建触发器。

¥Open your Expo project in the dashboard. To create a build trigger, scroll down to the Build triggers section of the project GitHub settings page and click New Build Trigger.

当你单击“新建构建触发器”时,你将看到一个表单来配置此构建应如何运行。

¥When you click New Build Trigger, you will be presented with a form to configure how this build should run.

这些模式可以包括由星号 (*) 表示的通配符,它可以匹配模式内的任何字符和字符数。例如,releases/* 可以匹配 releases/release/1234release/genesis 等。如果将模式指定为唯一的星号 (*),则将匹配所有分支/标签。

¥These patterns can include wildcards represented by asterisks (*), which can match any character and number of characters inside the pattern. For example, releases/* can match releases/, release/1234, release/genesis, and so on. If you specify the pattern as a sole asterisk (*), all branches/tags will be matched.

你还可以为特定平台配置触发器并构建配置文件。如果你选择多个平台,将为每个平台创建一个单独的触发器。

¥You can also configure triggers for specific platforms and build profiles. If you select multiple platforms, a separate trigger will be made for each.

当你推送到分支或标签时,你可以通过查看提交的检查部分来找到构建。

¥When you push to a branch or tag, you can find the builds by looking at a commit's Checks section.

对于拉取请求,你可以配置目标分支模式。这是你要构建的拉取请求的目标分支。相同的规则也适用于此处的通配符。

¥For pull requests, you can configure a target branch pattern. This is the destination branch of the pull request you want to build. The same rules apply for wildcards here as well.

当你推送具有与此触发器匹配的源和目标分支的拉取请求时,你将在拉取请求的检查部分中找到这些构建:

¥When you push to a pull request with a source and target branch matching this trigger, you'll find these builds in the checks section of the pull request:

注意:要从拉取请求触发构建,拉取请求的作者必须是 GitHub 存储库上的协作者。如果你想构建来自外部贡献者的拉取请求,应用 PR 标签

¥Note: To trigger builds from a pull request, the pull request's author must be a collaborator on the GitHub repository. If you want to build pull requests from external contributors, apply a PR Label.

管理构建触发器

¥Manage build triggers

在 Expo 仪表板中项目的 GitHub 设置页面上,你可以单击构建触发器行右侧的选项按钮来禁用、编辑或删除触发器。

¥On your project's GitHub settings page in the Expo dashboard, you can click the options button to the right of a build trigger row to disable, edit, or delete the trigger.

你还可以使用触发器中的参数手动运行 GitHub 构建。这不会计入你的自动构建触发记录。

¥You can also run a GitHub build with the parameters from the trigger manually. This will not count towards your automatic build trigger record.

使用 EAS Submit 自动提交应用商店

¥Automatic app stores submission with EAS Submit

构建完成后,你可以使用 EAS Submit 自动将你的应用提交到应用商店。此功能简化了流程,减少了发布应用所需的手动步骤。

¥Once your build completes, you can automatically submit your app to the app stores using EAS Submit. This feature streamlines the process, reducing the manual steps required to publish your app.

要启用自动提交,你需要配置构建触发器以将提交作为构建过程的一部分。以下是设置方法:

¥To enable automatic submission, you need to configure your build triggers to include submission as part of the build process. Here's how you can set it up:

  • 在 Expo 仪表板上导航到项目的 GitHub 设置页面。

    ¥Navigate to your project's GitHub settings page on the Expo dashboard.

  • 找到你要修改的构建触发器,然后单击选项按钮。

    ¥Find the build trigger you want to modify, and click the options button.

  • 选择编辑触发器,然后在出现的对话框中,选中构建后提交到存储选项。

    ¥Select Edit trigger and in the dialog that appears, check the option Submit to store after build.

  • 保存你的更改。

    ¥Save your changes.

启用后,每次从此配置触发构建时,它将自动提交到你在 eas.json 中 submit 字段下配置的应用商店。

¥Once enabled, every time a build is triggered from this configuration, it will automatically be submitted to the app stores you have configured in your eas.json under the submit field.

注意:确保你的 eas.json 已正确配置以进行提交,包括指定正确的应用商店凭据和提交配置文件。有关详细信息,请参阅 EAS 提交

¥Note: Ensure that your eas.json is properly configured for submission, including specifying the correct app store's credentials and submission profile. For more information, see the EAS Submit.

故障排除

¥Troubleshooting

  • 当出现问题时,我们将使用一些错误信息对尝试构建的提交进行评论。我们还在构建触发器 UI 中显示最新结果,其中包括当你将鼠标悬停在错误标签上时的错误信息。

    ¥When things go wrong, we will comment on the commit we attempted to build with some error information. We also show the latest result in the build triggers UI, which includes error information when you hover the Error tag.

  • 尝试构建时,请仔细检查 先决条件 部分中的所有内容是否正确。

    ¥Double check everything in the Prerequisites section is true when trying to build.

  • 如果你使用的是 monorepo 设置,请确认你的基本目录是准确的。

    ¥Confirm that your base directory is accurate if you're using a monorepo setup.

  • 你的构建配置文件正确吗?如果在 eas.json 中找不到匹配的配置文件,则不会调度构建。

    ¥Is your build profile correct? If a matching profile can't be found in eas.json, the build will not dispatch.

Expo 中文网 - 粤ICP备13048890号