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

GitLab CI for tag
然后您需要创建第一个 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 可以提交更改日志。
When you create the token, choose expiration as __CAPGO_KEEP_0__ and the scope as __CAPGO_KEEP_1__ never 和设置范围为 __CAPGO_KEEP_1__ repo.
最后,为了让工具了解你的版本保存在哪里,你需要创建一个文件 __CAPGO_KEEP_2__ .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"
]
将版本设置为这个文件的内容,和你在 __CAPGO_KEEP_3__ 文件中的版本保持一致。 package.json 这只需要在第一次使用时执行,之后工具会自动更新。
你可以现在提交这两个文件,看到你的第一个标签出现在 __CAPGO_KEEP_0__ 中!
GitHub 构建动作
GitHub actions for build
内容如下: .github/workflows/build.yml
将版本设置为这个文件的内容,和你在 __CAPGO_KEEP_3__ 文件中的版本保持一致。
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
This will install and build your dependency before sending it to 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.
前往您的GitHub控制台并检查刚刚出现的构建,您现在有了您的CI/CD系统。
如果您想让所有用户在可用时获得更新,请前往您的通道并将其设置为"自动"。
You should add your test in the build step to ensure your code is working.
Capgo
__CAPGO_KEEP_1__ public.
__CAPGO_KEEP_0__
如果您正在使用 与 Gitlab 自动构建和发布 来规划 CI/CD 自动化,连接它与 Capgo CI/CD 在 Capgo CI/CD 中的产品工作流程 Capgo 原生构建 在 Capgo 原生构建中 Capgo 集成 在 Capgo 集成中 CI/CD 集成 CI/CD 集成的实现细节 GitHub 动作集成 为 GitHub Actions Integration 的实现细节。