跳过主要内容
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.

前言

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

提交约定

首先,您需要遵循提交约定 规范提交` 这将有助于工具理解如何升级版本号码,花费 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

这将为您的主 branch 中的每个提交发布一个标签。并且, alpha 发布 development, and lastly a changelog entry for each commit in CHANGELOG.md.

最后,

不用担心,如果你没有这个文件,它会自动创建。 为了使其工作,需要创建一个 and add it to your GitHub __CAPGO_KEEP_0__ secrets PERSONAL_ACCESS_TOKEN.

secrets

这是必要的,以便 CI 可以提交更改日志和版本号 never and the scope as repo.

Set the version key in your package.json file. Use for that the last version released in The store.

This is only necessary the first time, then the tools will keep it up to date.

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

capacitor-standard-version 是这个包做的魔法, 默认情况下,他也会更新你的 Android 和 IOS 的版本号

GitHub 构建动作

在这个路径创建一个文件: .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

这将安装并构建你的依赖项,然后将其发送到 Capgo。

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

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

要使Capgo上传工作,您需要获取您的API密钥Capgo,并将其添加到Capgo仓库的 secret of your GitHub repository 您现在可以提交这两个文件并看到您的第一个版本出现在__CAPGO_KEEP_0__中! CAPGO_TOKEN.

添加提交将生成新的Capgo生产和开发渠道的构建。

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

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

继续使用Capgo动作管理开发和生产构建

GitHub

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

Capacitor 应用的实时更新

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

立即开始

最新博客

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