KusionStack / karpor

Intelligence for Kubernetes. World's most promising Kubernetes Visualization Tool for Developer and Platform Engineering teams.
https://karpor-demo.kusionstack.io
Apache License 2.0
440 stars 44 forks source link

Governance: Automatically update the appVersion in Chart when released #547

Open elliotxx opened 1 month ago

elliotxx commented 1 month ago

What would you like to be added?

Automatically update the appVersion in Chart when released.

Why is this needed?

The current release process is:

  1. Push tag, such as v0.4.5
  2. Auto trigger a karpor release pipeline. It will build an image and publish changelog, artifacts to the github release.
  3. Modify Karpor Chart's appVersion to the new version, such as v0.4.5.
  4. Auto trigger a chart release pipeline.
  5. End.

We hope the 3 and 4 steps can be merged into the 2 step and automated together.

rajeshkio commented 1 month ago

I can take this if there is no urgency to complete this. I can work on it next week.

elliotxx commented 1 month ago

@rajeshkio Yeah, this issue is not very urgent, you can start when you are convenient.

rajeshkio commented 1 month ago

I am confused. I do not see anything related to the helm chart in the current workflow; the helm chart has a different repo. So does the task include updating the Chart.yml in the helm chart repo?

elliotxx commented 1 month ago

@rajeshkio Ohh, I didn't make it clear. Chart repo is here.

The current workflow is as described in the issue, after each release, I manually update the version and appVersion in the chart repo, similar to this PR.

My idea is that after each release, this PR can be automatically generated through a github action (yaml-update-action is good), and maintainers only need to click merge.

Example ( in release.yaml ):

      - name: Get version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
      - name: Bump version in the related HelmChart Chart.yaml
        uses: fjogeleit/yaml-update-action@main
        with:
          repository: KusionStack/charts
          valueFile: 'charts/karpor/Chart.yaml'
          propertyPath: '{"version":"${{ steps.get_version.outputs.VERSION }}", "appVersion":"${{ steps.get_version.outputs.VERSION }}"}'
          value: ${{ steps.get_version.outputs.VERSION }}
          branch: bump-karpor-to-${{ steps.get_version.outputs.VERSION }}
          targetBranch: main
          createPR: true
          message: 'refactor: bump karpor version to ${{ steps.get_version.outputs.VERSION }}'
          token: ${{ secrets.GITHUB_TOKEN }}
          workDir: .
rajeshkio commented 1 month ago

Interesting. This would mean directly updating the version in the helm chart whenever there is a new image without considering if there are any changes in the helm chart repo. Also updating the appVersion in helm chart means we need to update the helm chart version as well, no?

elliotxx commented 1 month ago

@rajeshkio Yeah, as long as release has a new image, we can automatically generate a PR that only includes version bump. And just like you said, version (chart version) and appVersion(image version) need to be updated. We really need to consider how to update the version, its target value is not easy to get. Let me see. 🤔

elliotxx commented 1 month ago

@rajeshkio I think of a way, it can obtain and automatically bump chart version:

      - name: Get karpor version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
      - name: Get new chart version
        id: get-chart-version
        run: |
          helm repo add kusionstack https://kusionstack.github.io/charts
          helm repo update
          version=$(helm search repo kusionstack/karpor --versions | head -n 2 | tail -n 1 | awk '{print $2}')
          echo "Current chart version is: $version"

          major=$(echo "$version" | cut -d. -f1)
          minor=$(echo "$version" | cut -d. -f2)
          patch=$(echo "$version" | cut -d. -f3)
          new_chart_version="${major}.${minor}.$((patch + 1))"

          echo "New chart version is: $new_chart_version"
          echo "::set-output name=new_chart_version::$new_chart_version"
      - name: Bump version in the related HelmChart Chart.yaml
        uses: fjogeleit/yaml-update-action@main
        with:
          repository: KusionStack/charts
          valueFile: 'charts/karpor/Chart.yaml'
          propertyPath: '{"version":"${{ steps.get-chart-version.outputs.new_chart_version }}", "appVersion":"${{ steps.get_version.outputs.VERSION }}"}'
          value: ${{ steps.get_version.outputs.VERSION }}
          branch: bump-karpor-to-${{ steps.get_version.outputs.VERSION }}
          targetBranch: main
          createPR: true
          message: 'refactor: bump karpor version to ${{ steps.get_version.outputs.VERSION }}'
          token: ${{ secrets.GITHUB_TOKEN }}
          workDir: .
rajeshkio commented 1 month ago

Bro, you have already done all the hard work. Now I just need to copy and update the release YAML

elliotxx commented 1 month ago

@rajeshkio Yeah, but I did not do any tests in the above yaml... and its verification and debug is also important!

rajeshkio commented 1 month ago

Sure. I will try to complete it by the end of the week.