GitHub Actions 集成
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示
将 Capgo Live Updates 与 GitHub Actions 集成,以便在推送 code 更改时自动部署您的应用程序更新。 本指南涵盖了使用 GitHub 强大的 CI/CD 平台设置自动化构建、测试和部署工作流程。
先决条件
标题为“先决条件”在设置 GitHub Actions 集成之前,请确保您有:
- 一个 GitHub 仓库,其中包含您的应用程序的源 code
- 一个 Capgo 帐户,其中包含已配置的应用程序
- Node.js 和 npm/yarn 在您的项目中配置
- GitHub 仓库中的 Actions
GitHub 秘钥设置
标题:GitHub 秘钥设置步骤 1:配置仓库秘钥
标题:步骤 1:配置仓库秘钥在您的 GitHub 仓库中设置必要的秘钥:
- 导航到您的 GitHub 仓库
- 前往 设置 → 密钥和变量 → Actions
- 点击 新建仓库密钥 并添加以下内容:
| 密钥名称 | 值 |
|---|---|
CAPGO_TOKEN | 您的Capgo API令牌 |
简单生产部署
Section titled “简单生产部署”从以下基本配置开始,推送到主分支时即可部署到生产环境:
# Simple GitHub Actions Workflow for Capgo Live Updatesname: Deploy to Capgo
on: push: branches: - main
jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v6
- name: Setup Node.js uses: actions/setup-node@v6 with: node-version: '24' cache: 'npm'
- name: Install, test and build run: | npm ci npm run test npm run build
- name: Deploy to Capgo run: | npm install -g @capgo/cli npx @capgo/cli bundle upload --channel production env: CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }} # For encrypted uploads, add: --key-data-v2 "${{ secrets.CAPGO_PRIVATE_KEY }}"高级多渠道配置
Section titled “高级多渠道配置”特性分支部署
Section titled “特性分支部署”将特性分支部署到临时渠道进行测试:
# Feature branch deploymentname: Deploy Feature Branch to Capgo
on: push: branches: - 'feature/**'
jobs: deploy-feature: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: '24' cache: 'npm'
- run: | npm ci npm run test npm run build
- name: Deploy to feature channel run: | CHANNEL_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9]/-/g' | tr '[:upper:]' '[:lower:]') npm install -g @capgo/cli npx @capgo/cli channel create $CHANNEL_NAME --apikey ${{ secrets.CAPGO_TOKEN }} || true npx @capgo/cli bundle upload --apikey ${{ secrets.CAPGO_TOKEN }} --channel $CHANNEL_NAME如果您正在使用 Capgo的加密功能,您需要在CI/CD环境中安全存储您的私钥。
之后 设置本地加密密钥后 将您的私钥添加到GitHub密钥中:
# Display your private key content (copy this output)cat .capgo_key_v2将此内容添加为 CAPGO_PRIVATE_KEY 在GitHub仓库密钥中,然后在工作流中使用它:
# Deploy with encryption- name: Deploy to Capgo with Encryption run: | npm install -g @capgo/cli npx @capgo/cli bundle upload --apikey ${{ secrets.CAPGO_TOKEN }} --key-data-v2 "${{ secrets.CAPGO_PRIVATE_KEY }}" --channel production部署通道文档 包含开发、拉取请求和生产部署的完整工作流程:.
复制到剪贴板
# Complete multi-environment workflowname: Deploy to Capgo
on: push: branches: [main, develop] pull_request: branches: [main, develop]
jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: '24' cache: 'npm'
- run: | npm ci npm run test npm run build
- uses: actions/upload-artifact@v6 with: name: dist path: dist/
deploy-development: if: github.ref == 'refs/heads/develop' needs: build runs-on: ubuntu-latest environment: development steps: - uses: actions/setup-node@v6 with: node-version: '24'
- uses: actions/download-artifact@v4 with: name: dist path: dist/
- run: | npm install -g @capgo/cli npx @capgo/cli bundle upload --apikey ${{ secrets.CAPGO_TOKEN }} --channel development
deploy-pr: if: github.event_name == 'pull_request' needs: build runs-on: ubuntu-latest steps: - uses: actions/setup-node@v6 with: node-version: '24'
- uses: actions/download-artifact@v4 with: name: dist path: dist/
- name: Deploy to PR channel run: | CHANNEL_NAME="pr-${{ github.event.number }}" npm install -g @capgo/cli npx @capgo/cli channel create $CHANNEL_NAME --apikey ${{ secrets.CAPGO_TOKEN }} || true npx @capgo/cli bundle upload --apikey ${{ secrets.CAPGO_TOKEN }} --channel $CHANNEL_NAME
- name: Comment PR uses: actions/github-script@v7 with: script: | github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `🚀 This PR has been deployed to Capgo channel: \`pr-${{ github.event.number }}\`\n\nTo test this update in your app, configure it to use this channel. [Learn how to configure channels →](/docs/live-updates/channels/#configuring-the-channel-in-your-app)` })
deploy-production: if: github.ref == 'refs/heads/main' needs: build runs-on: ubuntu-latest environment: production steps: - uses: actions/setup-node@v6 with: node-version: '24'
- uses: actions/download-artifact@v4 with: name: dist path: dist/
- run: | npm install -g @capgo/cli npx @capgo/cli bundle upload --apikey ${{ secrets.CAPGO_TOKEN }} --channel production清理功能渠道
标题:清理功能渠道自动清理功能渠道,当分支被删除时:
name: Cleanup Feature Channels
on: delete:
jobs: cleanup: runs-on: ubuntu-latest if: github.event.ref_type == 'branch' && startsWith(github.event.ref, 'feature/') steps: - uses: actions/setup-node@v6 with: node-version: '24'
- name: Delete Capgo channel run: | CHANNEL_NAME=$(echo "${{ github.event.ref }}" | sed 's/[^a-zA-Z0-9]/-/g' | tr '[:upper:]' '[:lower:]') npm install -g @capgo/cli npx @capgo/cli channel delete $CHANNEL_NAME --apikey ${{ secrets.CAPGO_TOKEN }} || true安全性和最佳实践
标题:安全性和最佳实践环境保护规则
标题:环境保护规则在GitHub中设置环境保护规则:
- 前往 设置 → 环境 您的仓库
- 创建环境:
development,staging,production - 对于生产环境,添加:
- 必需审阅者: 添加必须审批部署的团队成员
- 等待时间: 添加部署前延迟(可选)
- 部署分支: 限制到
mainbranch only
安全密钥管理
标题:安全密钥管理使用环境特定的密钥:
# Use different secrets per environmentdeploy-production: environment: production steps: - name: Deploy to Production run: | npx @capgo/cli bundle upload \ --apikey ${{ secrets.CAPGO_PROD_TOKEN }} \ --app ${{ secrets.CAPGO_PROD_APP_ID }} \ --channel production监控和通知
标题:监控和通知Slack 集成
标题:Slack 集成将 Slack 通知添加到您的工作流程:
name: Deploy with Notifications
jobs: deploy: runs-on: ubuntu-latest steps: # ... deployment steps
- name: Notify Slack on Success if: success() uses: 8398a7/action-slack@v3 with: status: success text: '✅ Capgo deployment successful!' fields: repo,message,commit,author,action,eventName,ref,workflow env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Notify Slack on Failure if: failure() uses: 8398a7/action-slack@v3 with: status: failure text: '❌ Capgo deployment failed!' fields: repo,message,commit,author,action,eventName,ref,workflow env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}Discord 集成
Discord 集成向 Discord 发送通知:
- name: Discord notification if: always() uses: Ilshidur/action-discord@master with: args: | Capgo deployment ${{ job.status }}! App: ${{ secrets.CAPGO_APP_ID }} Channel: ${{ github.ref_name }} Commit: ${{ github.sha }} env: DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}电子邮件通知
电子邮件通知配置电子邮件通知:
- name: Send email notification if: failure() uses: dawidd6/action-send-mail@v3 with: server_address: smtp.gmail.com server_port: 465 username: ${{ secrets.EMAIL_USERNAME }} password: ${{ secrets.EMAIL_PASSWORD }} subject: 'Capgo Deployment Failed - ${{ github.repository }}' to: team@yourcompany.com from: ci-cd@yourcompany.com body: | Deployment failed for ${{ github.repository }} Branch: ${{ github.ref_name }} Commit: ${{ github.sha }} Workflow: ${{ github.workflow }}故障排除
故障排除调试工作流
调试工作流添加调试步骤以解决问题:
- name: Debug environment run: | echo "Node version: $(node --version)" echo "NPM version: $(npm --version)" echo "Working directory: $(pwd)" echo "Files in dist/: $(ls -la dist/ || echo 'No dist directory')" echo "Environment variables:" env | grep -E "(GITHUB_|CAPGO_)" | sort
- name: Test Capgo CLI run: | npx @capgo/cli --version npx @capgo/cli app debug --apikey ${{ secrets.CAPGO_TOKEN }} --app ${{ secrets.CAPGO_APP_ID }}常见问题和解决方案
标题为“常见问题和解决方案”工作流程因“CAPGO_TOKEN”未找到而失败:
- name: Verify secrets run: | if [ -z "${{ secrets.CAPGO_TOKEN }}" ]; then echo "ERROR: CAPGO_TOKEN secret is not set" exit 1 fi echo "CAPGO_TOKEN is set (length: ${#CAPGO_TOKEN})" env: CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }}未找到构建文件:
- name: Debug artifacts run: | echo "Checking for build artifacts..." ls -la dist/ || echo "No dist directory found" find . -name "*.js" -o -name "*.html" | head -10网络连接问题:
- name: Test connectivity run: | ping -c 3 api.capgo.io || echo "Ping failed" curl -I https://api.capgo.io/health || echo "Health check failed"可重用工作流程
标题为“可重用工作流程”为项目建立可重用的工作流程以实现一致性:
name: Reusable Capgo Deploy
on: workflow_call: inputs: environment: required: true type: string channel: required: true type: string secrets: CAPGO_TOKEN: required: true CAPGO_APP_ID: required: true
jobs: deploy: runs-on: ubuntu-latest environment: ${{ inputs.environment }} steps: - uses: actions/checkout@v6
- name: Setup Node.js uses: actions/setup-node@v6 with: node-version: '24' cache: 'npm'
- name: Install and build run: | npm ci npm run build
- name: Deploy to Capgo run: | npm install -g @capgo/cli npx @capgo/cli bundle upload \ --apikey ${{ secrets.CAPGO_TOKEN }} \ --app ${{ secrets.CAPGO_APP_ID }} \ --channel ${{ inputs.channel }}使用可重用的工作流程:
name: Deploy App
on: push: branches: [main, develop]
jobs: deploy-dev: if: github.ref == 'refs/heads/develop' uses: ./.github/workflows/reusable-capgo-deploy.yml with: environment: development channel: development secrets: CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }} CAPGO_APP_ID: ${{ secrets.CAPGO_APP_ID }}
deploy-prod: if: github.ref == 'refs/heads/main' uses: ./.github/workflows/reusable-capgo-deploy.yml with: environment: production channel: production secrets: CAPGO_TOKEN: ${{ secrets.CAPGO_TOKEN }} CAPGO_APP_ID: ${{ secrets.CAPGO_APP_ID }}下一步
了解关于通过GitHub Actions 集成,您可以利用GitHub强大的CI/CD平台来创建具有内置安全、监控和协作功能的复杂部署工作流程,用于您的Capgo Live Updates。
继续使用GitHub Actions 集成
标题:继续使用GitHub Actions 集成如果您正在使用 GitHub Actions 集成 为计划 CI/CD 自动化,连接它与 Capgo CI/CD 为产品工作流程在 Capgo CI/CD 中 Capgo 原生构建 为产品工作流程在 Capgo 原生构建中 Capgo 集成 为产品工作流程在 Capgo 集成中 CI/CD 集成 为 CI/CD 集成 为实现细节在 CI/CD 集成中,和 GitLab CI/CD 集成