GitHub Integración de acciones
Integre Capgo Actualizaciones en vivo con GitHub Acciones para implementar automáticamente las actualizaciones de su aplicación cada vez que realice cambios en el código. Esta guía cubre la configuración de flujos de trabajo de compilación, prueba e implementación automatizados utilizando la poderosa plataforma CI/CD de GitHub.
Requisitos previos
Section titled “Requisitos previos”Antes de configurar la integración de GitHub Acciones, asegúrese de tener:
- Un repositorio GitHub con el código fuente de tu aplicación
- Una cuenta Capgo con una aplicación configurada
- Node.js y npm/hilo configurado en su proyecto
- GitHub Acciones habilitadas para tu repositorio
Configuración de secretos GitHub
Section titled “Configuración de secretos GitHub”Paso 1: Configurar los secretos del repositorio
Section titled “Paso 1: Configurar los secretos del repositorio”Configure los secretos necesarios en su repositorio GitHub:
- Navegue a su repositorio GitHub
- Vaya a Configuración → Secretos y variables → Acciones
- Haga clic en Nuevo secreto del repositorio y agregue lo siguiente:
| Nombre secreto | Valor |
|---|---|
CAPGO_TOKEN | Su token Capgo API |
Implementación de producción simple
Section titled “Implementación de producción simple”Comience con esta configuración básica que se implementa en producción en cada envío a la rama principal:
# 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 }}"Configuración multicanal avanzada
Section titled “Configuración multicanal avanzada”Implementaciones de ramas de funciones
Section titled “Implementaciones de ramas de funciones”Deploy feature branches to temporary channels for testing:
# 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_NAMEUsando cifrado
Section titled “Usando cifrado”Si está utilizando la función de cifrado de Capgo, deberá almacenar su clave privada de forma segura en su entorno CI/CD.
After setting up encryption keys locally, add your private key to GitHub secrets:
# Display your private key content (copy this output)cat .capgo_key_v2Add this content as CAPGO_PRIVATE_KEY in your GitHub repository secrets, then use it in workflows:
# 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 productionConfiguración multicanal
Section titled “Configuración multicanal”For comprehensive information about setting up and managing multiple deployment channels, see the Channels documentation.
Complete workflow with development, pull requests, and production deployments:
# 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@v4 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 productionCanales de funciones de limpieza
Section titled “Canales de funciones de limpieza”Automatically clean up feature channels when branches are deleted:
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 }} || trueSeguridad y mejores prácticas
Section titled “Seguridad y mejores prácticas”Reglas de protección del medio ambiente
Section titled “Reglas de protección del medio ambiente”Set up environment protection rules in GitHub:
- Go to Settings → Environments in your repository
- Create environments:
development,staging,production - Para el entorno de producción, agregue:
- Required reviewers: Add team members who must approve deployments
- Wait timer: Add a delay before deployment (optional)
- Deployment branches: Restrict to
mainbranch only
Gestión segura de secretos
Section titled “Gestión segura de secretos”Utilice secretos específicos del entorno:
# 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 productionMonitoreo y Notificaciones
Section titled “Monitoreo y Notificaciones”Integración floja
Section titled “Integración floja”Agrega notificaciones de Slack a tu flujo de trabajo:
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 }}Integración de discordia
Section titled “Integración de discordia”Enviar notificaciones a 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 }}Notificaciones por correo electrónico
Section titled “Notificaciones por correo electrónico”Configurar notificaciones por correo electrónico:
- 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 }}Solución de problemas
Section titled “Solución de problemas”Flujo de trabajo de depuración
Section titled “Flujo de trabajo de depuración”Agregue pasos de depuración para solucionar problemas:
- 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 }}Problemas comunes y soluciones
Section titled “Problemas comunes y soluciones”El flujo de trabajo falla con “CAPGO_TOKEN no encontrado”:
- 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 }}Artefactos de compilación no encontrados:
- name: Debug artifacts run: | echo "Checking for build artifacts..." ls -la dist/ || echo "No dist directory found" find . -name "*.js" -o -name "*.html" | head -10Problemas de conectividad de red:
- name: Test connectivity run: | ping -c 3 api.capgo.io || echo "Ping failed" curl -I https://api.capgo.io/health || echo "Health check failed"Flujos de trabajo reutilizables
Section titled “Flujos de trabajo reutilizables”Create reusable workflows for consistency across projects:
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 }}Utilice el flujo de trabajo reutilizable:
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 }}Próximos pasos
Section titled “Próximos pasos”- Learn about Channels to manage different deployment environments
- Explore Custom Storage for advanced deployment scenarios
- Set up Encryption for secure deployments
- Configure Update Behavior to customize how updates are applied
Con la integración de acciones de GitHub, puede aprovechar la poderosa plataforma CI/CD de GitHub para crear flujos de trabajo de implementación sofisticados con funciones integradas de seguridad, monitoreo y colaboración para sus actualizaciones en vivo de Capgo.