本教程重点介绍了GitHub托管,但您可以轻松适应任何其他CI/CD平台。
前言
Be sure you have added your Capacitor app first to Capgo, this tutorial just focuses on the upload phase. If you need to add your app to Capgo, you can follow this 教程
提交规范
首先,您需要遵循提交规范 规范提交` 这将有助于工具了解如何升级版本号,学习它只需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原生构建 在Capgo原生构建中 Capgo 集成 为产品工作流程在 Capgo 集成中 CI/CD 集成 为 CI/CD 集成的实现细节 GitHub 动作集成 为 GitHub 动作集成的实现细节