Skip to content

Commit

Permalink
chore: update generate-release-notes.sh to work with multi version
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed AbouZaid <[email protected]>
  • Loading branch information
aabouzaid committed Jun 11, 2024
1 parent dd2b3fe commit 6a8aaaa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
14 changes: 6 additions & 8 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -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
36 changes: 25 additions & 11 deletions scripts/generate-release-notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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}"

Expand All @@ -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
}
Expand Down

0 comments on commit 6a8aaaa

Please sign in to comment.