Add ci for helmchart #1
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: Build and Publish Helm Chart | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*' | |
| paths: | |
| - 'helm/**' | |
| - '.github/workflows/helm-chart.yml' | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| CHART_NAME: dataflow-operator | |
| CHART_PATH: helm/dataflow-operator | |
| jobs: | |
| lint-and-test: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Helm | |
| uses: azure/setup-helm@v4 | |
| with: | |
| version: 'latest' | |
| - name: Lint Helm chart | |
| run: | | |
| helm lint ${{ env.CHART_PATH }} | |
| - name: Test Helm chart template rendering | |
| run: | | |
| helm template ${{ env.CHART_NAME }} ${{ env.CHART_PATH }} --debug | |
| build-and-push: | |
| needs: lint-and-test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Helm | |
| uses: azure/setup-helm@v4 | |
| with: | |
| version: 'latest' | |
| - name: Configure Helm OCI registry | |
| run: | | |
| helm registry login ${{ env.REGISTRY }} \ | |
| -u ${{ github.actor }} \ | |
| -p ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract chart version | |
| id: chart_version | |
| run: | | |
| VERSION=$(grep '^version:' ${{ env.CHART_PATH }}/Chart.yaml | cut -d' ' -f2) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Chart version: $VERSION" | |
| - name: Package Helm chart | |
| run: | | |
| helm package ${{ env.CHART_PATH }} --destination ./charts | |
| - name: Determine chart tag | |
| id: chart_tag | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
| TAG="${GITHUB_REF#refs/tags/}" | |
| else | |
| TAG="${{ steps.chart_version.outputs.version }}-${GITHUB_SHA:0:7}" | |
| fi | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "Chart tag: $TAG" | |
| - name: Push Helm chart to OCI registry | |
| run: | | |
| CHART_FILE=$(ls ./charts/${{ env.CHART_NAME }}-*.tgz | head -n 1) | |
| helm push $CHART_FILE oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/helm-charts | |
| echo "Published: oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/helm-charts/${{ env.CHART_NAME }}:${{ steps.chart_tag.outputs.tag }}" | |
| - name: Upload chart artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: helm-chart | |
| path: charts/*.tgz | |
| retention-days: 30 | |
| release: | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download chart artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: helm-chart | |
| path: charts | |
| - name: Get tag name | |
| id: tag | |
| run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Extract chart version | |
| id: chart_version | |
| run: | | |
| VERSION=$(grep '^version:' ${{ env.CHART_PATH }}/Chart.yaml | cut -d' ' -f2) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.tag.outputs.TAG_NAME }} | |
| name: Release ${{ steps.tag.outputs.TAG_NAME }} | |
| files: charts/*.tgz | |
| body: | | |
| ## Helm Chart | |
| Helm chart version **${{ steps.chart_version.outputs.version }}** is available for installation: | |
| ### Installation from OCI registry | |
| ```bash | |
| helm install dataflow-operator \ | |
| oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/helm-charts/${{ env.CHART_NAME }} \ | |
| --version ${{ steps.chart_version.outputs.version }} | |
| ``` | |
| ### Installation from GitHub Release | |
| ```bash | |
| helm install dataflow-operator \ | |
| https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.TAG_NAME }}/${{ env.CHART_NAME }}-${{ steps.chart_version.outputs.version }}.tgz | |
| ``` | |
| ### Adding repository (if using Helm chart repository) | |
| ```bash | |
| helm repo add dataflow-operator oci://${{ env.REGISTRY }}/${{ github.repository_owner }}/helm-charts | |
| helm repo update | |
| helm install dataflow-operator dataflow-operator/${{ env.CHART_NAME }} --version ${{ steps.chart_version.outputs.version }} | |
| ``` | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |