|
| 1 | +name: Build and Push Helm Chart |
| 2 | +description: Lint, build, and optionally push Helm chart to Google Artifact Registry |
| 3 | +inputs: |
| 4 | + chart-path: |
| 5 | + description: Path to the Helm chart directory |
| 6 | + required: true |
| 7 | + push: |
| 8 | + description: Whether to push the chart to registry |
| 9 | + required: false |
| 10 | + default: 'false' |
| 11 | + registry-login-url: |
| 12 | + description: Google Registry login URL (e.g., oci://europe-docker.pkg.dev/project/helm-charts) |
| 13 | + required: false |
| 14 | + default: "europe-docker.pkg.dev" |
| 15 | + registry-url: |
| 16 | + description: Google Artifact Registry URL (e.g., oci://europe-docker.pkg.dev/project/helm-charts) |
| 17 | + required: false |
| 18 | + credentials: |
| 19 | + description: Base64 encoded Google service account JSON credentials |
| 20 | + required: false |
| 21 | + version: |
| 22 | + description: Chart version (defaults to 0.0.0-{sha}) |
| 23 | + required: false |
| 24 | + app-version: |
| 25 | + description: App version (defaults to git sha) |
| 26 | + required: false |
| 27 | + |
| 28 | +outputs: |
| 29 | + chart-name: |
| 30 | + description: Name of the packaged chart file |
| 31 | + value: ${{ steps.package.outputs.chart-name }} |
| 32 | + chart-version: |
| 33 | + description: Version of the packaged chart |
| 34 | + value: ${{ steps.set-version.outputs.version }} |
| 35 | + |
| 36 | +runs: |
| 37 | + using: composite |
| 38 | + steps: |
| 39 | + - name: Set up Helm |
| 40 | + uses: azure/setup-helm@v4 |
| 41 | + with: |
| 42 | + version: v4.0.1 |
| 43 | + |
| 44 | + - name: Set version |
| 45 | + id: set-version |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + if [ -n "${{ inputs.version }}" ]; then |
| 49 | + VERSION="${{ inputs.version }}" |
| 50 | + else |
| 51 | + VERSION="0.0.0-${GITHUB_SHA::8}" |
| 52 | + fi |
| 53 | + # Set default image.tag version in values.yaml |
| 54 | + cd ${{ inputs.chart-path }} |
| 55 | + yq -i ".global.image.tag = \"$VERSION\"" values.yaml |
| 56 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 57 | + |
| 58 | + - name: Update Helm dependencies |
| 59 | + shell: bash |
| 60 | + run: helm dependency update ${{ inputs.chart-path }} |
| 61 | + |
| 62 | + - name: Lint Helm chart |
| 63 | + shell: bash |
| 64 | + run: helm lint ${{ inputs.chart-path }} |
| 65 | + |
| 66 | + - name: Package Helm chart |
| 67 | + id: package |
| 68 | + shell: bash |
| 69 | + run: | |
| 70 | + helm package ${{ inputs.chart-path }} \ |
| 71 | + --version ${{ steps.set-version.outputs.version }} \ |
| 72 | + --app-version ${{ steps.set-version.outputs.version }} |
| 73 | + |
| 74 | + CHART_NAME=$(ls -1 *.tgz | head -n1) |
| 75 | + echo "chart-name=$CHART_NAME" >> $GITHUB_OUTPUT |
| 76 | +
|
| 77 | + - name: Authenticate to Google Artifact Registry |
| 78 | + if: inputs.push == 'true' |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + echo "${{ inputs.credentials }}" | \ |
| 82 | + helm registry login -u _json_key_base64 \ |
| 83 | + --password-stdin ${{ inputs.registry-login-url }} |
| 84 | +
|
| 85 | + - name: Push Helm chart |
| 86 | + if: inputs.push == 'true' |
| 87 | + shell: bash |
| 88 | + run: | |
| 89 | + helm push ${{ steps.package.outputs.chart-name }} ${{ inputs.registry-url }} |
| 90 | +
|
| 91 | + - name: Cleanup credentials |
| 92 | + if: always() && inputs.push == 'true' |
| 93 | + shell: bash |
| 94 | + run: | |
| 95 | + rm -f /tmp/gcloud-key.json |
0 commit comments