feat: add GitHub Actions workflow for packaging and pushing Helm charts
This commit is contained in:
75
.github/workflows/helm-package-push.yml
vendored
Normal file
75
.github/workflows/helm-package-push.yml
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
name: Package and Push Helm Chart
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- beta
|
||||
- dev
|
||||
paths:
|
||||
- 'helm/**'
|
||||
tags:
|
||||
- 'v*'
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
- created
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: ${{ vars.DOCKER_REGISTRY }}
|
||||
|
||||
jobs:
|
||||
package-and-push:
|
||||
runs-on: self-hosted
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v4
|
||||
with:
|
||||
version: 'latest'
|
||||
|
||||
- name: Log in to Container Registry
|
||||
run: |
|
||||
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin
|
||||
|
||||
- name: Extract version from Chart.yaml
|
||||
id: version
|
||||
run: |
|
||||
VERSION=$(grep '^version:' ./helm/Chart.yaml | awk '{print $2}' | tr -d '"')
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Package Helm chart
|
||||
run: |
|
||||
helm package ./helm
|
||||
|
||||
- name: Push Helm chart to registry
|
||||
run: |
|
||||
CHART_VERSION=$(grep '^version:' ./helm/Chart.yaml | awk '{print $2}')
|
||||
CHART_FILE=$(grep '^name:' ./helm/Chart.yaml | awk '{print $2}')
|
||||
CHART_PATH="${CHART_FILE}-${CHART_VERSION}.tgz"
|
||||
|
||||
# Determine tag based on branch
|
||||
if [[ "${{ github.ref_name }}" == "main" ]]; then
|
||||
TAG="${{ steps.version.outputs.version }}"
|
||||
helm push "$CHART_PATH" oci://${{ env.REGISTRY }}/$CHART_FILE:$TAG
|
||||
helm push "$CHART_PATH" oci://${{ env.REGISTRY }}/$CHART_FILE:latest
|
||||
else
|
||||
TAG="${{ steps.version.outputs.version }}-${{ github.ref_name }}"
|
||||
helm push "$CHART_PATH" oci://${{ env.REGISTRY }}/$CHART_FILE:$TAG
|
||||
fi
|
||||
|
||||
- name: Chart pushed
|
||||
run: |
|
||||
CHART_FILE=$(grep '^name:' ./helm/Chart.yaml | awk '{print $2}')
|
||||
if [[ "${{ github.ref_name }}" == "main" ]]; then
|
||||
echo "Chart pushed: $CHART_FILE:${{ steps.version.outputs.version }} and $CHART_FILE:latest"
|
||||
else
|
||||
echo "Chart pushed: $CHART_FILE:${{ steps.version.outputs.version }}-${{ github.ref_name }}"
|
||||
fi
|
||||
Reference in New Issue
Block a user