使用 Chart Releaser Action 自动化 GitHub Pages 图表

本指南介绍了如何使用 Chart Releaser Action 自动化通过 GitHub Pages 发布图表。Chart Releaser Action 是一个 GitHub Action 工作流,它使用 helm/chart-releaser CLI 工具将 GitHub 项目变成自托管的 Helm 图表仓库。

仓库变更

在您的 GitHub 组织下创建一个 Git 仓库。您可以将仓库命名为 helm-charts,但其他名称也可以接受。所有图表的源代码可以放在 main 分支下。图表应放在目录树顶层的 /charts 目录下。

应该还有一个名为 gh-pages 的分支来发布图表。对该分支的更改将由此处描述的 Chart Releaser Action 自动创建。但是,您可以创建该 gh-branch 并添加 README.md 文件,该文件将对访问该页面的用户可见。

您可以在 README.md 中添加有关图表安装的说明,如下所示(替换 <alias><orgname><chart-name>):

## Usage

[Helm](https://helm.kubernetes.ac.cn) must be installed to use the charts.  Please refer to
Helm's [documentation](https://helm.kubernetes.ac.cn/docs) to get started.

Once Helm has been set up correctly, add the repo as follows:

  helm repo add <alias> https://<orgname>.github.io/helm-charts

If you had already added this repo earlier, run `helm repo update` to retrieve
the latest versions of the packages.  You can then run `helm search repo
<alias>` to see the charts.

To install the <chart-name> chart:

    helm install my-<chart-name> <alias>/<chart-name>

To uninstall the chart:

    helm delete my-<chart-name>

图表将发布到 URL 类似于这样的网站:

https://<orgname>.github.io/helm-charts

GitHub Actions 工作流

main 分支的 .github/workflows/release.yml 中创建一个 GitHub Actions 工作流文件

name: Release Charts

on:
  push:
    branches:
      - main

jobs:
  release:
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Configure Git
        run: |
          git config user.name "$GITHUB_ACTOR"
          git config user.email "$GITHUB_ACTOR@users.noreply.github.com"

      - name: Run chart-releaser
        uses: helm/chart-releaser-action@v1.6.0
        env:
          CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

以上配置使用 @helm/chart-releaser-action 将您的 GitHub 项目变成一个自托管的 Helm 图表仓库。它在每次推送到 main 时通过检查您项目中的每个图表来实现这一点。只要有新图表版本,就会创建一个与图表版本同名的 GitHub 发布,将 Helm 图表工件添加到发布,并创建或更新一个包含有关这些发布的元数据的 index.yaml 文件,该文件随后将托管在 GitHub Pages 上。

以上示例中使用的 Chart Releaser Action 版本号是 v1.6.0。您可以将其更改为 最新可用版本

注意:Chart Releaser Action 几乎总是与 Helm 测试操作Kind 操作 结合使用。