|
| 1 | +name: Package Helm Chart and publish to GitHub Packages |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: {} |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - .github/workflows/helm-release.yaml |
| 10 | + - charts/** |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + packages: write |
| 15 | + |
| 16 | +env: |
| 17 | + REGISTRY: ghcr.io |
| 18 | + ACTIONS_RUNNER_DEBUG: false |
| 19 | + |
| 20 | +jobs: |
| 21 | + helm-release: |
| 22 | + runs-on: [ default ] |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + include: |
| 27 | + - chartDir: charts/controlplane-operations |
| 28 | + chartName: controlplane-operations |
| 29 | + |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Configure Git |
| 37 | + run: | |
| 38 | + git config user.name "$GITHUB_ACTOR" |
| 39 | + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" |
| 40 | +
|
| 41 | + - name: Set up Helm |
| 42 | + uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0 |
| 43 | + |
| 44 | + - uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5 |
| 45 | + with: |
| 46 | + python-version: 3.9 |
| 47 | + check-latest: true |
| 48 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + |
| 50 | + - name: Log into registry ${{ env.REGISTRY }} |
| 51 | + if: github.event_name != 'pull_request' |
| 52 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3 |
| 53 | + with: |
| 54 | + registry: ${{ env.REGISTRY }} |
| 55 | + username: ${{ github.actor }} |
| 56 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Get changed files |
| 59 | + id: changed-files |
| 60 | + uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46 |
| 61 | + with: |
| 62 | + files: | |
| 63 | + ${{ matrix.chartDir }}/** |
| 64 | +
|
| 65 | + - name: Check if Helm chart with same version already exists |
| 66 | + id: check-chart |
| 67 | + if: steps.changed-files.outputs.all_changed_files != '' |
| 68 | + env: |
| 69 | + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
| 70 | + run: | |
| 71 | + # List all changed |
| 72 | + echo "All changed files: $ALL_CHANGED_FILES" |
| 73 | + chartName=$(yq .name "${{ matrix.chartDir }}/Chart.yaml") |
| 74 | + chartVersion=$(yq .version "${{ matrix.chartDir }}/Chart.yaml") |
| 75 | + echo "chart_version=${chartVersion}" >> "$GITHUB_OUTPUT" |
| 76 | + if $(helm pull "oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/${{ matrix.chartName }}" --version $chartVersion); then |
| 77 | + echo "bump=true" >> "$GITHUB_OUTPUT" |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: Chart needs version bump |
| 81 | + if: steps.check-chart.outputs.bump == 'true' |
| 82 | + env: |
| 83 | + CHART_VERSION: ${{ steps.check-chart.outputs.chart_version }} |
| 84 | + run: | |
| 85 | + echo "Chart ${{ matrix.chartDir }}:${{ env.CHART_VERSION }} already exists in OCI registry. Skipping upload. Please increment the chart version." |
| 86 | + exit 1 |
| 87 | +
|
| 88 | + - name: Push Charts to GHCR |
| 89 | + if: steps.changed-files.outputs.all_changed_files != '' && steps.check-chart.outputs.bump != 'true' |
| 90 | + run: | |
| 91 | + helm package ${{ matrix.chartDir }} -d ${{ matrix.chartDir }} |
| 92 | + PKG_NAME=`ls ${{ matrix.chartDir }}/*.tgz` |
| 93 | + helm push ${PKG_NAME} oci://${{ env.REGISTRY }}/${{ github.repository }}/charts/ |
| 94 | +
|
| 95 | + - name: Run chart-releaser |
| 96 | + uses: helm/chart-releaser-action@cae68fefc6b5f367a0275617c9f83181ba54714f # v1.7.0 |
| 97 | + env: |
| 98 | + CR_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 99 | + CR_GENERATE_RELEASE_NOTES: true |
0 commit comments