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

GitLab CI标签
然后您需要创建第一个GitLab来自动构建和创建标签。
创建一个文件到这个路径: .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.
如果您不了解这个文件,不用担心,它将为您创建。
要使其工作,请创建一个 个人访问令牌 并将其添加到您的 GitLab CI/CD 变量中 PERSONAL_ACCESS_TOKEN.
这有必要让 CI 提交更改日志
当您创建令牌时,请选择过期时间为 never 并将范围设置为 repo.
最后,要让工具了解您的版本保存在哪里,您必须创建一个文件 .cz.toml 在您的仓库根目录
并添加以下内容:
[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$major.$minor.$patch$prerelease"
version = "0.11.5"
version_files = [
"package.json:version",
".cz.toml"
]
将版本设置为此文件中的同一个版本,您在文件 package.json 中保存的版本
这只需要第一次,然后工具将自动更新
您现在可以提交这两个文件并看到您的第一个标签出现在 GitHub!
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 您现在可以提交这两个文件并在 GitHub 中看到您的第一个标签! 添加提交将为生产频道生成一个新的构建。 CAPGO_TOKEN.
您应该在构建步骤中添加您的测试,以确保您的 GitHub 正在工作。
前往您的 __CAPGO_KEEP_0__ 控制台并检查刚刚出现的构建,您现在有了您的 CI/CD 系统。
You should add your test in the build step to ensure your code is working.
Go To your Capgo dashboard and check your build who just appeared, you now have your CI/CD system.
If you want to let all of your users get the update whenever it’s available, go to your channel and set it to public.
Keep going from Automatic build and release with Gitlab
If you are using Automatic build and release with Gitlab to plan CI/CD automation, connect it with Capgo CI/CD for the product workflow in Capgo CI/CD Capgo Native Builds for the product workflow in Capgo Native Builds Capgo Integrations for the product workflow in Capgo Integrations CI/CD Integration 为 CI/CD Integration 的实现细节 GitHub Actions Integration 为 GitHub Actions Integration 的实现细节