|
| 1 | +name: release-helm-charts |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'charts/**' |
| 9 | + tags: |
| 10 | + - '*' |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: chart-release |
| 18 | + cancel-in-progress: false |
| 19 | + |
| 20 | +jobs: |
| 21 | + release: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Configure Git |
| 30 | + run: | |
| 31 | + git config user.name "github-actions[bot]" |
| 32 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 33 | +
|
| 34 | + - name: Extract tag |
| 35 | + id: vars |
| 36 | + if: startsWith(github.ref, 'refs/tags/') |
| 37 | + run: | |
| 38 | + TAG="${GITHUB_REF#refs/tags/}" |
| 39 | + TAG="${TAG////-}" |
| 40 | + echo "Using tag: $TAG" |
| 41 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 42 | +
|
| 43 | + - name: Set chart versions to tag |
| 44 | + if: startsWith(github.ref, 'refs/tags/') && !startsWith(github.ref, 'refs/tags/zk') |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | + for chart in charts/*; do |
| 48 | + f="$chart/Chart.yaml" |
| 49 | + if [ -f "$f" ]; then |
| 50 | + echo "Updating version in $f to ${TAG:-${{ steps.vars.outputs.tag }}}" |
| 51 | + # Replace the version field at start of line (optional leading spaces) |
| 52 | + sed -i.bak -E "s|^[[:space:]]*version:[[:space:]]*.*$|version: ${{ steps.vars.outputs.tag }}|" "$f" |
| 53 | + rm -f "$f.bak" |
| 54 | + fi |
| 55 | + done |
| 56 | +
|
| 57 | + - name: Sync zookeeper chart image.tag with Docker tag |
| 58 | + if: startsWith(github.ref, 'refs/tags/') |
| 59 | + run: | |
| 60 | + set -euo pipefail |
| 61 | + ZK_VERSION=$(sed -n "s/^ARG DISTRO_NAME=apache-zookeeper-\([0-9.]*\)-bin$/\1/p" docker/zookeeper-image/Dockerfile | head -n1) |
| 62 | + if [ -z "$ZK_VERSION" ]; then |
| 63 | + # Fallback to current value in chart values |
| 64 | + ZK_VERSION=$(sed -n "s/^[[:space:]]*tag:[[:space:]]*\([0-9.]*\).*/\1/p" charts/zookeeper/values.yaml | head -n1) |
| 65 | + fi |
| 66 | + TAG="${{ steps.vars.outputs.tag }}" |
| 67 | + if [[ "$GITHUB_REF" == refs/tags/zk* ]]; then |
| 68 | + NEW_IMG_TAG="${ZK_VERSION}-apache-${TAG}" |
| 69 | + else |
| 70 | + NEW_IMG_TAG="${ZK_VERSION}-${TAG}" |
| 71 | + fi |
| 72 | + echo "Setting charts/zookeeper/values.yaml image.tag to ${NEW_IMG_TAG}" |
| 73 | + sed -i.bak -E "s|^([[:space:]]*tag:[[:space:]]*).*$|\1${NEW_IMG_TAG}|" charts/zookeeper/values.yaml |
| 74 | + rm -f charts/zookeeper/values.yaml.bak |
| 75 | +
|
| 76 | + - name: Set up Helm |
| 77 | + uses: azure/setup-helm@v4 |
| 78 | + with: |
| 79 | + version: v3.14.4 |
| 80 | + |
| 81 | + - name: Lint Helm charts |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | + found=0 |
| 85 | + for chart in charts/*; do |
| 86 | + if [ -f "$chart/Chart.yaml" ]; then |
| 87 | + found=1 |
| 88 | + echo "Linting $chart" |
| 89 | + helm lint "$chart" |
| 90 | + fi |
| 91 | + done |
| 92 | + if [ "$found" -eq 0 ]; then |
| 93 | + echo "No charts found under charts/." >&2 |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | +
|
| 97 | + - name: Build chart dependencies (if any) |
| 98 | + run: | |
| 99 | + set -euo pipefail |
| 100 | + for chart in charts/*; do |
| 101 | + if [ -f "$chart/Chart.yaml" ] && [ -f "$chart/Chart.yaml" ]; then |
| 102 | + if [ -f "$chart/Chart.yaml" ] && grep -q "^dependencies:" "$chart/Chart.yaml"; then |
| 103 | + echo "Updating dependencies for $chart" |
| 104 | + helm dependency update "$chart" |
| 105 | + fi |
| 106 | + fi |
| 107 | + done |
| 108 | +
|
| 109 | + - name: Ensure gh-pages branch exists |
| 110 | + run: | |
| 111 | + set -euo pipefail |
| 112 | + if ! git ls-remote --exit-code origin gh-pages >/dev/null 2>&1; then |
| 113 | + echo "Initializing gh-pages branch for chart-releaser" |
| 114 | + tmpdir=$(mktemp -d) |
| 115 | + git worktree add "$tmpdir" HEAD |
| 116 | + pushd "$tmpdir" |
| 117 | + git checkout --orphan gh-pages |
| 118 | + rm -rf ./* |
| 119 | + touch .nojekyll |
| 120 | + echo "" > index.yaml |
| 121 | + git add .nojekyll index.yaml |
| 122 | + git commit -m "Initialize gh-pages" |
| 123 | + git push origin gh-pages |
| 124 | + popd |
| 125 | + git worktree remove "$tmpdir" --force |
| 126 | + fi |
| 127 | +
|
| 128 | + - name: Release charts to GitHub Pages |
| 129 | + if: ${{ !startsWith(github.ref, 'refs/tags/zk') }} |
| 130 | + |
| 131 | + env: |
| 132 | + CR_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 133 | + with: |
| 134 | + charts_dir: charts |
| 135 | + packages_with_index: true |
| 136 | + pages_branch: gh-pages |
| 137 | + skip_existing: true |
0 commit comments