跳过主要内容

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

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

文章来源

马丁·多纳迪厄

作者

Valeria

审稿者

乔丹

编辑

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

本教程重点介绍了 GitHub 主机,但您可以通过稍微调整一下适用于任何其他 CI/CD 平台

序言

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

提交约定

首先,您需要遵循提交约定 conventional commits ` 这将有助于工具理解如何升级版本号,学习它只需 5 分钟

规范提交

GitHub Actions for tag

然后你需要创建第一个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.

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

为了使其工作,你需要创建一个 个人访问令牌 并将其添加到你的GitHub 密钥 as PERSONAL_ACCESS_TOKEN.

这有必要让CI提交changelog和版本号。

当您创建令牌时,选择过期时间为 never 并且范围为 repo.

设置 version 密钥在您的 package.json 文件中使用。使用该文件中的最后一个版本发布在商店中。

这只需要第一次,然后工具会自动更新。

您现在可以提交这两个文件并看到您的第一个标签出现在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 step.

如果您需要一个环境变量,请使用 MY_ENV_VAR 并设置 secret in your GitHub project setting, then secret then GitHub Action.

为了让Capgo上传工作,您需要获取您的API密钥,用于Capgo,并将其添加到 This will install and build your dependency before sending it to GitHub. as CAPGO_TOKEN.

You can now commit this both files and see your first version appear in Capgo!

and set the in your Capacitor project setting, then secret then __CAPGO_KEEP_1__ Action.

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

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

继续使用Manage development and production build with GitHub actions

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

Capacitor 应用实时更新

When a web-layer bug is live, ship the fix through Capgo instead of waiting days for app store approval. Users get the update in the background while native changes stay in the normal review path.

当 web 层 bug 活跃时,通过 __CAPGO_KEEP_0__ 发送修复,而不是等待 app 商店批准几天。用户在后台接收更新,而原生更改仍在正常审查路径中。

上下文: Capgo 营销网站。角色: 支持描述段落或元描述。见于组件 GetStarted.astro。保留 Capgo 产品/品牌和开发者术语的原始形式。

马丁的专业支持

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