使用 EAS 工作流程进行 Web 部署

了解如何使用 EAS Hosting 和 Workflows 自动化网站和服务器部署。


EAS Workflows 是一种自动化 React Native CI/CD 流水线的好方法,可用于将项目的网站和 API 路由部署到 EAS Hosting,并支持拉取请求 (PR) 预览和生产部署。

🌐 EAS Workflows is a great way to automate the React Native CI/CD pipeline for deploying your project's website and API routes to EAS Hosting with pull request (PR) previews and production deployments.

设置工作流程

🌐 Set up workflows

要使用 EAS 工作流程 自动部署你的项目,请按照 使用 EAS 工作流程入门 中的说明操作。你还可以添加 GitHub 集成 将 GitHub 仓库连接到你的工作流程。

🌐 To use EAS Workflows to automatically deploy your project, follow the instructions in Get started with EAS Workflows. You can also add the GitHub integration to connect a GitHub repository to your workflows.

创建部署工作流

🌐 Create a deployment workflow

将以下文件添加到 .eas/workflows/deploy.yml。这将使用生产环境变量,导出 web 包,部署你的项目,并在你推送到 main 分支时将其推广到生产环境。

🌐 Add the following file to .eas/workflows/deploy.yml. This will use the production environment variables, export the web bundle, deploy your project and promote it to production whenever you push to the main branch.

.eas/workflows/deploy.yml
name: Deploy on: push: branches: ['main'] jobs: deploy: type: deploy name: Deploy environment: production params: prod: true

现在,无论何时将提交推送到 main 或合并 PR,工作流都会运行以部署你的网站。

🌐 Now, whenever a commit is pushed to main or a PR is merged, the workflow will run to deploy your website.

你还可以通过手动触发来测试此工作流程:

🌐 You can also test this workflow by triggering it manually:

Terminal
eas workflow:run .eas/workflows/deploy.yml

创建 PR 预览工作流

🌐 Create a PR preview workflow

将以下文件添加到 .eas/workflows/pr-preview.yml。每当创建或更新拉取请求时,这将自动部署你的网站预览,并在拉取请求中发布包含部署详情的评论。

🌐 Add the following file to .eas/workflows/pr-preview.yml. This will automatically deploy a preview of your website whenever a pull request is created or updated, and post a comment to the PR with the deployment details.

.eas/workflows/pr-preview.yml
name: PR Preview on: pull_request: {} jobs: deploy: type: deploy name: Deploy PR Preview comment: needs: [deploy] type: github-comment

每当拉取请求被创建、重新打开或同步时,此工作流都会运行。comment 任务将自动发现部署并将其详细信息发布到拉取请求中,使审核者能够轻松测试你的更改。

🌐 This workflow will run whenever a pull request is opened, reopened, or synchronized. The comment job will automatically discover the deployment and post its details to the pull request, making it easy for reviewers to test your changes.