From c4385b69d2515097edb9182cbc5c3934d22bf558 Mon Sep 17 00:00:00 2001 From: Kazuki Suda Date: Wed, 7 Dec 2022 22:13:29 +0900 Subject: [PATCH] Support packaging and pushing a specified chart only Signed-off-by: Kazuki Suda --- README.md | 21 ++++++++++++++++++++- action.yml | 6 +++++- src/entrypoint.sh | 12 ++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f49b4b..6983f46 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A GitHub Action for publishing Helm charts with Github Pages. Inputs: * `token` The GitHub token with write access to the target repository -* `charts_dir` The charts directory, defaults to `charts` +* `charts_dir` The charts directory, defaults to `charts`. It cannot be used with `chart_dir`. * `charts_url` The GitHub Pages URL, defaults to `https://.github.io/` * `owner` The GitHub user or org that owns this repository, defaults to the owner in `GITHUB_REPOSITORY` env var * `repository` The GitHub repository, defaults to the `GITHUB_REPOSITORY` env var @@ -21,6 +21,7 @@ Inputs: * `index_dir` The location of `index.yaml` file in the repo, defaults to the same value as `target_dir` * `enterprise_url` The URL of enterprise github server in the format `/` * `dependencies` A list of helm repositories required to verify dependencies in the format `,;,` or if using private repositories `,,,;,,,`. Combinations are allowed. +* `chart_dir` The specified chart directory, e.g. charts/wordpress. It cannot be used with `charts_dir`. ## Examples @@ -88,3 +89,21 @@ jobs: app_version: 1.16.0 chart_version: 0.1.0 ``` +Package and push the specified chart in `./charts/wordpress` dir to `gh-pages` branch: +```yaml +name: release +on: + push: + tags: '*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Publish Helm charts + uses: stefanprodan/helm-gh-pages@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + chart_dir: charts/wordpress +``` diff --git a/action.yml b/action.yml index 946063d..439b5c8 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,7 @@ inputs: description: "GitHub token" required: true charts_dir: - description: "The charts directory, defaults to `charts`" + description: "The charts directory, defaults to `charts`. It cannot be used with `chart_dir`." required: false charts_url: description: "The GitHub Pages URL, defaults to `https://.github.io/`" @@ -55,6 +55,9 @@ inputs: dependencies: description: "A list of helm repositories required to verify dependencies in the format ',;,'" required: false + chart_dir: + description: "The specified chart directory,, e.g. charts/wordpress. It cannot be used with `charts_dir`." + required: false runs: using: 'docker' image: 'Dockerfile' @@ -75,3 +78,4 @@ runs: - ${{ inputs.index_dir }} - ${{ inputs.enterprise_url }} - ${{ inputs.dependencies }} + - ${{ inputs.chart_dir }} diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 374ceb8..879ccbd 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -33,6 +33,7 @@ CHART_VERSION=${13} INDEX_DIR=${14} ENTERPRISE_URL=${15} DEPENDENCIES=${16} +CHART_DIR=${17} CHARTS=() CHARTS_TMP_DIR=$(mktemp -d) @@ -40,6 +41,11 @@ REPO_ROOT=$(git rev-parse --show-toplevel) REPO_URL="" main() { + if [[ -n "$CHARTS_DIR" ]] && [[ -n "$CHART_DIR" ]]; then + echo '"Both charts_dir" and "chart_dir" cannot be specified' >&2 + exit 1 + fi + if [[ -z "$HELM_VERSION" ]]; then HELM_VERSION="3.10.0" fi @@ -104,6 +110,12 @@ main() { } locate() { + if [[ -n "$CHART_DIR" ]]; then + echo "Use the specific chart directory ${CHART_DIR}" + CHARTS+=( "$CHART_DIR" ) + return + fi + for dir in $(find "${CHARTS_DIR}" -type d -mindepth 1 -maxdepth 1); do if [[ -f "${dir}/Chart.yaml" ]]; then CHARTS+=("${dir}")