[GitHub Integrasi Aksi]
Copy sebuah prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
Integrasikan Capgo Live Updates dengan GitHub Actions untuk memperbarui aplikasi Anda secara otomatis setiap kali Anda memasukkan code perubahan. Panduan ini menjelaskan cara mengatur build otomatis, pengujian, dan alur kerja pengiriman menggunakan GitHub’s platform CI/CD yang kuat.
Prasyarat
Bab berjudul “Prasyarat”Sebelum mengatur integrasi GitHub Actions, pastikan Anda memiliki:
- A GitHub repository with your app’s source code
- Akun Capgo dengan aplikasi yang telah dikonfigurasi
- Node.js dan npm/yarn yang telah dikonfigurasi di proyek Anda
- GitHub Actions yang telah diaktifkan untuk repositori Anda
Pengaturan GitHub Rahasia
Bab yang berjudul “Pengaturan GitHub Rahasia”Langkah 1: Konfigurasi Rahasia Repositori
Bab yang berjudul “Langkah 1: Konfigurasi Rahasia Repositori”Konfigurasi rahasia yang diperlukan di repositori GitHub Anda:
- Navigasi ke repositori GitHub Anda
- Pergi ke Pengaturan → Rahasia dan variabel → Aksi
- Klik Rahasia Repositori Baru dan tambahkan berikut:
| Nama Rahasia | Nilai |
|---|---|
CAPGO_TOKEN | Token Capgo API Anda |
Deployan Produksi Sederhana
Judul Bagian “Deployan Produksi Sederhana”Mulai dengan konfigurasi dasar ini yang mengirimkan ke produksi setiap kali push ke cabang utama:
# 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 }}"Konfigurasi Lanjutan Multi-Channel
Judul Bagian “Konfigurasi Lanjutan Multi-Channel”Deployan Cabang Fitur
Judul Bagian “Deployan Cabang Fitur”Deploy cabang fitur ke saluran sementara untuk tes:
# 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_NAMEMenggunakan Enkripsi
Judul Bagian “Menggunakan Enkripsi”Jika Anda menggunakan fitur enkripsi Capgo, Anda perlu menyimpan kunci pribadi Anda dengan aman di lingkungan CI/CD Anda.
Setelah mengatur kunci enkripsi di lokal, tambahkan kunci pribadi Anda ke rahasia GitHub:
# Display your private key content (copy this output)cat .capgo_key_v2Tambahkan konten ini sebagai CAPGO_PRIVATE_KEY di rahasia GitHub Anda di repositori, lalu gunakan di workflow:
# 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 productionKonfigurasi Multi-Channel
Bab yang berjudul “Konfigurasi Multi-Channel”Untuk informasi yang lebih komprehensif tentang mengatur dan mengelola beberapa saluran pengiriman, lihat dokumentasi Dokumentasi Saluran.
Alur kerja yang lengkap dengan pengembangan, permintaan pull, dan pengiriman produksi:
# 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 productionPembersihan Fitur Saluran
Bab berjudul “Pembersihan Fitur Saluran”Otomi membersihkan saluran fitur secara otomatis ketika cabang dihapus:
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 }} || trueKeamanan dan Praktik Terbaik
Bab berjudul “Keamanan dan Praktik Terbaik”Aturan Perlindungan Lingkungan
Aturan Perlindungan LingkunganKonfigurasi aturan perlindungan lingkungan di GitHub:
- Pergi ke Pengaturan → Lingkungan di repositori Anda
- Buat lingkungan:
development,staging,production - Untuk lingkungan produksi, tambahkan:
- Pengulas Wajib: Tambahkan anggota tim yang harus menyetujui pengiriman
- Timer Tunggu: Tambahkan jeda sebelum pengiriman (opsional)
- Branch Pengembangan: Hanya Batasi ke
mainBranch Hanya
Pengelolaan Rahasia yang Aman
Judul Bagian “Pengelolaan Rahasia yang Aman”Gunakan rahasia spesifik lingkungan:
# 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 productionPantauan dan Pemberitahuan
Judul Bagian “Pantauan dan Pemberitahuan”Pengintegrasian Slack
Judul Bagian “Pengintegrasian Slack”Tambahkan pemberitahuan Slack ke alur kerja Anda:
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 }}Integrasi Discord
Bab berjudul “Integrasi Discord”Kirim pemberitahuan ke 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 }}Pemberitahuan Email
Bab berjudul “Pemberitahuan Email”Konfigurasi pemberitahuan email:
- 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 }}Pengaturan
Bab berjudul “Pengaturan”Alur Debug
Alur DebuggingTambahkan langkah debugging untuk menyelesaikan masalah:
- 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 }}Masalah Umum dan Solusi
Alur DebuggingAlur gagal dengan pesan “CAPGO_TOKEN tidak ditemukan”:
- 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 }}Artefak pembangunan tidak ditemukan:
- name: Debug artifacts run: | echo "Checking for build artifacts..." ls -la dist/ || echo "No dist directory found" find . -name "*.js" -o -name "*.html" | head -10Masalah koneksi jaringan:
- name: Test connectivity run: | ping -c 3 api.capgo.io || echo "Ping failed" curl -I https://api.capgo.io/health || echo "Health check failed"Alur yang Dapat Dikembalikan
Judul Bagian ‘Penggunaan Ulang’Buat penggunaan ulang untuk konsistensi di antara proyek:
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 }}Pakai penggunaan ulang:
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 }}Langkah-Langkah Selanjutnya
Konteks: Halaman/area: Capgo Builder / produk halaman build awan asli. Peran: Label UI pendek atau item navigasi. Pesan kunci `native_build_builder_credit_next` (Kredit Pembangun Build Asli Berikut).- Judul Bagian ‘Langkah-Langkah Selanjutnya’ Pelajari tentang Saluran-Saluran Pengiriman ‘Saluran’ untuk mengelola lingkungan pengiriman yang berbeda
- Temukan Penyimpanan Kustom untuk skenario penggunaan yang lebih maju
- Konfigurasi Enkripsi untuk penggunaan yang lebih aman
- Konfigurasi Perilaku Update untuk mengatur bagaimana update diterapkan
Dengan integrasi GitHub Actions, Anda dapat memanfaatkan kemampuan GitHub’s CI/CD yang kuat untuk membuat alur kerja penggunaan yang canggih dengan fitur keamanan, pemantauan, dan kolaborasi yang terintegrasi untuk Capgo Live Updates Anda.
Teruskan dari GitHub Actions Integration
Judul bagian “Teruskan dari GitHub Actions Integration”If Anda menggunakan __CAPGO_KEEP_0__ Integrasi Aksi GitHub Integrasi Aksi untuk merencanakan otomatisasi CI/CD, hubungkan dengan __CAPGO_KEEP_0__ CI/CD Capgo CI/CD untuk alur kerja produk di Capgo CI/CD, Capgo Pembangunan Asli untuk alur kerja produk di Capgo Pembangunan Asli, Capgo Integrasi untuk alur kerja produk di Capgo Integrasi, Integrasi CI/CD untuk detail implementasi di Integrasi CI/CD, dan Integrasi CI GitLab untuk detail implementasi di Integrasi GitLab CI/CD.