用于 PR 预览的 Github Action

了解如何使用 GitHub Actions 通过 EAS 更新自动发布更新。


GitHub Action 是一种云函数,每次 GitHub 上发生事件时都会运行。你可以配置 GitHub Actions,以便在你或你的团队成员合并到分支(例如 "production")时自动构建和发布更新。这使得部署过程一致且快速,让你有更多时间来开发应用。

¥A GitHub Action is a cloud function that runs every time an event on GitHub occurs. You can configure GitHub Actions to automate building and publishing updates when you or members of your team merge to a branch, like "production". This makes the process of deploying consistent and fast, leaving you more time to develop your app.

本指南将引导你完成如何设置 GitHub Actions 以在拉取请求上发布预览。

¥This guide will walk you through how to set up GitHub Actions to publish previews on pull requests.

发布拉取请求预览

¥Publish previews on pull requests

另一个常见的用例是为每个拉取请求创建新的更新。这允许你在合并代码之前在设备上测试拉取请求中的更改,而无需在本地启动项目。以下是每次打开拉取请求时发布更新的步骤:

¥Another common use case is to create a new update for every pull request. This allows you to test the changes in the pull request on a device before merging the code, and without having to start the project locally. Below are the steps to publish an update every time a pull request is opened:

1

Create a file path named .github/workflows/preview.yml at the root of your project.

2

Inside preview.yml, copy and paste the following snippet:

!!!IG0!!!

In the above script:

  • You are using the workflow event on to run every time a pull request is opened or updated.
  • In the update job, the Node.js version, Expo's GitHub Action and the dependencies are set up using GitHub Action's built-in cache.
  • The eas update --auto is run by the preview subaction. It adds a comment to the pull request with basic information about the update and a QR code to scan the update.

Don't forget to add the permissions section to the job. This enables the job to add comments to the pull request.

3

You can skip this step if you have already set up EXPO_TOKEN in the previous section. Only one valid EXPO_TOKEN is required to authenticate GitHub Actions with your Expo account.

If you haven't, you need to give the script above permission to run by providing an EXPO_TOKEN environment variable.

Your GitHub Action should be set up now. Whenever a developer creates a pull request, this action will build an update and publish it, making it available to all reviewers with builds that have access to the EAS branch.

Some repositories or organizations might need to explicitly enable GitHub Workflows and allow third-party Actions.

Using Bun instead of Yarn

To use Bun as the package manager instead of Yarn, follow the steps below for both publishing updates on push and previews on pull requests:

1

Replace the Setup Node step in update.yml or preview.yml with the following snippet:

!!!IG1!!!

2

To install dependencies using Bun, replace the Install dependencies step with the following snippet:

!!!IG2!!!