Release Helm Chart #32
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: Release Helm Chart | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_change: | |
| description: 'Type of version change (major, minor, patch)' | |
| required: true | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - major | |
| - minor | |
| - patch | |
| env: | |
| REGISTRY: registry-1.docker.io | |
| CHART_NAME: dakr-operator | |
| ORG: devzeroinc | |
| CHART_TAG_PREFIX: chart-v | |
| jobs: | |
| release-helm-chart: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Helm | |
| uses: azure/setup-helm@v4 | |
| with: | |
| version: '3.12.3' | |
| - name: Install yq | |
| run: | | |
| sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 | |
| sudo chmod +x /usr/local/bin/yq | |
| - name: Helm registry login | |
| run: | | |
| echo "${{ secrets.DOCKERHUB_TOKEN }}" | \ | |
| helm registry login registry-1.docker.io \ | |
| --username "${{ secrets.DOCKERHUB_USERNAME }}" \ | |
| --password-stdin | |
| - name: Enable Helm OCI support | |
| run: echo "HELM_EXPERIMENTAL_OCI=1" >> $GITHUB_ENV | |
| - name: Fetch tags | |
| run: git fetch --tags | |
| - name: Get last chart version from tags | |
| id: get_version | |
| run: | | |
| LAST_TAG=$(git tag --list '${{ env.CHART_TAG_PREFIX }}*' --sort=-v:refname | head -n 1) | |
| if [ -z "$LAST_TAG" ]; then | |
| LAST_VERSION="0.0.0" | |
| else | |
| LAST_VERSION="${LAST_TAG#${{ env.CHART_TAG_PREFIX }}}" | |
| fi | |
| echo "Last version: $LAST_VERSION" | |
| echo "last_version=$LAST_VERSION" >> $GITHUB_OUTPUT | |
| - name: Bump version takes the most recent tag and bumps the version in it | |
| id: bump_version | |
| run: | | |
| LAST_VERSION="${{ steps.get_version.outputs.last_version }}" | |
| # Set default to 'patch' if not provided | |
| CHANGE_TYPE="${{ github.event.inputs.version_change || 'patch' }}" | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$LAST_VERSION" | |
| if [[ "$CHANGE_TYPE" == "major" ]]; then | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| elif [[ "$CHANGE_TYPE" == "minor" ]]; then | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| elif [[ "$CHANGE_TYPE" == "patch" ]]; then | |
| PATCH=$((PATCH + 1)) | |
| else | |
| echo "Invalid version change type: $CHANGE_TYPE" | |
| exit 1 | |
| fi | |
| NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | |
| echo "Bumped version: $NEW_VERSION" | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Create and push the newly created tag | |
| run: | | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "GitHub Actions" | |
| git tag "${{ env.CHART_TAG_PREFIX }}${{ steps.bump_version.outputs.new_version }}" | |
| git push origin "${{ env.CHART_TAG_PREFIX }}${{ steps.bump_version.outputs.new_version }}" | |
| - name: Renaming operator (from dakr in helm/dakr/Chart.yaml, to dakr-operator) to match upstream repo name | |
| run: | | |
| # on mac: sed -i '' 's/^name: dakr$/name: dakr-operator/' helm/dakr/Chart.yaml | |
| sed -i 's/^name: dakr$/name: dakr-operator/' helm/dakr/Chart.yaml | |
| - name: Update chart dependencies | |
| run: | | |
| helm dependency update helm/dakr | |
| - name: Lint Helm chart | |
| run: | | |
| helm lint helm/dakr | |
| - name: Package Helm chart | |
| run: | | |
| mkdir -p helm/packages | |
| helm package helm/dakr \ | |
| --version ${{ steps.bump_version.outputs.new_version }} \ | |
| --app-version ${{ steps.bump_version.outputs.new_version }} \ | |
| --destination helm/packages | |
| - name: Push Helm chart to Docker Hub OCI registry | |
| run: | | |
| helm push helm/packages/dakr-operator-${{ steps.bump_version.outputs.new_version }}.tgz \ | |
| oci://${{ env.REGISTRY }}/${{ env.ORG }} | |
| - name: Update Chart.yaml version and appVersion | |
| run: | | |
| yq e -i '.version = "${{ steps.bump_version.outputs.new_version }}"' helm/dakr/Chart.yaml | |
| yq e -i '.appVersion = "${{ steps.bump_version.outputs.new_version }}"' helm/dakr/Chart.yaml | |
| - name: Create PR to update Chart.yaml version and appVersion | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| commit-message: "chore(helm): update Chart.yaml version to ${{ steps.bump_version.outputs.new_version }}" | |
| title: "chore(helm): update Chart.yaml version to ${{ steps.bump_version.outputs.new_version }}" | |
| body: | | |
| This PR updates the `version` and `appVersion` fields in `helm/dakr/Chart.yaml` to `${{ steps.bump_version.outputs.new_version }}`. | |
| branch: "update/chart-version-${{ steps.bump_version.outputs.new_version }}" | |
| add-paths: | | |
| helm/dakr/Chart.yaml |