本教程重点介绍了GitHub托管,但您可以轻松适应任何其他CI/CD平台。
前言
确保您已将Capacitor应用程序添加到Capgo中,这个教程只关注上传阶段。 如果您需要将应用程序添加到Capgo中,请遵循本 教程
提交规范
首先你需要遵循提交规范 规范提交` 这将有助于工具了解如何升级版本号,学习它只需5分钟。`

GitHub 标签操作
然后你需要创建第一个 GitHub 动作来自动构建和创建标签。
在这个路径创建一个文件: .github/workflows/bump_version.yml
内容如下:
name: Bump version
on:
push:
branches:
- main
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
run: npx capacitor-standard-version
- 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
这将为每个主分支的提交发布一个标签,并为每个主分支的提交添加一个更改日志条目。 CHANGELOG.md.
如果你没有这个文件,不用担心,它会自动创建。
为了使其工作,创建一个 个人访问令牌 并将其添加到您的GitHub 秘密 作为 PERSONAL_ACCESS_TOKEN.
这有必要让CI提交changelog。
当您创建令牌时,请选择 never 和范围为 repo.
最后,设置您的 package.json 文件,同步您的本机版本号,以便简化,然后下一步。
这只在第一次必要,工具将保持最新状态。
您现在可以提交这两个文件并看到您的第一个标签出现在GitHub!
两者本地和web平台都会在每次提交后更新版本号。
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 run build
env: # Remove both lines if you don't need it
FIREBASE_CONFIG: ${{ secrets.FIREBASE_CONFIG }} # Example of env var coming from a secret
- name: Create Release
id: create_release
run: npx @capgo/cli@latest bundle upload -a ${{ secrets.CAPGO_TOKEN }} -c production
这将在发送给 Capgo 之前安装和构建您的依赖项。
如果您的构建命令不同,您可以在步骤中更改它。 build_code 要使其工作,您需要获取您的 __CAPGO_KEEP_0__ 密钥并将其添加到您的 __CAPGO_KEEP_1__ 的密钥中,然后将其添加到您的 __CAPGO_KEEP_0__ 仓库的密钥中。
To make this work, you need to get your API key for Capgo, add it in the secret of your GitHub repository __CAPGO_KEEP_0__ CAPGO_TOKEN.
You can now commit this both files and see your first tag appear in GitHub!
__CAPGO_KEEP_0__
您应该在构建步骤中添加您的测试,以确保您的code正在工作中.
前往您的Capgo控制台,检查刚刚出现的构建,您现在已经拥有了CI/CD系统.
如果您想让所有用户在可用时立即获得更新,请转到您的频道并设置为 public.
您还可以通过遵循此教程添加Ionic Capacitor JavaScript应用的原生构建 👇
继续使用自动构建和发布应用程序的Github动作
如果您正在使用 自动构建和发布应用程序的Github动作 来规划CI/CD自动化,连接它与 Capgo CI/CD 为Capgo CI/CD中的产品工作流程 Capgo Native Builds 为Capgo Native Builds中的产品工作流程, Capgo 集成 为产品工作流程在 Capgo 集成中 CI/CD 集成 为 CI/CD 集成的实现细节 GitHub 动作集成 为 GitHub 动作集成的实现细节