Skip to content

Publish Helm chart

Publish Helm chart #6

Workflow file for this run

name: Publish Helm chart
on:
workflow_run:
workflows: ["Set Version"]
types: [completed]
jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # checkout the correct branch name
fetch-tags: true
# Run the script only if there are changes in the folders ./charts/ or ./deploy/
- name: Check for changes in specific folders
id: check_changes
run: |
if git diff --name-only HEAD^ HEAD | grep -qE '^charts/|^deploy/'; then
echo "Changes detected in charts or deploy folder"
else
exit 0
fi
- name: detect version
id: set-env
run: echo "version=`echo $(git describe --tags --abbrev=0 --exact-match || echo 'v0.0.0')`" >> $GITHUB_OUTPUT
# Set appVersion in all Chart.yaml files under folder ./charts/
- name: version Helm Chart
shell: bash
run: |
export CHAT_VERSION=${{ steps.set-env.outputs.version }}
if [[ $CHAT_VERSION == v* ]]; then
export CHAT_VERSION=${CHAT_VERSION:1}
fi
find ./charts -name Chart.yaml -maxdepth 2 -exec sed -i "s/version: .*/version: ${CHAT_VERSION}/g" {} \;
find ./charts -name Chart.yaml -maxdepth 2 -exec sed -i "s/appVersion: .*/appVersion: ${{ steps.set-env.outputs.version }}/g" {} \;
- name: set up Helm
uses: azure/setup-helm@v4
with:
version: "latest"
# Be ware that special chars here (e.g. $) must be escaped by backslash in GitHub Secrets!
- name: Helm Registry Login
run: echo "${{ secrets.HELM_PASSWORD }}" | helm registry login ${{ secrets.HELM_REGISTRY }}/${{ github.repository_owner }} --username ${{ secrets.HELM_USERNAME }} --password-stdin
- name: package and publish Helm chart
shell: bash
run: |
for dir in $(find ./charts -name Chart.yaml -maxdepth 2 -exec dirname {} \;); do
(cd $dir && helm package . && helm push *.tgz oci://${{ secrets.HELM_REGISTRY }}/${{ github.repository }}/charts)
done