• 产品简介
  • 快速开始
    • 导入 Git 仓库
    • 从模板开始
    • 直接上传
    • 从 AI 开始
  • 框架指南
    • 前端
      • Vite
      • React
      • Vue
      • 其他框架
    • 后端
    • 全栈
      • Next.js
      • Nuxt
      • Astro
      • React Router
      • SvelteKit
      • TanStack Start
      • Vike
    • 自定义 404 页面
  • 项目指南
    • 项目管理
    • edgeone.json
    • 缓存配置
    • 错误码
  • 构建指南
  • 部署指南
    • 概览
    • 触发部署
    • 管理部署
    • 部署按钮
    • 使用 Github Action
    • 使用 Gitlab CI/CD
    • 使用 CNB 插件
    • 使用 IDE 插件
    • 使用 CodeBuddy IDE
  • 域名管理
    • 概览
    • 自定义域名
    • 配置 HTTPS 证书
      • 概览
      • 申请免费证书
      • 使用 SSL 托管证书
    • 配置 DNS 的 CNAME 记录
  • 可观测性
    • 概览
    • 指标分析
    • 日志分析
  • Pages Functions
    • 概览
    • Edge Functions
    • Cloud Functions
      • 概览
      • Node Functions
  • 中间件
  • KV 存储
  • 边缘 AI
  • API Token
  • EdgeOne CLI
  • Pages MCP
  • 消息通知
  • 集成指南
    • AI
      • 对话型大模型集成
      • 图片大模型集成
    • 数据库
      • Supabase 集成
      • Pages KV 集成
    • 电商
      • Shopify 集成
      • WooCommerce 集成
    • 支付
      • Stripe 集成
      • Paddle 集成
    • CMS
      • WordPress 集成
      • Contentful 集成
      • Sanity 集成
      • Payload 集成
    • 身份验证
      • Supabase 集成
      • Clerk 集成
  • 最佳实践
    • 使用通用大模型快速搭建 AI 应用
    • 使用边缘 AI 模型快速搭建对话型 AI 站点
    • 使用 Shopify 搭建电商平台
    • 使用 Supabase 和 Stripe 搭建 SaaS 站点
    • 如何快速搭建公司品牌站点
    • 如何快速搭建博客站点
  • 迁移指南
    • 从 Vercel 迁移至 EdgeOne Pages
    • 从 Cloudflare Pages 迁移至 EdgeOne Pages
    • 从 Netlify 迁移至 EdgeOne Pages
  • 排障指南
  • 常见问题
  • 联系我们
  • 产品动态

使用 Github Action

通过本章节的指南,您可以快速在 GitHub 仓库集成 Actions 工作流,实现自动构建并部署至 EdgeOne Pages。

设置 GitHub 仓库 Secrets

要运行此 Actions,您需要在 GitHub 中创建仓库的 Secrets:
访问您的 GitHub 仓库页面。
前往 Settings > Secrets and variables > Actions。
单击New repository secret。
在“Name”输入 EDGEONE_API_TOKEN,在“Secret”输入 EdgeOne API token 的值。
EDGEONE_API_TOKEN 的获取可参考文档 API Token

部署主干代码变更

完整的 .github/workflows/deploy.yml 配置如下:
name: Build and Deploy

# 向主干 main 分支推送代码时触发部署
on:
push:
branches:
- main

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.11.0' # 选择适合的 Node.js 版本
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build
- name: Deploy to EdgeOne Pages
run: npx edgeone pages deploy <outputDirectory> -n <projectName> -t ${{ secrets.EDGEONE_API_TOKEN }} [-e <env>]
env:
EDGEONE_API_TOKEN: ${{ secrets.EDGEONE_API_TOKEN }}
将上述的 deploy.yml 文件配置到您的项目根目录下。当代码推送到 main 分支时,会触发以下构建过程:
1. checkout 到目标仓库。
2. 设置 Node.js 版本为 22.11.0。
3. 安装项目依赖。
4. 构建项目。
构建完成后回到控制台查看构建链接,或者在当前仓库下前往 Actions > All workflows > Build and Deploy 查看 Deploy to EdgeOne Pages 节点。
workflow_deploy_pagas
workflow_deploy_pagas


代码合入前部署预览链接

完整的 .github/workflows/deploy.yml 配置如下:

name: Build and Deploy

on:
pull_request_target:
types: [opened]

jobs:
Deploy-Preview:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.11.0' # 选择适合的 Node.js 版本

- name: Install dependencies
run: npm install
- name: Build project
run: npm run build

- name: Deploy to EdgeOne Pages
id: deploy
run: |
echo "Deploying to EdgeOne Pages..."
DEPLOY_OUTPUT=$(npx edgeone pages deploy ./.next -n next-mix-render-template -t ${{ secrets.EDGEONE_TOKEN }} -e preview 2>&1)
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep "EDGEONE_DEPLOY_URL=" | cut -d'=' -f2-)
echo "DEPLOY_URL=$DEPLOY_URL" >> $GITHUB_OUTPUT
PROJECT_ID=$(echo "$DEPLOY_OUTPUT" | grep "EDGEONE_PROJECT_ID=" | cut -d'=' -f2-)
echo "PROJECT_ID=$PROJECT_ID" >> $GITHUB_OUTPUT

DEPLOY_END_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "DEPLOY_END_TIME=$DEPLOY_END_TIME" >> $GITHUB_OUTPUT

env:
EDGEONE_API_TOKEN: ${{ secrets.EDGEONE_TOKEN }}

- name: Enable PR comments # 支持在代码合并前部署预览链接
uses: thollander/actions-comment-pull-request@v2
with:
message: |
🚀 **EdgeOne Pages 部署完成**
| 项目 | 预览链接 | 项目ID | 更新时间 |
|---|---|---|---|
| [${{ github.event.repository.name }}](https://console.tencentcloud.com/edgeone/pages/project/${{ steps.deploy.outputs.PROJECT_ID }}/deploy) | [🔗 点击预览](${{ steps.deploy.outputs.DEPLOY_URL }}) | ${{ steps.deploy.outputs.PROJECT_ID }} | ${{ steps.deploy.outputs.DEPLOY_END_TIME }} |
将上述的 deploy.yml 文件配置到您的项目根目录下。当有 pull request 创建时会触发以下构建过程:
1. checkout 到目标仓库。
2. 设置 Node.js 版本为 22.11.0。
3. 安装项目依赖。
4. 构建项目。
5. pull request 评论区会增加 EdgeOne 部署成功的相关信息,可以在合并代码前审阅页面改动。



说明:
npx edgeone pages deploy 参数说明:
<outputDirectory>: 项目构建后产物所在的文件夹(必填)。
-n, --name: 需要部署的项目名称,项目不存在则自动创建新项目(必填)。
-e, --env: 部署目标环境,可选值: production 或 preview(默认 production)。
示例:npx edgeone pages deploy ./dist -n project-name -t ${{ secrets.EDGEONE_API_TOKEN }}。

EdgeOne Pages 部署

构建完成后,项目将通过以下步骤自动部署到 EdgeOne Pages:
构建阶段生成 ./out 目录
使用 EdgeOne 命令行工具进行部署:npx edgeone pages deploy ./out -n my-edgeone-pages-project -t ${{ secrets.EDGEONE_API_TOKEN }}
GitHub Actions 的相关信息可查看 文档

ai-agent
你可以这样问我
如何开始使用 EdgeOne Pages?