|
| 1 | +name: Helm Chart Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + packages: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + publish: |
| 14 | + if: startsWith(github.event.release.tag_name, 'v') |
| 15 | + runs-on: ubuntu-latest |
| 16 | + concurrency: |
| 17 | + group: helm-release-${{ github.event.release.tag_name }} |
| 18 | + cancel-in-progress: true |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v6 |
| 22 | + |
| 23 | + - name: Set up Helm |
| 24 | + uses: azure/setup-helm@v4 |
| 25 | + with: |
| 26 | + version: v3.13.3 |
| 27 | + |
| 28 | + - name: Sync chart version with release tag |
| 29 | + run: | |
| 30 | + RAW_TAG="${GITHUB_REF_NAME}" |
| 31 | + TAG="${RAW_TAG#v}" |
| 32 | + echo "Setting chart version to ${TAG} and appVersion to ${RAW_TAG}" |
| 33 | + sed -i -E "s/^version: .*/version: ${TAG} # replaced by CI/" Chart.yaml |
| 34 | + sed -i -E "s/^appVersion: .*/appVersion: \"${RAW_TAG}\" # replaced by CI/" Chart.yaml |
| 35 | +
|
| 36 | + - name: Validate chart version |
| 37 | + run: | |
| 38 | + RAW_TAG="${GITHUB_REF_NAME}" |
| 39 | + TAG="${RAW_TAG#v}" |
| 40 | + grep -Eq "^version: ${TAG}([[:space:]]+#.*)?$" Chart.yaml || { echo "Chart version mismatch"; cat Chart.yaml; exit 1; } |
| 41 | + grep -Eq "^appVersion: \"?${RAW_TAG}\"?([[:space:]]+#.*)?$" Chart.yaml || { echo "appVersion mismatch"; cat Chart.yaml; exit 1; } |
| 42 | + - name: Package chart |
| 43 | + run: | |
| 44 | + mkdir -p dist |
| 45 | + helm dependency update charts/k8s-copycat |
| 46 | + helm package charts/k8s-copycat --destination dist |
| 47 | +
|
| 48 | + - name: Login to GHCR |
| 49 | + run: | |
| 50 | + echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin |
| 51 | +
|
| 52 | + - name: Push chart to GHCR |
| 53 | + run: | |
| 54 | + for chart in dist/*.tgz; do |
| 55 | + helm push "$chart" oci://ghcr.io/${{ github.repository_owner }}/charts |
| 56 | + done |
| 57 | +
|
| 58 | + - name: Upload packaged chart to release assets |
| 59 | + uses: softprops/action-gh-release@v2 |
| 60 | + with: |
| 61 | + files: dist/*.tgz |
| 62 | + env: |
| 63 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments