跳过主要内容
CI/CD

使用GitHub管理开发和生产构建

使用Capgo将开发构建发布到特定频道,允许您的团队尝试Capacitor Ionic 应用程序,而无需等待苹果和谷歌的审查

马丁·多纳迪尤

马丁·多纳迪尤

内容营销人员

使用GitHub管理开发和生产构建

This tutorial focuses on the GitHub hosting, but you can adapt it with a little tweak to any other CI/CD platform.

序言

确保您已经在 Capgo 中添加了您的 Capacitor 应用程序,这个教程只关注上传阶段

提交约定

首先,您需要遵循提交约定 规范提交` 这将有助于工具理解如何升级版本号,花费 5 分钟学习即可。

规范提交

GitHub 动作标签

然后您需要创建第一个 GitHub 动作来自动构建和创建标签

在此路径创建一个文件: .github/workflows/bump_version.yml

内容如下:

name: Bump version

on:
  push:
    branches:
      - main
      - development

jobs:
  bump-version:
    if: "!startsWith(github.event.head_commit.message, 'chore(release):')"
    runs-on: ubuntu-latest
    name: "Bump version and create changelog with standard version"
    steps:
      - name: Check out
        uses: actions/checkout@v6
        with:
          fetch-depth: 0
          filter: blob:none
          token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
      - name: Git config
        run: |
          git config --local user.name "github-actions[bot]"
          git config --local user.email "github-actions[bot]@users.noreply.github.com"
      - name: Create bump and changelog
        if: github.ref == 'refs/heads/main'
        run: npx capacitor-standard-version
      - name: Create bump and changelog
        if: github.ref != 'refs/heads/main'
        run: npx capacitor-standard-version --prerelease alpha
      - name: Push to origin
        run: |
          CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
          remote_repo="https://${GITHUB_ACTOR}:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
          git pull $remote_repo $CURRENT_BRANCH
          git push $remote_repo HEAD:$CURRENT_BRANCH --follow-tags --tags

每次你在主分支提交代码时都会发布一个标签。并且会发布一个 alpha 的版本,最后会为每个提交生成一个 development的更新日志。 CHANGELOG.md.

如果你没有这个文件,不用担心,它会自动创建。

为了让这个功能正常工作,你需要创建一个 PERSONAL ACCESS TOKEN GitHub 的密钥 密钥 PERSONAL_ACCESS_TOKEN.

作为

你需要选择 never 并且范围为 repo.

设置 version 在你的 package.json 文件中使用最新版本的

仅在第一次使用时需要,之后工具将自动更新。

You can now commit this both files and see your first tag appear in GitHub!

capacitor-standard-version 是负责魔法的包, 默认情况下,它还会在 Android 和 IOS 中更新版本号

GitHub actions for build

在这个路径创建一个文件: .github/workflows/build.yml

内容如下:

name: Build source code and send to Capgo

on:
  push:
    tags:
      - '*'
      
jobs:
  deploy:
    runs-on: ubuntu-latest
    name: "Build code and release"
    steps:
      - name: Check out
        uses: actions/checkout@v6
      - name: Install dependencies
        id: install_code
        run: npm i
      - name: Build
        id: build_code
        run: npm build
        env:
          MY_ENV_VAR: ${{ secrets.MY_ENV_VAR }}
      - name: Create Release Alpha
        if: "contains(github.ref, '-alpha.')"
        id: create_release_prepro
        run: npx @capgo/cli@latest bundle upload -a ${{ secrets.CAPGO_TOKEN }} -c development
      - name: Create Release Production
        if: "!contains(github.ref, '-alpha.')"
        id: create_release_prod
        run: npx @capgo/cli@latest bundle upload -a ${{ secrets.CAPGO_TOKEN }} -c production

This will install and build your dependency before sending it to Capgo.

如果你的构建命令不同,你可以在这里进行更改 build_code 步骤。

如果您需要一个环境变量,请使用 MY_ENV_VAR 并设置 secret 在您的GitHub项目设置中,然后秘密然后GitHub动作。

要使Capgo上传工作,您需要获取您的API密钥,Capgo,并将其添加到 您的GitHub仓库的 作为 CAPGO_TOKEN.

您现在可以提交这两个文件并看到您的第一个版本出现在Capgo中!

添加提交将生成一个新的Capacitor生产和开发通道的构建。

您应该在Ionic构建步骤中添加您的测试,以确保您的code正在工作。

前往您的Capgo控制台并检查刚刚出现的构建,您现在有了您的CI/CD系统。

继续管理开发和生产构建与GitHub动作

如果您正在使用 使用 GitHub 动作管理开发和生产构建 来规划渠道路由和阶段性发布,连接它与 渠道 查看渠道的实施细节在渠道中 渠道 查看渠道的实施细节在渠道中 渠道 查看渠道的实施细节在渠道中 Beta 测试解决方案 查看 Beta 测试解决方案中的产品工作流程, 版本目标解决方案 用于产品工作流程的版本目标解决方案。

从管理开发和生产构建继续,使用 Capacitor 操作

当一个 web层 bug 活跃时,通过 Capgo 将修复推送到应用商店,而不是等待几天的审批时间。用户在后台接收更新,而原生变化仍然在正常的审批路径中。

立即开始

最新博客

Capgo 为您提供创建真正专业的移动应用所需的最佳见解。