圖表發布動作,用於自動化 GitHub 頁面圖表
本指南說明如何使用 圖表發布動作,透過 GitHub 頁面自動發布圖表。圖表發布動作是一種 GitHub 動作工作流程,使用 helm/chart-releaser CLI 工具,將 GitHub 專案轉換為自管 Helm 圖表儲存庫。
儲存庫變更
在您的 GitHub 組織下建立 Git 儲存庫。您可以將儲存庫命名為 helm-charts
,但也可以使用其他名稱。所有圖表的來源都可以放在 main
分支下。圖表應放置在目錄樹頂層的 /charts
目錄下。
應該有另一個名為 gh-pages
的分支來發布圖表。該分支的變更將由這裡說明的圖表發布動作自動建立。但是,您可以建立 gh-branch
並新增 README.md
檔案,該檔案將對造訪該頁面的使用者可見。
您可以在 README.md
中新增圖表安裝說明,如下所示(替換 <alias>
、<orgname>
和 <chart-name>
)
## Usage
[Helm](https://helm.dev.org.tw) must be installed to use the charts. Please refer to
Helm's [documentation](https://helm.dev.org.tw/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>
圖表將發布到網址如下所示的網站
https://<orgname>.github.io/helm-charts
GitHub 動作工作流程
在 main
分支的 .github/workflows/release.yml
中建立 GitHub 動作工作流程檔案
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 頁面上。
上述範例中使用的圖表發布動作版本號碼為 v1.6.0
。您可以將其更改為 最新的可用版本。