|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright Materialize, Inc. and contributors. All rights reserved. |
| 4 | +# |
| 5 | +# Use of this software is governed by the Business Source License |
| 6 | +# included in the LICENSE file at the root of this repository. |
| 7 | +# |
| 8 | +# As of the Change Date specified in that file, in accordance with |
| 9 | +# the Business Source License, use of this software will be governed |
| 10 | +# by the Apache License, Version 2.0. |
| 11 | + |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +. misc/shlib/shlib.bash |
| 15 | + |
| 16 | +CHARTS_DIR=misc/helm-charts |
| 17 | +# TODO: Switch back to gh-pages before merging |
| 18 | +# GITHUB_PAGES_BRANCH=gh-pages |
| 19 | +GITHUB_PAGES_BRANCH=gh-pages-test |
| 20 | +RELEASE_DIR=.cr-release-packages |
| 21 | + |
| 22 | +# Find directories containing Chart.yaml |
| 23 | +CHARTS="" |
| 24 | +for dir in "$CHARTS_DIR"/*/; do |
| 25 | + if [ -f "${dir}Chart.yaml" ]; then |
| 26 | + chart_name=$(basename "$dir") |
| 27 | + CHARTS="${CHARTS:+${CHARTS} }$chart_name" |
| 28 | + fi |
| 29 | +done |
| 30 | +if [ -z "$CHARTS" ]; then |
| 31 | + echo "No valid Helm charts found" |
| 32 | + exit 0 |
| 33 | +fi |
| 34 | +echo "Found valid charts: $CHARTS" |
| 35 | + |
| 36 | +git fetch origin |
| 37 | +git checkout $GITHUB_PAGES_BRANCH |
| 38 | + |
| 39 | +mkdir -p $RELEASE_DIR |
| 40 | +CHANGES_MADE=0 |
| 41 | +for CHART in $CHARTS; do |
| 42 | + CHART_PATH="$CHARTS_DIR/$CHART" |
| 43 | + VERSION=$(yq eval '.version' "$CHART_PATH"/Chart.yaml) |
| 44 | + echo "Processing chart: $CHART version: $VERSION" |
| 45 | + # Check if version already exists |
| 46 | + if [ -f "gh-pages/$CHART-$VERSION.tgz" ]; then |
| 47 | + echo "Chart $CHART version $VERSION already exists, skipping" |
| 48 | + continue |
| 49 | + fi |
| 50 | + # Lint chart |
| 51 | + if ! helm lint "$CHART_PATH"; then |
| 52 | + echo "Linting failed for $CHART" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + # Package chart |
| 56 | + helm package "$CHART_PATH" --destination $RELEASE_DIR |
| 57 | + CHANGES_MADE=1 |
| 58 | +done |
| 59 | +# Only proceed if we have new packages |
| 60 | +if [ $CHANGES_MADE -eq 1 ]; then |
| 61 | + # Copy new charts to gh-pages |
| 62 | + cp $RELEASE_DIR/*.tgz gh-pages/ |
| 63 | + # Update the repository index |
| 64 | + cd gh-pages |
| 65 | + REPO_URL="https://materialize.github.io/materialize" |
| 66 | + if [ -f index.yaml ]; then |
| 67 | + helm repo index . --url "$REPO_URL" --merge index.yaml |
| 68 | + else |
| 69 | + helm repo index . --url "$REPO_URL" |
| 70 | + fi |
| 71 | + # Commit and push changes |
| 72 | + git add . |
| 73 | + git commit -m "helm-charts: publish updated charts" |
| 74 | + git push origin $GITHUB_PAGES_BRANCH |
| 75 | +else |
| 76 | + echo "No new chart versions to publish" |
| 77 | +fi |
0 commit comments