From 9b91e9673f5a41e0a39a9ee92e0261a1336aa951 Mon Sep 17 00:00:00 2001 From: Ahmed AbouZaid <6760103+aabouzaid@users.noreply.github.com> Date: Thu, 25 Jul 2024 05:40:59 +0200 Subject: [PATCH] chore: fix release process issues Signed-off-by: Ahmed AbouZaid <6760103+aabouzaid@users.noreply.github.com> --- .chglog/CHANGELOG.tpl.md | 45 ----------- .chglog/config.yml | 25 ------ .github/config/cliff.toml | 79 +++++++++++++++++++ .../release-please/release-please-config.json | 9 ++- .github/workflows/chart-release-pr.yml | 8 +- .../workflows/chart-release-update-config.yml | 42 ++++++++++ .github/workflows/chart-release.yaml | 4 +- .github/workflows/repo-pr-conventions.yaml | 3 + .tool-versions | 2 +- scripts/generate-release-notes.sh | 34 ++++---- 10 files changed, 158 insertions(+), 93 deletions(-) delete mode 100644 .chglog/CHANGELOG.tpl.md delete mode 100755 .chglog/config.yml create mode 100644 .github/config/cliff.toml create mode 100644 .github/workflows/chart-release-update-config.yml diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md deleted file mode 100644 index e3e45ecffd..0000000000 --- a/.chglog/CHANGELOG.tpl.md +++ /dev/null @@ -1,45 +0,0 @@ -The changelog is automatically generated using [git-chglog](https://github.com/git-chglog/git-chglog) -and it follows [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) format. - -{{ range .Versions }} - -## {{ if .Tag.Previous -}} - [{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}) - {{- else -}} - [{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/releases/tag/{{ .Tag.Name }}) - {{- end }} ({{ datetime "2006-01-02" .Tag.Date }}) - -{{ range .CommitGroups -}} -### {{ .Title }} - -{{ range .Commits -}} -* {{ .Subject }} -{{ end }} -{{ end -}} - -{{- if .RevertCommits -}} -### Reverts - -{{ range .RevertCommits -}} -* {{ .Revert.Header }} -{{ end }} -{{ end -}} - -{{- if .MergeCommits -}} -### Pull Requests - -{{ range .MergeCommits -}} -* {{ .Header }} -{{ end }} -{{ end -}} - -{{- if .NoteGroups -}} -{{ range .NoteGroups -}} -### {{ .Title }} - -{{ range .Notes }} -{{ .Body }} -{{ end }} -{{ end -}} -{{ end -}} -{{ end -}} diff --git a/.chglog/config.yml b/.chglog/config.yml deleted file mode 100755 index 11f59835e8..0000000000 --- a/.chglog/config.yml +++ /dev/null @@ -1,25 +0,0 @@ -style: github -template: CHANGELOG.tpl.md -info: - title: CHANGELOG - repository_url: https://github.com/camunda/camunda-platform-helm -options: - commits: - filters: - Type: - - build - - ci - - docs - - feat - - fix - - refactor - - style - - test - header: - pattern: "^(\\w*)\\:\\s(.*)$" - pattern_maps: - - Type - - Subject - notes: - keywords: - - BREAKING CHANGE diff --git a/.github/config/cliff.toml b/.github/config/cliff.toml new file mode 100644 index 0000000000..53fe571ed6 --- /dev/null +++ b/.github/config/cliff.toml @@ -0,0 +1,79 @@ +# git-cliff ~ default configuration file +# https://git-cliff.org/docs/configuration +# +# Lines starting with "#" are comments. +# Configuration options are organized into tables and keys. +# See documentation for more information on available options. + +[changelog] +# template for the changelog footer +header = """ +The changelog is automatically generated and it follows [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) format. +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ + +{% if version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](https://github.com/camunda/camunda-platform-helm/releases/tag/{{ version }}) ({{ timestamp | date(format="%Y-%m-%d") }}) +{% else %}\ + ## [unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits %} + - {% if commit.breaking %}**⚠ BREAKING CHANGE** {% endif %}\ + {{ commit.message | upper_first }}\ + {% endfor %} +{% endfor %}\n +""" +# template for the changelog footer +footer = """ + +""" +# remove the leading and trailing s +trim = true +# postprocessors +postprocessors = [ + # { pattern = '', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL +] + +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for preprocessing the commit messages +commit_preprocessors = [ + # Replace issue numbers + #{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, + # Check spelling of the commit with https://github.com/crate-ci/typos + # If the spelling is incorrect, it will be automatically fixed. + #{ pattern = '.*', replace_command = 'typos --write-changes -' }, +] +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat:", group = "Features" }, + { message = "^refactor:", group = "Refactor" }, + { message = "^fix:", group = "Fixes" }, + { message = "^doc:", group = "Documentation" }, + { message = "^revert:", group = "Revert" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# regex for matching git tags +# tag_pattern = "v[0-9].*" +# regex for skipping tags +# skip_tags = "" +# regex for ignoring tags +# ignore_tags = "" +# sort the tags topologically +topo_order = false +# sort the commits inside sections by oldest/newest order +sort_commits = "oldest" +# limit the number of commits included in the changelog. +# limit_commits = 42 diff --git a/.github/config/release-please/release-please-config.json b/.github/config/release-please/release-please-config.json index 1b58bb4aa7..f4057513b8 100644 --- a/.github/config/release-please/release-please-config.json +++ b/.github/config/release-please/release-please-config.json @@ -5,17 +5,18 @@ "bump-minor-pre-major": false, "prerelease": false, "draft": false, + "last-release-sha": "e098c6f7f1d6870acde813b2d38f3db33f89e662", "packages": { "charts/camunda-platform-latest": { "release-type": "helm", "extra-label": "version/8.5,automation/release-please,release/pr,kind/chore,chart/camunda-platform", - "component": "camunda-platform", + "component": "camunda-platform-latest", "include-v-in-tag": false }, "charts/camunda-platform-8.4": { "release-type": "helm", "extra-label": "version/8.4,automation/release-please,release/pr,kind/chore,chart/camunda-platform", - "component": "camunda-platform", + "component": "camunda-platform-8.4", "include-v-in-tag": false, "extra-files": [ { @@ -28,7 +29,7 @@ "charts/camunda-platform-8.3": { "release-type": "helm", "extra-label": "version/8.3,automation/release-please,release/pr,kind/chore,chart/camunda-platform", - "component": "camunda-platform", + "component": "camunda-platform-8.3", "include-v-in-tag": false, "extra-files": [ { @@ -41,7 +42,7 @@ "charts/camunda-platform-8.2": { "release-type": "helm", "extra-label": "version/8.2,automation/release-please,release/pr,kind/chore,chart/camunda-platform", - "component": "camunda-platform", + "component": "camunda-platform-8.2", "include-v-in-tag": false, "extra-files": [ { diff --git a/.github/workflows/chart-release-pr.yml b/.github/workflows/chart-release-pr.yml index e281b07d25..883f27c79f 100644 --- a/.github/workflows/chart-release-pr.yml +++ b/.github/workflows/chart-release-pr.yml @@ -9,6 +9,10 @@ permissions: contents: write pull-requests: write +env: + RELEASE_PLEASE_CONFIG_FILE: .github/config/release-please/release-please-config.json + RELEASE_PLEASE_MANIFEST_FILE: .github/config/release-please/.release-please-manifest.json + jobs: release-please: name: Run Release Please @@ -24,5 +28,5 @@ jobs: with: token: '${{ steps.generate-github-token.outputs.token }}' # Config docs: https://github.com/googleapis/release-please/blob/main/docs/manifest-releaser.md - config-file: .github/config/release-please/release-please-config.json - manifest-file: .github/config/release-please/.release-please-manifest.json + config-file: "${{ env.RELEASE_PLEASE_CONFIG_FILE }}" + manifest-file: "${{ env.RELEASE_PLEASE_MANIFEST_FILE }}" diff --git a/.github/workflows/chart-release-update-config.yml b/.github/workflows/chart-release-update-config.yml new file mode 100644 index 0000000000..be005ad59d --- /dev/null +++ b/.github/workflows/chart-release-update-config.yml @@ -0,0 +1,42 @@ +name: "Chart - Release - Update Config" + +on: + push: + branches: + - main + paths: + - .github/config/release-please/.release-please-manifest.json + +permissions: + contents: write + +env: + RELEASE_PLEASE_CONFIG: ".github/config/release-please/release-please-config.json" + +jobs: + # A workaround for https://github.com/googleapis/release-please/issues/2202 + update-config: + name: Update release-please config + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + fetch-depth: 0 + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - name: Get latest release commit + run: | + last_release_commit="$(git log -n1 --pretty=format:'%H' --grep='chore(release):')" + cat "${RELEASE_PLEASE_CONFIG_FILE}" | + jq --arg last_release_commit "${last_release_commit}" \ + '."last-release-sha" = $last_release_commit' | tee "${RELEASE_PLEASE_CONFIG_FILE}" + - name: Git pull + run: git pull --rebase --autostash . + - uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4 + with: + author_name: "distro-ci[bot]" + author_email: "122795778+distro-ci[bot]@users.noreply.github.com" + message: "chore(release): update release-please config" diff --git a/.github/workflows/chart-release.yaml b/.github/workflows/chart-release.yaml index f191292e2a..f8b4b040b6 100644 --- a/.github/workflows/chart-release.yaml +++ b/.github/workflows/chart-release.yaml @@ -163,11 +163,11 @@ jobs: - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 with: - # The verification step happens in the "release" branch before merging into the "main" branch. + # The verification step happens in the release branch before merging into the "main" branch. fetch-depth: 0 + ref: release-please--branches--main - name: Install env dependencies uses: asdf-vm/actions/install@05e0d2ed97b598bfce82fd30daf324ae0c4570e6 # v3 - # NOTE: This simple test is under review. So it could fail (it should be fixed in that case). - name: Simple smoke test uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3 with: diff --git a/.github/workflows/repo-pr-conventions.yaml b/.github/workflows/repo-pr-conventions.yaml index a34bb74b3e..cc36194bc4 100644 --- a/.github/workflows/repo-pr-conventions.yaml +++ b/.github/workflows/repo-pr-conventions.yaml @@ -28,6 +28,9 @@ jobs: # Configure additional validation for the subject based on a regex. # Ensures the subject doesn't start with an uppercase character. subjectPattern: ^(?![A-Z]).+$ + # Ignore release PR since it's different and already automated. + ignoreLabels: | + release/pr # When using "Squash and merge" on a PR with only one commit, GitHub # will suggest using that commit message instead of the PR title for the # merge commit, and it's easy to commit this by mistake. Enable this option diff --git a/.tool-versions b/.tool-versions index eef7ab6b90..73b420bec3 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ -git-chglog 0.15.4 +git-cliff 2.4.0 golang 1.22.5 gomplate v4.1.0 helm 3.15.3 diff --git a/scripts/generate-release-notes.sh b/scripts/generate-release-notes.sh index 93a282abac..eb463ed9e1 100644 --- a/scripts/generate-release-notes.sh +++ b/scripts/generate-release-notes.sh @@ -1,16 +1,17 @@ #!/bin/bash -set -euo pipefail +set -euox pipefail + main () { test "$(git branch --show-current)" != "main" && git fetch origin main:main + latest_release_commit="$(git log main -n1 --pretty=format:'%H' --grep='chore(release):')" + cliff_config_file=".github/config/cliff.toml" chart_dir="${1}" chart_file="${chart_dir}/Chart.yaml" chart_name="$(yq '.name' ${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_tag_previous="${chart_name}-${chart_version_previous}" # # Early exit if the tag already exists. @@ -24,24 +25,29 @@ main () { # # Generate RELEASE-NOTES.md file (used for Github release notes and ArtifactHub "changes" annotation). - git-chglog \ + git-cliff ${latest_release_commit}.. \ + --config "${cliff_config_file}" \ --output "${chart_dir}/RELEASE-NOTES.md" \ - --tag-filter-pattern "${chart_tag}" \ - --next-tag "${chart_tag}" \ - --path "${chart_dir}" \ - "${chart_tag_previous}".."${chart_tag}" + --include-path "${chart_dir}/**" \ + --tag "${chart_tag}" + + cat "${chart_dir}/RELEASE-NOTES.md" # # Update ArtifactHub "changes" annotation in the Chart.yaml file. # https://artifacthub.io/docs/topics/annotations/helm/#supported-annotations - change_types="$(yq e '.options.commits.filters.Type | join(" ")' .chglog/config.yml)" + change_types () { + yq -oy "${cliff_config_file}" | + yq '[.git.commit_parsers[].group] | join(" ")' | + tr -d '[:punct:]' | tr -d '[:digit:]' + } # declare -A kac_map kac_map+=( - ["feat"]=added - ["refactor"]=changed - ["fix"]=fixed + ["Features"]=added + ["Refactor"]=changed + ["Fixes"]=fixed ) # Workaround to rest with empty literal block which is not possible in yq. @@ -52,10 +58,10 @@ main () { artifacthub_changes_tmp="/tmp/changes-for-artifacthub.yaml.tmp" echo -e 'annotations:\n artifacthub.io/changes: |' > "${artifacthub_changes_tmp}" - for change_type in ${change_types}; do + for change_type in $(change_types); do change_type_section=$(sed -rn "/^\#+\s${change_type^}/,/^#/p" "${chart_dir}/RELEASE-NOTES.md") if [[ -n "${change_type_section}" && "${!kac_map[@]}" =~ "${change_type}" ]]; then - echo "${change_type_section}" | egrep '^\*' | sed 's/^* //g' | while read commit_message; do + echo "${change_type_section}" | egrep '^\-' | sed 's/^- //g' | while read commit_message; do echo " - kind: ${kac_map[${change_type}]}" echo " description: \"$(echo ${commit_message} | sed -r "s/ \(.+\)$//")\"" done >> "${artifacthub_changes_tmp}"