| # |
| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| # |
| |
| name: Helm Chart |
| |
| on: |
| workflow_dispatch: |
| inputs: |
| publish: |
| description: "Publish the packaged chart to gh-pages" |
| required: true |
| default: "false" |
| type: choice |
| options: |
| - "false" |
| - "true" |
| |
| permissions: |
| contents: write |
| |
| concurrency: |
| group: helm-chart-publish |
| cancel-in-progress: false |
| |
| env: |
| CHART_REPO_URL: https://apache.github.io/druid-operator |
| CHART_RELEASE_DIR: helm-releases |
| |
| jobs: |
| publish: |
| if: github.repository == 'apache/druid-operator' |
| runs-on: ubuntu-latest |
| steps: |
| - name: Checkout source |
| uses: actions/checkout@v4 |
| with: |
| path: source |
| |
| - name: Checkout gh-pages |
| uses: actions/checkout@v4 |
| with: |
| ref: gh-pages |
| path: gh-pages |
| |
| - name: Verify Helm |
| run: helm version |
| |
| - name: Package chart |
| run: | |
| mkdir -p source/.chart-packages |
| helm lint source/chart |
| helm package source/chart --destination source/.chart-packages |
| |
| - name: Verify chart metadata |
| run: | |
| package_path="$(find source/.chart-packages -name '*.tgz' -print -quit)" |
| test -n "${package_path}" |
| |
| tar -tzf "${package_path}" | grep -Eq '^[^/]+/LICENSE$' |
| tar -tzf "${package_path}" | grep -Eq '^[^/]+/NOTICE$' |
| |
| - name: Update Helm repository index |
| if: inputs.publish == 'true' |
| run: | |
| package_path="$(find source/.chart-packages -name '*.tgz' -print -quit)" |
| package_name="$(basename "${package_path}")" |
| release_dir="gh-pages/${CHART_RELEASE_DIR}" |
| |
| mkdir -p "${release_dir}" |
| |
| if [[ -f "${release_dir}/${package_name}" ]]; then |
| echo "Chart package ${package_name} already exists on gh-pages." |
| exit 1 |
| fi |
| |
| cp "${package_path}" "${release_dir}/" |
| |
| if [[ -f gh-pages/index.yaml ]]; then |
| helm repo index gh-pages --url "${CHART_REPO_URL}" --merge gh-pages/index.yaml |
| else |
| helm repo index gh-pages --url "${CHART_REPO_URL}" |
| fi |
| |
| - name: Publish chart |
| if: inputs.publish == 'true' |
| run: | |
| chart_version="$(helm show chart source/chart | awk '/^version:/ { print $2 }')" |
| |
| cd gh-pages |
| git config user.name "github-actions[bot]" |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| git add index.yaml "${CHART_RELEASE_DIR}" |
| |
| if git diff --cached --quiet; then |
| echo "No chart changes to publish." |
| exit 0 |
| fi |
| |
| git commit -m "Publish druid-operator chart ${chart_version}" |
| git push origin HEAD:gh-pages |