Update Chart.yaml #78
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: Package Helm Chart and publish to GitHub Packages | |
| concurrency: | |
| group: helm-push-${{ github.repository }} | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'charts/**/Chart.yaml' | |
| permissions: | |
| contents: write | |
| packages: write | |
| env: | |
| REGISTRY: ghcr.io | |
| ACTIONS_RUNNER_DEBUG: false | |
| jobs: | |
| helm-push: | |
| runs-on: [ ubuntu-latest ] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Helm | |
| uses: azure/setup-helm@v4.2.0 | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Get all changed Chart.yaml files | |
| id: changed-chart-yaml-files | |
| uses: tj-actions/changed-files@v44 | |
| with: | |
| files: | | |
| **/Chart.yaml | |
| - name: Check if Helm chart with same version already exists | |
| id: check-chart | |
| if: steps.changed-chart-yaml-files.outputs.any_changed == 'true' | |
| shell: bash | |
| env: | |
| ALL_CHANGED_FILES: ${{ steps.changed-chart-yaml-files.outputs.all_changed_files }} | |
| run: | | |
| for file in ${ALL_CHANGED_FILES}; do | |
| echo "Checking ${file}" | |
| chart_name=$(yq .name "$file") | |
| chart_version=$(yq .version "$file") | |
| if helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/${chart_name}" --version $chart_version; then | |
| echo "chart_name=${chart_name}" >> "$GITHUB_OUTPUT" | |
| echo "chart_version=${chart_version}" >> "$GITHUB_OUTPUT" | |
| echo "needsbump=true" >> "$GITHUB_OUTPUT" | |
| exit 1 | |
| fi | |
| done | |
| - name: Chart needs version bump | |
| if: steps.check-chart.outputs.bump == 'true' | |
| env: | |
| CHART_NAME: ${{ steps.check-chart.outputs.chart_name }} | |
| CHART_VERSION: ${{ steps.check-chart.outputs.chart_version }} | |
| run: | | |
| echo "Chart ${{ env.CHART_NAME }}:${{ env.CHART_VERSION }} already exists in OCI registry. Skipping upload. Please increment the chart version." | |
| exit 1 | |
| - name: Push chart to registry | |
| if: steps.changed-chart-yaml-files.outputs.all_changed_files != '' | |
| shell: bash | |
| env: | |
| ALL_CHANGED_FILES: ${{ steps.changed-chart-yaml-files.outputs.all_changed_files }} | |
| run: | | |
| for CHART_FILE in ${ALL_CHANGED_FILES}; do | |
| CHART_DIR=$(dirname $CHART_FILE) | |
| helm package $CHART_DIR --dependency-update --destination $CHART_DIR | |
| CHART_PACKAGE=$(ls $CHART_DIR/*.tgz) | |
| helm push $CHART_PACKAGE oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/ | |
| done |