Publish Bitnami Helm Chart #76
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Bitnami Helm Chart | |
| concurrency: | |
| group: ${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| packages: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bitnami_repo: | |
| description: "Bitnami charts repository" | |
| default: "https://github.com/bitnami/charts.git" | |
| required: true | |
| ghcr_namespace: | |
| description: "Base GHCR namespace (for images and charts)" | |
| default: "ghcr.io/platform-mesh/upstream-images" | |
| required: true | |
| chart_tag: | |
| description: "Chart tag to process (e.g. nginx/15.2.1)" | |
| default: "keycloak/25.2.5" | |
| required: true | |
| env: | |
| BITNAMI_REPO: ${{ github.event.inputs.bitnami_repo }} | |
| WORKDIR: './charts-workdir' | |
| CHART_TAG: ${{ github.event.inputs.chart_tag }} | |
| CHART_NAMESPACE: ${{ github.event.inputs.ghcr_namespace }}/charts | |
| jobs: | |
| clone-chart: | |
| name: Clone Chart | |
| runs-on: ubuntu-latest | |
| outputs: | |
| chart_path: ${{ steps.clone.outputs.chart_path }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - id: clone | |
| run: | | |
| mkdir -p "${{ env.WORKDIR }}" | |
| tool=$(echo "${{ env.CHART_TAG }}" | cut -d/ -f1) | |
| version=$(echo "${{ env.CHART_TAG }}" | cut -d/ -f2) | |
| chart_path="${{ env.WORKDIR }}/${tool}" | |
| rm -rf "${chart_path}" | |
| git init "${chart_path}" | |
| git -C "${chart_path}" remote add origin "${{ env.BITNAMI_REPO }}" | |
| git -C "${chart_path}" config core.sparseCheckout true | |
| echo "bitnami/${tool}" > "${chart_path}/.git/info/sparse-checkout" | |
| git -C "${chart_path}" fetch --depth 1 origin "refs/tags/${{ env.CHART_TAG }}:refs/tags/${{ env.CHART_TAG }}" | |
| git -C "${chart_path}" checkout "tags/${{ env.CHART_TAG }}" | |
| if [[ -d "${chart_path}/bitnami/${tool}" ]]; then | |
| mv "${chart_path}/bitnami/${tool}"/* "${chart_path}/" | |
| rm -rf "${chart_path}/bitnami" | |
| fi | |
| ls -R "${chart_path}" | |
| test -f "${chart_path}/values.yaml" || (echo "values.yaml not found in ${chart_path}" && exit 1) | |
| echo "chart_path=${chart_path}" >> $GITHUB_OUTPUT | |
| - name: Upload chart as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: chart | |
| path: ${{ env.WORKDIR }} | |
| update-deps: | |
| name: Update Dependencies | |
| needs: [clone-chart] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download chart artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: chart | |
| path: ${{ env.WORKDIR }} | |
| - name: Update chart dependencies | |
| env: | |
| GHCR_USER: ${{ github.actor }} | |
| GHCR_PAT: ${{ secrets.GHCR_PAT }} | |
| CHART_NAMESPACE: ${{ env.CHART_NAMESPACE }} | |
| run: | | |
| chart_path="${{ needs.clone-chart.outputs.chart_path }}" | |
| chart_yaml="${chart_path}/Chart.yaml" | |
| chart_lock="${chart_path}/Chart.lock" | |
| if [[ ! -f "${chart_lock}" ]]; then | |
| echo "[WARN] No Chart.lock found, skipping dependency update." >&2 | |
| exit 0 | |
| fi | |
| echo "[INFO] Logging in to GHCR..." | |
| if ! echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login "$CHART_NAMESPACE" --username "$GHCR_USER" --password-stdin; then | |
| echo "[ERROR] Failed to login to GHCR" >&2 | |
| exit 1 | |
| fi | |
| dep_count=$(yq eval '.dependencies | length' "${chart_lock}") | |
| missing_deps=() | |
| for i in $(seq 0 $((dep_count - 1))); do | |
| name=$(yq eval ".dependencies[${i}].name" "${chart_lock}") | |
| repo=$(yq eval ".dependencies[${i}].repository" "${chart_lock}") | |
| version=$(yq eval ".dependencies[${i}].version" "${chart_lock}") | |
| if [[ "$repo" == *"bitnami"* ]]; then | |
| dep_repo="oci://${CHART_NAMESPACE}" | |
| dep_target="${dep_repo}/${name}:${version}" | |
| echo "[INFO] Updating dependency ${name} -> repository: ${dep_repo}, version: ${version}" | |
| # Update Chart.yaml with exact repo/version | |
| yq eval --inplace " | |
| .dependencies[] |= (select(.name == \"${name}\") | .repository = \"${dep_repo}\" | .version = \"${version}\") | |
| " "${chart_yaml}" | |
| # Check if chart exists in GHCR | |
| if ! helm pull "$dep_target" --destination /tmp >/dev/null 2>&1; then | |
| echo "[WARN] Chart not found in registry: ${dep_target}" | |
| missing_deps+=("${name}:${version}") | |
| else | |
| echo "[INFO] Chart exists in registry: ${dep_target}" | |
| fi | |
| fi | |
| done | |
| if [[ ${#missing_deps[@]} -gt 0 ]]; then | |
| echo "[ERROR] The following charts must be built/pushed first:" >&2 | |
| for dep in "${missing_deps[@]}"; do | |
| echo " - ${dep}" >&2 | |
| done | |
| exit 1 | |
| fi | |
| - name: Upload updated chart | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: chart | |
| path: ${{ env.WORKDIR }} | |
| overwrite: true | |
| package-push-chart: | |
| name: Package & Push Chart | |
| runs-on: ubuntu-latest | |
| needs: [update-deps,clone-chart] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download chart artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: chart | |
| path: ${{ env.WORKDIR }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Helm | |
| run: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io \ | |
| --username "${{ github.actor }}" \ | |
| --password-stdin | |
| - name: Rebuild Helm dependencies | |
| run: | | |
| chart_path="${{ needs.clone-chart.outputs.chart_path }}" | |
| rm -f "${chart_path}/Chart.lock" | |
| helm dependency build "${chart_path}" | |
| echo "CHART_PATH=${chart_path}" >> $GITHUB_ENV | |
| - name: Push Helm chart | |
| uses: bsord/helm-push@51f937208fed71540ab5ec5215cf9b3ecae9c7b7 # v4.2.0 | |
| with: | |
| useOCIRegistry: true | |
| username: ${{ github.actor }} | |
| access-token: ${{ secrets.GITHUB_TOKEN }} | |
| registry-url: oci://ghcr.io/${{ github.repository }}/charts | |
| chart-folder: ${{ env.CHART_PATH }} |