Publish Helm Chart main by @liyaka #4
This file contains 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: Publish Helm Chart | |
run-name: "Publish Helm Chart ${{ github.ref_name }} by @${{ github.actor }}" | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- 'main' | |
paths: | |
- "charts/**" | |
env: | |
BASE_VERSION: "1.0" | |
jobs: | |
set-version: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
steps: | |
- name: Set version | |
id: version | |
run: | | |
BRANCH_NAME="${{ github.ref_name }}" | |
if [[ "${BRANCH_NAME}" == "main" ]] | |
then | |
echo 'version=${{env.BASE_VERSION}}.${{ github.run_number }}' | tee -a $GITHUB_OUTPUT | |
else | |
# Normalize branch name | |
fixedBranchName=$(echo "${BRANCH_NAME}" | sed 's/origin\///; s/\//-/g; s/_/-/g; s/.*/\L&/') | |
if [ ${#fixedBranchName} -gt 21 ]; then | |
fixedBranchName="${fixedBranchName:0:20}" | |
# remove dash at the end | |
while [ "${fixedBranchName: -1}" = "-" ]; do | |
fixedBranchName="${fixedBranchName%?}" | |
done | |
fi | |
VERSION="${{env.BASE_VERSION}}-${fixedBranchName}.${{ github.run_number }}" | |
echo "version=${VERSION}" | tee -a $GITHUB_OUTPUT | |
fi | |
publish-helm-chart: | |
needs: | |
- set-version | |
runs-on: ubuntu-latest | |
env: | |
VERSION_NAME: ${{ needs.set-version.outputs.version }} | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Run lint on Helm chart | |
run: | | |
set -e | |
cd charts/public-test | |
helm repo add bitnami https://charts.bitnami.com/bitnami | |
helm dependency build | |
helm lint --values values.yaml . | |
cd - | |
- name: Package helm chart | |
run: | | |
cd charts | |
helm package --version ${{env.VERSION_NAME}} public-test/ | |
cd - | |
- name: Update Helm Charts repo index | |
run: | | |
cd charts | |
helm repo index --url https://comet-ml.github.io/public-test/ --merge index.yaml . | |
cat index.yaml | |
cd - | |
- name: Push the changes | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "github-actions" | |
git add charts/* | |
git commit -m "Publish helm chart ${{env.VERSION_NAME}}" | |
git push origin main | |
- name: Summary | |
run: | | |
echo "Helm chart is published, version is : ${{env.VERSION_NAME}}" >> $GITHUB_STEP_SUMMARY | |