From 6a8aaaa159c321e4f59bd5f6c5845233670f848c Mon Sep 17 00:00:00 2001 From: Ahmed AbouZaid <6760103+aabouzaid@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:46:05 +0200 Subject: [PATCH] chore: update generate-release-notes.sh to work with multi version Signed-off-by: Ahmed AbouZaid <6760103+aabouzaid@users.noreply.github.com> --- .tool-versions | 14 ++++++------ scripts/generate-release-notes.sh | 36 +++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/.tool-versions b/.tool-versions index 441adc5480..52f8b3d5b2 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,11 +1,9 @@ -helm 3.15.1 -# The kubectl version depends on the K8s CI cluster version -kubectl 1.27.14 -kustomize 5.4.2 +git-chglog 0.15.4 golang 1.22.4 -# Task is mainly used to run tests locally or in the CI pipeline. -task 3.30.1 gomplate v3.11.8 -git-chglog 0.15.4 -yq 4.44.1 +helm 3.15.1 +kubectl 1.27.14 # The kubectl version depends on the K8s CI cluster version +kustomize 5.4.2 +task 3.30.1 # Task is mainly used to run tests locally or in the CI pipeline. yamllint 1.35.1 +yq 4.44.1 diff --git a/scripts/generate-release-notes.sh b/scripts/generate-release-notes.sh index 3bad44c872..3900e09ef5 100644 --- a/scripts/generate-release-notes.sh +++ b/scripts/generate-release-notes.sh @@ -2,13 +2,22 @@ set -euo pipefail main () { - chart_files_to_release="${1:-"charts/*/Chart.yaml"}" + chart_files_to_release="${1:-"charts/camunda-platform*/Chart.yaml"}" for chart_file in ${chart_files_to_release}; do - chart_name=$(grep -Po "(?<=^name: ).+" ${chart_file}) - chart_version=$(grep -Po "(?<=^version: ).+" ${chart_file}) + chart_name="$(yq '.name' ${chart_file})" + chart_path="$(dirname ${chart_file})" + chart_version="$(yq '.version' ${chart_file})" + chart_version_previous="$(git show main:${chart_file} | yq '.version')" chart_tag="${chart_name}-${chart_version}" - chart_path="charts/${chart_name}" + chart_tag_previous="${chart_name}-${chart_version_previous}" + + # + # Early exit if the tag already exists. + git tag -l | grep -q "${chart_tag}" && { + echo "[WARN] The tag ${chart_tag} already exists, nothing to do..."; + continue + } # # Set Helm CLI version. @@ -17,11 +26,11 @@ main () { # # Generate RELEASE-NOTES.md file (used for Github release notes and ArtifactHub "changes" annotation). - git-chglog \ - --output "${chart_path}/RELEASE-NOTES.md" \ - --tag-filter-pattern "${chart_tag%%.*}" \ - --next-tag "${chart_tag}" \ - --path "${chart_path}" "${chart_tag}" + git-chglog \ + --output "${chart_path}/RELEASE-NOTES.md" \ + --next-tag "${chart_tag}" \ + --path "${chart_path}" \ + "${chart_tag_previous}".."${chart_tag}" # # Update ArtifactHub "changes" annotation in the Chart.yaml file. @@ -36,6 +45,11 @@ main () { ["fix"]=fixed ) + # Workaround to rest with empty literal block which is not possible in yq. + yq -i '.annotations."artifacthub.io/changes" = ""' "${chart_file}" + sed -i 's#artifacthub.io/changes: ""#artifacthub.io/changes: |#g' "${chart_file}" + + # Generate temp file with changes to be merged with the Chart.yaml file. artifacthub_changes_tmp="/tmp/changes-for-artifacthub.yaml.tmp" echo -e 'annotations:\n artifacthub.io/changes: |' > "${artifacthub_changes_tmp}" @@ -59,9 +73,9 @@ main () { # Merge changes back to the Chart.yaml file. # https://mikefarah.gitbook.io/yq/operators/reduce#merge-all-yaml-files-together yq eval-all '. as $item ireduce ({}; . * $item )' \ - ${chart_path}/Chart.yaml "${artifacthub_changes_tmp}" > \ + "${chart_file}" "${artifacthub_changes_tmp}" > \ /tmp/Chart-with-artifacthub-changes.yaml.tmp - cat /tmp/Chart-with-artifacthub-changes.yaml.tmp > ${chart_path}/Chart.yaml + cat /tmp/Chart-with-artifacthub-changes.yaml.tmp > "${chart_file}" rm "${artifacthub_changes_tmp}" done }